From: <mik...@us...> - 2003-12-27 10:27:13
|
Update of /cvsroot/sharedaemon/sharedaemon-ui-web/src/server/http In directory sc8-pr-cvs1:/tmp/cvs-serv24081/src/server/http Modified Files: HttpServerSocket.cpp Log Message: 27/12/2003 Mikael Barbeaux * Fixed a bug about accepting sockets and closing server. Index: HttpServerSocket.cpp =================================================================== RCS file: /cvsroot/sharedaemon/sharedaemon-ui-web/src/server/http/HttpServerSocket.cpp,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- HttpServerSocket.cpp 26 Dec 2003 22:56:41 -0000 1.1 +++ HttpServerSocket.cpp 27 Dec 2003 10:27:09 -0000 1.2 @@ -62,8 +62,14 @@ } catch(SocketException& se) { } - if(client == 0) + if(client == 0){ + continue; + } + if(cancel_th ==true) { + client->close(); + delete client; continue; + } // process the connection //theManager->addConnection(client); @@ -78,7 +84,7 @@ *writer << "<html><body>Request received !</body></html>"; writer->close(); HttpResponse response(writer); - response.setContentType("text/html"); cout << "ok" << endl; + response.setContentType("text/html"); client->sendHttpResponse(response); cout << "Closing socket..." << endl; client->close(); @@ -102,7 +108,23 @@ * Stops the server. */ void HttpServerSocket::stop() throw (SocketException) { - close(); cancel(); + + // make a connection for stopping accept() + int sd = socket(AF_INET, SOCK_STREAM, 0); + if(sd == -1) + throw SocketException(CantCreateSockExcp, "Cannot create socket.", + "HttpServerSocket::stop"); + struct sockaddr_in address; + address.sin_family = AF_INET; + address.sin_addr.s_addr = INADDR_ANY; + address.sin_port = htons(server_port); + int ret = ::connect(sd, (struct sockaddr *) &address, + sizeof(struct sockaddr_in)); + if(ret == -1) + throw SocketException(CantCreateSockExcp, "Cannot create socket.", + "HttpServerSocket::stop"); + + close(); } |