Fixes for OpenBSD.
Took the opportunity to switch to the more portable call 'fctnl(... O_NONBLOCK ...)' instead of 'ioctl(... FIONBIO ...)' for all UNIX-like OSes.
This commit is contained in:
parent
bb0b69bc41
commit
53fac332c1
1 changed files with 14 additions and 7 deletions
|
@ -40,10 +40,15 @@ INCLUDES
|
||||||
|
|
||||||
#if defined(_MSC_VER) || defined(__MINGW32__)
|
#if defined(_MSC_VER) || defined(__MINGW32__)
|
||||||
#include <WS2tcpip.h>
|
#include <WS2tcpip.h>
|
||||||
|
#elif defined(__OpenBSD__)
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/socket.h>
|
||||||
|
#include <netdb.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <fcntl.h>
|
||||||
#else
|
#else
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <sys/ioctl.h>
|
|
||||||
#endif
|
#endif
|
||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
@ -95,7 +100,7 @@ FGfdmSocket::FGfdmSocket(const string& address, int port, int protocol)
|
||||||
hints.ai_socktype = SOCK_STREAM;
|
hints.ai_socktype = SOCK_STREAM;
|
||||||
hints.ai_protocol = 0;
|
hints.ai_protocol = 0;
|
||||||
if (!is_number(address))
|
if (!is_number(address))
|
||||||
hints.ai_flags = AI_V4MAPPED | AI_ADDRCONFIG;
|
hints.ai_flags = AI_ADDRCONFIG;
|
||||||
else
|
else
|
||||||
hints.ai_flags = AI_NUMERICHOST;
|
hints.ai_flags = AI_NUMERICHOST;
|
||||||
|
|
||||||
|
@ -189,13 +194,14 @@ FGfdmSocket::FGfdmSocket(int port, int protocol)
|
||||||
<< " input socket on port " << port << endl << endl;
|
<< " input socket on port " << port << endl << endl;
|
||||||
|
|
||||||
if (Protocol == ptTCP) {
|
if (Protocol == ptTCP) {
|
||||||
unsigned long NoBlock = true;
|
|
||||||
if (listen(sckt, 5) >= 0) { // successful listen()
|
if (listen(sckt, 5) >= 0) { // successful listen()
|
||||||
#if defined(_MSC_VER) || defined(__MINGW32__)
|
#if defined(_MSC_VER) || defined(__MINGW32__)
|
||||||
|
u_long NoBlock = 1;
|
||||||
ioctlsocket(sckt, FIONBIO, &NoBlock);
|
ioctlsocket(sckt, FIONBIO, &NoBlock);
|
||||||
sckt_in = accept(sckt, (struct sockaddr*)&scktName, &len);
|
sckt_in = accept(sckt, (struct sockaddr*)&scktName, &len);
|
||||||
#else
|
#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);
|
sckt_in = accept(sckt, (struct sockaddr*)&scktName, (socklen_t*)&len);
|
||||||
#endif
|
#endif
|
||||||
connected = true;
|
connected = true;
|
||||||
|
@ -229,7 +235,6 @@ string FGfdmSocket::Receive(void)
|
||||||
char buf[1024];
|
char buf[1024];
|
||||||
int len = sizeof(struct sockaddr_in);
|
int len = sizeof(struct sockaddr_in);
|
||||||
int num_chars=0;
|
int num_chars=0;
|
||||||
unsigned long NoBlock = true;
|
|
||||||
string data; // todo: should allocate this with a standard size as a
|
string data; // todo: should allocate this with a standard size as a
|
||||||
// class attribute and pass as a reference?
|
// class attribute and pass as a reference?
|
||||||
|
|
||||||
|
@ -241,9 +246,11 @@ string FGfdmSocket::Receive(void)
|
||||||
#endif
|
#endif
|
||||||
if (sckt_in > 0) {
|
if (sckt_in > 0) {
|
||||||
#if defined(_MSC_VER) || defined(__MINGW32__)
|
#if defined(_MSC_VER) || defined(__MINGW32__)
|
||||||
ioctlsocket(sckt_in, FIONBIO,&NoBlock);
|
u_long NoBlock = 1;
|
||||||
|
ioctlsocket(sckt_in, FIONBIO, &NoBlock);
|
||||||
#else
|
#else
|
||||||
ioctl(sckt_in, FIONBIO, &NoBlock);
|
int flags = fcntl(sckt_in, F_GETFL, 0);
|
||||||
|
fcntl(sckt_in, F_SETFL, flags | O_NONBLOCK);
|
||||||
#endif
|
#endif
|
||||||
send(sckt_in, "Connected to JSBSim server\nJSBSim> ", 35, 0);
|
send(sckt_in, "Connected to JSBSim server\nJSBSim> ", 35, 0);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue