diff --git a/src/FDM/JSBSim/input_output/FGfdmSocket.cpp b/src/FDM/JSBSim/input_output/FGfdmSocket.cpp index af9e605fb..5a3f9f6ab 100644 --- a/src/FDM/JSBSim/input_output/FGfdmSocket.cpp +++ b/src/FDM/JSBSim/input_output/FGfdmSocket.cpp @@ -40,10 +40,15 @@ INCLUDES #if defined(_MSC_VER) || defined(__MINGW32__) #include +#elif defined(__OpenBSD__) +#include +#include +#include +#include +#include #else #include #include -#include #endif #include #include @@ -95,7 +100,7 @@ FGfdmSocket::FGfdmSocket(const string& address, int port, int protocol) hints.ai_socktype = SOCK_STREAM; hints.ai_protocol = 0; if (!is_number(address)) - hints.ai_flags = AI_V4MAPPED | AI_ADDRCONFIG; + hints.ai_flags = AI_ADDRCONFIG; else hints.ai_flags = AI_NUMERICHOST; @@ -189,13 +194,14 @@ FGfdmSocket::FGfdmSocket(int port, int protocol) << " input socket on port " << port << endl << endl; if (Protocol == ptTCP) { - unsigned long NoBlock = true; if (listen(sckt, 5) >= 0) { // successful listen() #if defined(_MSC_VER) || defined(__MINGW32__) + u_long NoBlock = 1; ioctlsocket(sckt, FIONBIO, &NoBlock); sckt_in = accept(sckt, (struct sockaddr*)&scktName, &len); #else - ioctl(sckt, FIONBIO, &NoBlock); + int flags = fcntl(sckt, F_GETFL, 0); + fcntl(sckt, F_SETFL, flags | O_NONBLOCK); sckt_in = accept(sckt, (struct sockaddr*)&scktName, (socklen_t*)&len); #endif connected = true; @@ -229,7 +235,6 @@ string FGfdmSocket::Receive(void) char buf[1024]; int len = sizeof(struct sockaddr_in); int num_chars=0; - unsigned long NoBlock = true; string data; // todo: should allocate this with a standard size as a // class attribute and pass as a reference? @@ -241,9 +246,11 @@ string FGfdmSocket::Receive(void) #endif if (sckt_in > 0) { #if defined(_MSC_VER) || defined(__MINGW32__) - ioctlsocket(sckt_in, FIONBIO,&NoBlock); + u_long NoBlock = 1; + ioctlsocket(sckt_in, FIONBIO, &NoBlock); #else - ioctl(sckt_in, FIONBIO, &NoBlock); + int flags = fcntl(sckt_in, F_GETFL, 0); + fcntl(sckt_in, F_SETFL, flags | O_NONBLOCK); #endif send(sckt_in, "Connected to JSBSim server\nJSBSim> ", 35, 0); }