From e9e477ffe5d6db6795c535c854a9eac7c773ba71 Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Sat, 12 Dec 2015 01:13:49 -0500 Subject: [PATCH] some attempted changes for ipMIDI on windows --- libs/midi++2/ipmidi_port.cc | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/libs/midi++2/ipmidi_port.cc b/libs/midi++2/ipmidi_port.cc index 8e907471e0..cf4e6b243d 100644 --- a/libs/midi++2/ipmidi_port.cc +++ b/libs/midi++2/ipmidi_port.cc @@ -31,6 +31,7 @@ #endif #if defined(PLATFORM_WINDOWS) #include +#include #else #include #endif @@ -111,6 +112,7 @@ IPMIDIPort::close_sockets () } } +#ifndef PLATFORM_WINDOWS static bool get_address (int sock, struct in_addr *inaddr, const string& ifname ) { @@ -140,6 +142,7 @@ get_address (int sock, struct in_addr *inaddr, const string& ifname ) return true; } +#endif bool IPMIDIPort::open_sockets (int base_port, const string& ifname) @@ -172,6 +175,7 @@ IPMIDIPort::open_sockets (int base_port, const string& ifname) // INADDR_ANY will bind to default interface, // specify alternate interface nameon which to bind... struct in_addr if_addr_in; +#ifndef PLATFORM_WINDOWS if (!ifname.empty()) { if (!get_address(sockin, &if_addr_in, ifname)) { error << string_compose ("socket(in): could not find interface address for %1", ifname) << endmsg; @@ -185,6 +189,9 @@ IPMIDIPort::open_sockets (int base_port, const string& ifname) } else { if_addr_in.s_addr = htonl (INADDR_ANY); } +#else + if_addr_in.s_addr = htonl (INADDR_ANY); +#endif struct ip_mreq mreq; mreq.imr_multiaddr.s_addr = ::inet_addr("225.0.0.37"); @@ -229,6 +236,8 @@ IPMIDIPort::open_sockets (int base_port, const string& ifname) return false; } +#ifndef PLATFORM_WINDOWS + if (fcntl (sockin, F_SETFL, O_NONBLOCK)) { error << "cannot set non-blocking mode for IP MIDI input socket (" << ::strerror (errno) << ')' << endmsg; return false; @@ -239,6 +248,20 @@ IPMIDIPort::open_sockets (int base_port, const string& ifname) return false; } +#else + // If iMode!=0, non-blocking mode is enabled. + u_long mode=1; + if (ioctlsocket(sockin,FIONBIO,&imode)) { + error << "cannot set non-blocking mode for IP MIDI input socket (" << ::strerror (errno) << ')' << endmsg; + return false; + } + imode = 1; + if (ioctlsocket(sockout,FIONBIO,&iMode)) { + error << "cannot set non-blocking mode for IP MIDI output socket (" << ::strerror (errno) << ')' << endmsg; + return false; + } +#endif + return true; } @@ -287,4 +310,3 @@ IPMIDIPort::parse (framecnt_t timestamp) ::perror ("failed to recv from socket"); } } -