@@ -48,15 +48,11 @@ /* * FIXME: Key normalization replaces headers like "DNT" with "Dnt". * FIXME: Errors are not reported to the user. */ -@interface OFHTTPServer () -- (bool)of_socket: (OFTCPSocket *)sock - didAcceptSocket: (OFTCPSocket *)clientSocket - context: (id)context - exception: (id)exception; +@interface OFHTTPServer () @end @interface OFHTTPServerResponse: OFHTTPResponse { OF_KINDOF(OFTCPSocket *) _socket; @@ -68,11 +64,11 @@ - (instancetype)initWithSocket: (OF_KINDOF(OFTCPSocket *))sock server: (OFHTTPServer *)server request: (OFHTTPRequest *)request; @end -@interface OFHTTPServer_Connection: OFObject +@interface OFHTTPServer_Connection: OFObject { @public OF_KINDOF(OFTCPSocket *) _socket; OFHTTPServer *_server; OFTimer *_timer; @@ -778,45 +774,39 @@ _port = [_listeningSocket bindToHost: _host port: _port]; [_listeningSocket listen]; - [_listeningSocket asyncAcceptWithTarget: self - selector: @selector(of_socket: - didAcceptSocket:context: - exception:) - context: nil]; + [(OFTCPSocket *)_listeningSocket setDelegate: self]; + [_listeningSocket asyncAccept]; } - (void)stop { [_listeningSocket cancelAsyncRequests]; [_listeningSocket release]; _listeningSocket = nil; } -- (bool)of_socket: (OFTCPSocket *)sock - didAcceptSocket: (OFTCPSocket *)clientSocket - context: (id)context - exception: (id)exception -{ - OFHTTPServer_Connection *connection; - - if (exception != nil) { - if ([_delegate respondsToSelector: - @selector(server:didReceiveExceptionOnListeningSocket:)]) - return [_delegate server: self - didReceiveExceptionOnListeningSocket: exception]; - - return false; - } - - connection = [[[OFHTTPServer_Connection alloc] - initWithSocket: clientSocket +- (bool)socket: (OF_KINDOF(OFTCPSocket *))sock + didAcceptSocket: (OF_KINDOF(OFTCPSocket *))acceptedSocket +{ + OFHTTPServer_Connection *connection = [[[OFHTTPServer_Connection alloc] + initWithSocket: acceptedSocket server: self] autorelease]; - [clientSocket setDelegate: connection]; - [clientSocket asyncReadLine]; + [(OFTCPSocket *)acceptedSocket setDelegate: connection]; + [acceptedSocket asyncReadLine]; return true; } + +- (void)stream: (OF_KINDOF(OFStream *))stream + didFailWithException: (id)exception +{ + if ([_delegate respondsToSelector: + @selector(server:didReceiveExceptionOnListeningSocket:)]) + if ([_delegate server: self + didReceiveExceptionOnListeningSocket: exception]) + [stream asyncAccept]; +} @end