1
0
Fork 0

(svn r1836) Clean up some strange constructs concerning socket options

release/0.4.5
tron 2005-02-07 09:56:16 +00:00
parent 7c38b7bc01
commit 552d84884f
2 changed files with 32 additions and 44 deletions

View File

@ -573,14 +573,8 @@ static bool NetworkConnect(const char *hostname, int port)
return false; return false;
} }
{ // set nodelay /* XXX should this be done at all? */ if (!SetNoDelay(s))
#if !defined(BEOS_NET_SERVER) // not implemented on BeOS net_server... DEBUG(net, 1)("[NET] Setting TCP_NODELAY failed");
int b = 1;
// The (const char*) cast is needed for windows!!
if (setsockopt(s, IPPROTO_TCP, TCP_NODELAY, (const char*)&b, sizeof(b)) != 0)
DEBUG(net, 1)("[NET] Setting TCP_NODELAY failed");
#endif
}
sin.sin_family = AF_INET; sin.sin_family = AF_INET;
sin.sin_addr.s_addr = NetworkResolveHost(hostname); sin.sin_addr.s_addr = NetworkResolveHost(hostname);
@ -592,16 +586,8 @@ static bool NetworkConnect(const char *hostname, int port)
return false; return false;
} }
{ // set nonblocking mode for socket.. if (!SetNonBlocking(s))
unsigned long blocking = 1; DEBUG(net, 0)("[NET] Setting non-blocking failed"); // XXX should this be an error?
#if defined(__BEOS__) && defined(BEOS_NET_SERVER)
byte nonblocking = 1;
if (setsockopt(s, SOL_SOCKET, SO_NONBLOCK, &nonblocking, sizeof(blocking)) != 0)
#else
if (ioctlsocket(s, FIONBIO, &blocking) != 0)
#endif
DEBUG(net, 0)("[NET] Setting non-blocking failed"); /* XXX should this be an error? */
}
// in client mode, only the first client field is used. it's pointing to the server. // in client mode, only the first client field is used. it's pointing to the server.
NetworkAllocClient(s); NetworkAllocClient(s);
@ -619,11 +605,6 @@ static void NetworkAcceptClients(void)
struct sockaddr_in sin; struct sockaddr_in sin;
SOCKET s; SOCKET s;
NetworkClientState *cs; NetworkClientState *cs;
#ifndef __MORPHOS__
int sin_len;
#else
LONG sin_len; // for some reason we need a 'LONG' under MorphOS
#endif
uint i; uint i;
bool banned; bool banned;
@ -631,24 +612,17 @@ static void NetworkAcceptClients(void)
assert(_listensocket != INVALID_SOCKET); assert(_listensocket != INVALID_SOCKET);
for (;;) { for (;;) {
socklen_t sin_len;
sin_len = sizeof(sin); sin_len = sizeof(sin);
s = accept(_listensocket, (struct sockaddr*)&sin, &sin_len); s = accept(_listensocket, (struct sockaddr*)&sin, &sin_len);
if (s == INVALID_SOCKET) return; if (s == INVALID_SOCKET) return;
// set nonblocking mode for client socket SetNonBlocking(s); // XXX error handling?
#if defined(__BEOS__) && defined(BEOS_NET_SERVER)
{ unsigned long blocking = 1; byte nonblocking = 1; setsockopt(s, SOL_SOCKET, SO_NONBLOCK, &nonblocking, sizeof(blocking)); }
#else
{ unsigned long blocking = 1; ioctlsocket(s, FIONBIO, &blocking); }
#endif
DEBUG(net, 1) ("[NET] Client connected from %s on frame %d", inet_ntoa(sin.sin_addr), _frame_counter); DEBUG(net, 1) ("[NET] Client connected from %s on frame %d", inet_ntoa(sin.sin_addr), _frame_counter);
// set nodelay SetNoDelay(s); // XXX error handling?
#if !defined(BEOS_NET_SERVER) // not implemented on BeOS net_server...
// The (const char*) cast is needed for windows!!
{int b = 1; setsockopt(s, IPPROTO_TCP, TCP_NODELAY, (const char*)&b, sizeof(b));}
#endif
/* Check if the client is banned */ /* Check if the client is banned */
banned = false; banned = false;
@ -734,16 +708,8 @@ static bool NetworkListen(void)
} }
} }
{ // set nonblocking mode for socket if (!SetNonBlocking(ls))
unsigned long blocking = 1; DEBUG(net, 0)("[NET] Setting non-blocking failed"); // XXX should this be an error?
#if defined(__BEOS__) && defined(BEOS_NET_SERVER)
byte nonblocking = 1;
if (setsockopt(ls, SOL_SOCKET, SO_NONBLOCK, &nonblocking, sizeof(blocking)) != 0)
#else
if (ioctlsocket(ls, FIONBIO, &blocking) != 0)
#endif
DEBUG(net, 0)("[NET] Setting non-blocking failed"); /* XXX should this be an error? */
}
sin.sin_family = AF_INET; sin.sin_family = AF_INET;
sin.sin_addr.s_addr = _network_server_bind_ip; sin.sin_addr.s_addr = _network_server_bind_ip;

View File

@ -140,4 +140,26 @@ typedef unsigned long in_addr_t;
# endif # endif
#endif // __MORPHOS__ || __AMIGA__ #endif // __MORPHOS__ || __AMIGA__
static inline bool SetNonBlocking(int d)
{
int nonblocking = 1;
#if defined(__BEOS__) && defined(BEOS_NET_SERVER)
return setsockopt(d, SOL_SOCKET, SO_NONBLOCK, &nonblocking, sizeof(nonblocking)) == 0;
#else
return ioctlsocket(d, FIONBIO, &nonblocking) == 0;
#endif
}
static inline bool SetNoDelay(int d)
{
// XXX should this be done at all?
#if !defined(BEOS_NET_SERVER) // not implemented on BeOS net_server
int b = 1;
// The (const char*) cast is needed for windows
return setsockopt(d, IPPROTO_TCP, TCP_NODELAY, (const char*)&b, sizeof(b)) == 0;
#else
return true;
#endif
}
#endif // NETWORK_CORE_H #endif // NETWORK_CORE_H