|
From: <mik...@us...> - 2003-12-27 10:27:14
|
Update of /cvsroot/sharedaemon/sharedaemon-ui-web/src/server/network
In directory sc8-pr-cvs1:/tmp/cvs-serv24081/src/server/network
Modified Files:
ServerSocket.cpp ServerSocket.h
Log Message:
27/12/2003 Mikael Barbeaux
* Fixed a bug about accepting sockets and closing server.
Index: ServerSocket.cpp
===================================================================
RCS file: /cvsroot/sharedaemon/sharedaemon-ui-web/src/server/network/ServerSocket.cpp,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- ServerSocket.cpp 26 Dec 2003 22:56:42 -0000 1.2
+++ ServerSocket.cpp 27 Dec 2003 10:27:10 -0000 1.3
@@ -19,8 +19,6 @@
#include "ServerSocket.h"
#include "../../thread/Thread.h"
-#include <signal.h>
-#include <sys/types.h>
#ifdef _WIN32_
#define socklen_t int
#endif
@@ -192,10 +190,8 @@
* Throws a SocketException if an error occurs when
* accepting or any other reasons ( not valid, not
* bound, not listening ).
- *
- * @param timeout - timeout for accepting connection
*/
-Socket* ServerSocket::accept(int timeout) throw (SocketException) {
+Socket* ServerSocket::accept() throw (SocketException) {
if(server_id == -1)
throw SocketException(InvalidSockExcp, "Invalid server socket.",
"ServerSocket::accept");
@@ -214,25 +210,9 @@
sockaddr_in client_address;
int address_length = sizeof(struct sockaddr_in);
- /**
- * In order to add a timeout for accepting connections ( else it will
- * wait for a connection forever ), we introduce a fork process
- * that will wait for the timeout to achieve, and if no client has
- * connected at this time, it will kill the accept process.
- */
- int pid;
- if((pid = fork())) {
- // father process : waiting for the timeout to achieve
- Thread::sleep(timeout);
- // timeout achieves : father kills his son
- kill(pid, SIGKILL);
- }
- else {
- // son process : waiting for a connection...
- client_id = ::accept(server_id, (sockaddr *) &client_address,
- (socklen_t *) &address_length);
- }
-
+ client_id = ::accept(server_id, (sockaddr *) &client_address,
+ (socklen_t *) &address_length);
+
if(client_id <= 0)
throw SocketException(NotAcceptedSockExcp, "Received socket is invalid.",
"ServerSocket::accept");
Index: ServerSocket.h
===================================================================
RCS file: /cvsroot/sharedaemon/sharedaemon-ui-web/src/server/network/ServerSocket.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- ServerSocket.h 26 Dec 2003 22:56:42 -0000 1.2
+++ ServerSocket.h 27 Dec 2003 10:27:10 -0000 1.3
@@ -114,11 +114,10 @@
/**
* Accepts a connection.
*
- * @param timeout
* @return Socket* - The connected socket.
* @throw SocketException
*/
- Socket* accept(int timeout = 3) throw (SocketException);
+ Socket* accept() throw (SocketException);
};
|