Index: src/OFHTTPServer.h ================================================================== --- src/OFHTTPServer.h +++ src/OFHTTPServer.h @@ -126,12 +126,19 @@ /*! * @brief Starts the HTTP server in the current thread's runloop. */ - (void)start; +/*! + * @brief Stops the HTTP server, meaning it will not accept any new incoming + * connections, but still handle existing connections until they are + * finished or timed out. + */ +- (void)stop; + - (BOOL)OF_socket: (OFTCPSocket*)socket didAcceptSocket: (OFTCPSocket*)clientSocket exception: (OFException*)exception; @end @interface OFObject (OFHTTPServerDelegate) @end Index: src/OFHTTPServer.m ================================================================== --- src/OFHTTPServer.m +++ src/OFHTTPServer.m @@ -43,11 +43,10 @@ /* * FIXME: Currently, connections never time out, which means a DoS is possible. * TODO: Add support for chunked transfer encoding. * FIXME: Key normalization replaces headers like "DNT" with "Dnt". - * FIXME: It is currently not possible to stop the server. * FIXME: Errors are not reported to the user. */ static const char* status_code_to_string(short code) @@ -205,19 +204,20 @@ server: (OFHTTPServer*)server_ { self = [super init]; sock = [sock_ retain]; - server = server_; + server = [server_ retain]; state = AWAITING_PROLOG; return self; } - (void)dealloc { [sock release]; + [server release]; [host release]; [path release]; [headers release]; [POSTData release]; @@ -594,10 +594,17 @@ [listeningSocket asyncAcceptWithTarget: self selector: @selector(OF_socket: didAcceptSocket: exception:)]; } + +- (void)stop +{ + [listeningSocket cancelAsyncRequests]; + [listeningSocket release]; + listeningSocket = nil; +} - (BOOL)OF_socket: (OFTCPSocket*)socket didAcceptSocket: (OFTCPSocket*)clientSocket exception: (OFException*)exception {