Index: src/OFHTTPClient.m ================================================================== --- src/OFHTTPClient.m +++ src/OFHTTPClient.m @@ -545,23 +545,29 @@ } return ret; } -- (void)stream: (OF_KINDOF(OFStream *))sock - didFailWithException: (id)exception +- (void)stream: (OF_KINDOF(OFStream *))sock + didFailToReadWithException: (id)exception +{ + if ([exception isKindOfClass: [OFInvalidEncodingException class]]) + exception = [OFInvalidServerReplyException exception]; + + [self raiseException: exception]; +} + +- (void)stream: (OF_KINDOF(OFStream *))sock + didFailToWriteWithException: (id)exception { if ([exception isKindOfClass: [OFWriteFailedException class]] && ([exception errNo] == ECONNRESET || [exception errNo] == EPIPE)) { /* In case a keep-alive connection timed out */ [self closeAndReconnect]; return; } - if ([exception isKindOfClass: [OFInvalidEncodingException class]]) - exception = [OFInvalidServerReplyException exception]; - [self raiseException: exception]; } - (size_t)stream: (OF_KINDOF(OFStream *))sock didWriteBuffer: (const void **)request Index: src/OFHTTPServer.m ================================================================== --- src/OFHTTPServer.m +++ src/OFHTTPServer.m @@ -798,15 +798,15 @@ [acceptedSocket asyncReadLine]; return true; } -- (void)stream: (OF_KINDOF(OFStream *))stream - didFailWithException: (id)exception +- (void)stream: (OF_KINDOF(OFStream *))stream + didFailToAcceptWithException: (id)exception { if ([_delegate respondsToSelector: @selector(server:didReceiveExceptionOnListeningSocket:)]) if ([_delegate server: self didReceiveExceptionOnListeningSocket: exception]) [stream asyncAccept]; } @end Index: src/OFRunLoop.m ================================================================== --- src/OFRunLoop.m +++ src/OFRunLoop.m @@ -337,13 +337,13 @@ return [_delegate stream: object didReadIntoBuffer: _buffer length: length]; } else { if ([_delegate respondsToSelector: - @selector(stream:didFailWithException:)]) - [_delegate stream: object - didFailWithException: exception]; + @selector(stream:didFailToReadWithException:)]) + [_delegate stream: object + didFailToReadWithException: exception]; return false; } # ifdef OF_HAVE_BLOCKS } @@ -401,13 +401,13 @@ _readLength = 0; return true; } else { if ([_delegate respondsToSelector: - @selector(stream:didFailWithException:)]) - [_delegate stream: object - didFailWithException: exception]; + @selector(stream:didFailToReadWithException:)]) + [_delegate stream: object + didFailToReadWithException: exception]; return false; } # ifdef OF_HAVE_BLOCKS } @@ -452,13 +452,13 @@ return [_delegate stream: object didReadLine: line]; } else { if ([_delegate respondsToSelector: - @selector(stream:didFailWithException:)]) - [_delegate stream: object - didFailWithException: exception]; + @selector(stream:didFailToReadWithException:)]) + [_delegate stream: object + didFailToReadWithException: exception]; return false; } # ifdef OF_HAVE_BLOCKS } @@ -519,13 +519,13 @@ _writtenLength = 0; return true; } else { if ([_delegate respondsToSelector: - @selector(stream:didFailWithException:)]) - [_delegate stream: object - didFailWithException: exception]; + @selector(stream:didFailToWriteWithException:)]) + [_delegate stream: object + didFailToWriteWithException: exception]; return false; } # ifdef OF_HAVE_BLOCKS } @@ -589,13 +589,13 @@ return [_delegate socket: object didAcceptSocket: acceptedSocket]; } else { if ([_delegate respondsToSelector: - @selector(stream:didFailWithException:)]) - [_delegate stream: object - didFailWithException: exception]; + @selector(socket:didFailToAcceptWithException:)]) + [_delegate socket: object + didFailToAcceptWithException: exception]; return false; } # ifdef OF_HAVE_BLOCKS } Index: src/OFStream.h ================================================================== --- src/OFStream.h +++ src/OFStream.h @@ -95,11 +95,11 @@ * A delegate for OFStream. */ @protocol OFStreamDelegate @optional /*! - * @brief This method is called when data was read asynchronously from the + * @brief This method is called when data was read asynchronously from a * stream. * * @param stream The stream on which data was read * @param buffer A buffer with the data that has been read * @param length The length of the data that has been read @@ -108,11 +108,11 @@ - (bool)stream: (OF_KINDOF(OFStream *))stream didReadIntoBuffer: (void *)buffer length: (size_t)length; /*! - * @brief This method is called when a line was read asynchronously from the + * @brief This method is called when a line was read asynchronously from a * stream. * * @param stream The stream on which a line was read * @param line The line which has been read or `nil` when the end of stream * occurred @@ -120,11 +120,11 @@ */ - (bool)stream: (OF_KINDOF(OFStream *))stream didReadLine: (nullable OFString *)line; /*! - * @brief This method is called when data was written asynchronously to the + * @brief This method is called when data was written asynchronously to a * stream. * * @param stream The stream to which data was written * @param buffer A pointer to the buffer which was written to the stream. This * can be changed to point to a different buffer to be used on the @@ -138,17 +138,27 @@ didWriteBuffer: (const void *_Nonnull *_Nonnull)buffer length: (size_t)length; /*! * @brief This method is called when an exception occurred during an - * asynchronous operation on the stream. + * asynchronous read on a stream. + * + * @param stream The stream for which an exception occurred + * @param exception The exception which occurred for the stream + */ +- (void)stream: (OF_KINDOF(OFStream *))stream + didFailToReadWithException: (id)exception; + +/*! + * @brief This method is called when an exception occurred during an + * asynchronous write on a stream. * * @param stream The stream for which an exception occurred * @param exception The exception which occurred for the stream */ -- (void)stream: (OF_KINDOF(OFStream *))stream - didFailWithException: (id)exception; +- (void)stream: (OF_KINDOF(OFStream *))stream + didFailToWriteWithException: (id)exception; @end /*! * @class OFStream OFStream.h ObjFW/OFStream.h * Index: src/OFTCPSocket.h ================================================================== --- src/OFTCPSocket.h +++ src/OFTCPSocket.h @@ -76,10 +76,34 @@ * @param acceptedSocket The socket which has been accepted * @return A bool whether to accept the next incoming connection */ - (bool)socket: (OF_KINDOF(OFTCPSocket *))socket didAcceptSocket: (OF_KINDOF(OFTCPSocket *))acceptedSocket; + +/*! + * @brief This method is called when an exception occurred during an + * asynchronous connect. + * + * @param socket The socket for which an exception occurred + * @param exception The exception which occurred for the stream + * @param host The host to which the connection failed + * @param port The port on the host to which the connection failed + */ +- (void)socket: (OF_KINDOF(OFTCPSocket *))socket + didFailToConnectWithException: (id)exception + host: (OFString *)host + port: (uint16_t)port; + +/*! + * @brief This method is called when an exception occurred during an + * asynchronous accept. + * + * @param socket The socket for which an exception occurred + * @param exception The exception which occurred for the stream + */ +- (void)socket: (OF_KINDOF(OFTCPSocket *))socket + didFailToAcceptWithException: (id)exception; @end /*! * @class OFTCPSocket OFTCPSocket.h ObjFW/OFTCPSocket.h * Index: src/OFTCPSocket.m ================================================================== --- src/OFTCPSocket.m +++ src/OFTCPSocket.m @@ -218,14 +218,16 @@ @selector(socket:didConnectToHost:port:)]) [_delegate socket: _socket didConnectToHost: _host port: _port]; } else { - if ([_delegate respondsToSelector: - @selector(stream:didFailWithException:)]) - [_delegate stream: _socket - didFailWithException: _exception]; + if ([_delegate respondsToSelector: @selector(socket: + didFailToConnectWithException:host:port:)]) + [_delegate socket: _socket + didFailToConnectWithException: _exception + host: _host + port: _port]; } #ifdef OF_HAVE_BLOCKS } #endif } @@ -552,12 +554,19 @@ assert(0); return 0; } } -- (void)stream: (OF_KINDOF(OFStream *))sock - didFailWithException: (id)exception +- (void)stream: (OF_KINDOF(OFStream *))sock + didFailToReadWithException: (id)exception +{ + _exception = [exception retain]; + [self didConnect]; +} + +- (void)stream: (OF_KINDOF(OFStream *))sock + didFailToWriteWithException: (id)exception { _exception = [exception retain]; [self didConnect]; } @end @@ -575,12 +584,12 @@ port: (uint16_t)port { _done = true; } -- (void)stream: (OF_KINDOF(OFStream *))stream - didFailWithException: (id)exception +- (void)socket: (OF_KINDOF(OFTCPSocket *))sock + didFailToConnectWithException: (id)exception { _done = true; _exception = [exception retain]; } @end