[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[myserver-commit] [3039] Under Windows `Socket::recv' keeps the same beh
From: |
Giuseppe Scrivano |
Subject: |
[myserver-commit] [3039] Under Windows `Socket::recv' keeps the same behaviour that it has under POSIX with non blocking sockets . |
Date: |
Sun, 29 Mar 2009 20:34:36 +0000 |
Revision: 3039
http://svn.sv.gnu.org/viewvc/?view=rev&root=myserver&revision=3039
Author: gscrivano
Date: 2009-03-29 20:34:36 +0000 (Sun, 29 Mar 2009)
Log Message:
-----------
Under Windows `Socket::recv' keeps the same behaviour that it has under POSIX
with non blocking sockets.
Modified Paths:
--------------
trunk/myserver/include/base/socket/socket.h
trunk/myserver/src/base/socket/socket.cpp
Modified: trunk/myserver/include/base/socket/socket.h
===================================================================
--- trunk/myserver/include/base/socket/socket.h 2009-03-29 20:34:32 UTC (rev
3038)
+++ trunk/myserver/include/base/socket/socket.h 2009-03-29 20:34:36 UTC (rev
3039)
@@ -99,6 +99,7 @@
int operator=(Socket);
int getsockname(MYSERVER_SOCKADDR*,int*);
int setNonBlocking(int);
+ bool getNonBLocking () {return isNonBlocking;}
virtual int dataOnRead(int sec = 0, int usec = 500);
u_long getThrottling();
@@ -121,6 +122,9 @@
/*! Send throttling rate. */
u_long throttlingRate;
+ /*! Is the socket non blocking? */
+ bool isNonBlocking;
+
/*! Stop the sockets system. */
static bool denyBlockingOperations;
Modified: trunk/myserver/src/base/socket/socket.cpp
===================================================================
--- trunk/myserver/src/base/socket/socket.cpp 2009-03-29 20:34:32 UTC (rev
3038)
+++ trunk/myserver/src/base/socket/socket.cpp 2009-03-29 20:34:36 UTC (rev
3039)
@@ -92,6 +92,7 @@
socketHandle = s.socketHandle;
serverSocket = s.serverSocket;
throttlingRate = s.throttlingRate;
+ isNonBlocking = s.isNonBlocking;
return 0;
}
/*!
@@ -113,7 +114,8 @@
Socket::Socket(FileHandle handle)
{
throttlingRate = 0;
- setHandle(handle);
+ setHandle (handle);
+ isNonBlocking = false;
}
/*!
@@ -124,6 +126,7 @@
socketHandle = socket->socketHandle;
serverSocket = socket->serverSocket;
throttlingRate = socket->throttlingRate;
+ isNonBlocking = socket->isNonBlocking;
}
/*!
@@ -647,7 +650,10 @@
err = ::recv(socketHandle, buffer, len, flags);
}while((err == SOCKET_ERROR) && (GetLastError() == WSAEWOULDBLOCK));
- if(err == SOCKET_ERROR)
+ if ( err == SOCKET_ERROR && GetLastError() == WSAEWOULDBLOCK &&
isNonBlocking)
+ return 0;
+
+ if (err == SOCKET_ERROR)
return -1;
else
return err;
@@ -655,15 +661,10 @@
#endif
#ifdef NOT_WIN
err = ::recv((int)socketHandle, buffer, len, flags);
- if ( err < 0 && errno == EAGAIN )
- {// if temporarily unavailable ...
- int flags = fcntl((int)socketHandle, F_GETFL, 0);
- if ( (flags >= 0) && ((flags & O_NONBLOCK) != 0) )
- {// ... and nonblocking it's allright
- return 0;
- }
- }
+ if ( err < 0 && errno == EAGAIN && isNonBlocking)
+ return 0;
+
if(err == 0)
err = -1;
@@ -690,13 +691,18 @@
}
/*!
- *Pass a nonzero value to set the socket to be nonblocking.
+ *Change the socket behaviour when an operation can't be completed
+ *immediately.
+ *If the socket is configured to be non blocking then it will return
+ *immediately the control to the caller function.
+ *A blocking socket will wait until the operation can be performed.
+ *\param nonBlocking Nonzero to configure the socket non blocking.
*/
-int Socket::setNonBlocking(int non_blocking)
+int Socket::setNonBlocking(int nonBlocking)
{
int ret = -1;
#ifdef WIN32
- u_long nonblock = non_blocking ? 1 : 0;
+ u_long nonblock = nonBlocking ? 1 : 0;
ret = ioctlsocket( FIONBIO, &nonblock);
#else
@@ -706,7 +712,7 @@
if (flags < 0)
return -1;
- if(non_blocking)
+ if(nonBlocking)
flags |= O_NONBLOCK;
else
flags &= ~O_NONBLOCK;
@@ -714,7 +720,7 @@
ret = fcntl((int)socketHandle, F_SETFL, flags);
#endif
-
+ isNonBlocking = nonBlocking ? true : false;
return ret;
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [myserver-commit] [3039] Under Windows `Socket::recv' keeps the same behaviour that it has under POSIX with non blocking sockets .,
Giuseppe Scrivano <=