diff options
author | skotlex <skotlex@54d463be-8e91-2dee-dedb-b68131a5f0ec> | 2006-09-11 21:32:26 +0000 |
---|---|---|
committer | skotlex <skotlex@54d463be-8e91-2dee-dedb-b68131a5f0ec> | 2006-09-11 21:32:26 +0000 |
commit | 5e6c9e9a7fd16be13a59b361d2855813a1420009 (patch) | |
tree | a2c8e0293a3ac5fbe2f157ecffc5b5d0799d0342 /src/common | |
parent | e05a8b8263a62fd5645db1251e80fc78cec4e9d3 (diff) | |
download | hercules-5e6c9e9a7fd16be13a59b361d2855813a1420009.tar.gz hercules-5e6c9e9a7fd16be13a59b361d2855813a1420009.tar.bz2 hercules-5e6c9e9a7fd16be13a59b361d2855813a1420009.tar.xz hercules-5e6c9e9a7fd16be13a59b361d2855813a1420009.zip |
- Modified set_nonblocking and setsocketoptions in socket.c, using eApp's code as reference. Hopefully should improve performance somewhat.
git-svn-id: https://rathena.svn.sourceforge.net/svnroot/rathena/trunk@8710 54d463be-8e91-2dee-dedb-b68131a5f0ec
Diffstat (limited to 'src/common')
-rw-r--r-- | src/common/socket.c | 46 | ||||
-rw-r--r-- | src/common/socket.h | 2 |
2 files changed, 21 insertions, 27 deletions
diff --git a/src/common/socket.c b/src/common/socket.c index 537066ca7..e3ccb78a1 100644 --- a/src/common/socket.c +++ b/src/common/socket.c @@ -84,21 +84,34 @@ void set_defaultparse(int (*defaultparse)(int)) }
void set_nonblocking(int fd, int yes) {
- setsockopt(fd,IPPROTO_TCP,TCP_NODELAY,(char *)&yes,sizeof yes);
+ // I don't think we need this
+ // TCP_NODELAY BOOL Disables the Nagle algorithm for send coalescing.
+ //setsockopt(sock,IPPROTO_TCP,TCP_NODELAY,(char *)&yes,sizeof yes);
+
+ // FIONBIO Use with a nonzero argp parameter to enable the nonblocking mode of socket s.
+ // The argp parameter is zero if nonblocking is to be disabled.
+#ifdef __WIN32
+ ioctlsocket(fd, FIONBIO, &yes);
+#else
+ ioctl(fd,FIONBIO,&yes);
+#endif
}
static void setsocketopts(int fd)
{
+#ifndef WIN32
int yes = 1; // reuse fix
- size_t buff;
- size_t buff_size = sizeof (buff);
-
- setsockopt(fd,SOL_SOCKET,SO_REUSEADDR,(char *)&yes,sizeof yes);
+ // set SO_REAUSEADDR to true, unix only. on windows this option causes
+ // the previous owner of the socket to give up, which is not desirable
+ // in most cases, neither compatible with unix.
+ setsockopt(fd,SOL_SOCKET,SO_REUSEADDR,(char *)&yes,sizeof(yes));
#ifdef SO_REUSEPORT
- setsockopt(fd,SOL_SOCKET,SO_REUSEPORT,(char *)&yes,sizeof yes);
+ setsockopt(fd,SOL_SOCKET,SO_REUSEPORT,(char *)&yes,sizeof(yes));
#endif
- setsockopt(fd,IPPROTO_TCP,TCP_NODELAY,(char *)&yes,sizeof yes);
-
+#endif
+// setsockopt(sock,IPPROTO_TCP,TCP_NODELAY,(char *)&yes,sizeof(yes));
+// setsockopt(sock, SOL_SOCKET, SO_SNDBUF, (char *) &wfifo_size , sizeof(rfifo_size ));
+// setsockopt(sock, SOL_SOCKET, SO_RCVBUF, (char *) &rfifo_size , sizeof(rfifo_size ));
#ifdef __WIN32
{ //set SO_LINGER option (from Freya)
//(http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winsock/winsock/closesocket_2.asp)
@@ -109,23 +122,6 @@ static void setsocketopts(int fd) ShowWarning("setsocketopts: Unable to set SO_LINGER mode for connection %d!\n",fd);
}
#endif
-
- setsockopt(fd, SOL_SOCKET, SO_SNDBUF, (void *)&wfifo_size , sizeof(wfifo_size ));
- if (getsockopt(fd, SOL_SOCKET, SO_SNDBUF, (void *)&buff, &buff_size) == 0)
- {
- if (buff < wfifo_size) //We are not going to complain if we get more, aight? [Skotlex]
- ShowError("setsocketopts: Requested send buffer size failed (requested %d bytes buffer, received a buffer of size %d)\n", wfifo_size, buff);
- }
- else
- perror("setsocketopts: getsockopt wfifo");
- setsockopt(fd, SOL_SOCKET, SO_RCVBUF, (void *) &rfifo_size , sizeof(rfifo_size ));
- if (getsockopt(fd, SOL_SOCKET, SO_RCVBUF, (void *) &buff, &buff_size) == 0)
- {
- if (buff < rfifo_size)
- ShowError("setsocketopts: Requested receive buffer size failed (requested %d bytes buffer, received a buffer of size %d)\n", rfifo_size, buff);
- }
- else
- perror("setsocketopts: getsockopt rfifo");
}
/*======================================
diff --git a/src/common/socket.h b/src/common/socket.h index ca4b20c91..502529419 100644 --- a/src/common/socket.h +++ b/src/common/socket.h @@ -165,6 +165,4 @@ in_addr_t resolve_hostbyname(char* hostname, unsigned char *ip, char *ip_str); extern unsigned int addr_[16]; // ip addresses of local host (host byte order)
extern unsigned int naddr_; // # of ip addresses
-
-
#endif // _SOCKET_H_
|