Index: src/OFStream.h ================================================================== --- src/OFStream.h +++ src/OFStream.h @@ -965,12 +965,16 @@ - (nullable OFString *)tryReadTillDelimiter: (OFString *)delimiter encoding: (OFStringEncoding)encoding; /** * @brief Writes everything in the write buffer to the stream. + * + * @return Whether the write buffer was flushed entirely. On non-blocking + * sockets, this can return `false` if flushing the write buffer in its + * entirety would block. */ -- (void)flushWriteBuffer; +- (bool)flushWriteBuffer; /** * @brief Writes from a buffer into the stream. * * In non-blocking mode, if less than the specified length could be written, an Index: src/OFStream.m ================================================================== --- src/OFStream.m +++ src/OFStream.m @@ -1054,27 +1054,29 @@ { return [self tryReadTillDelimiter: delimiter encoding: OFStringEncodingUTF8]; } -- (void)flushWriteBuffer +- (bool)flushWriteBuffer { size_t bytesWritten; if (_writeBuffer == NULL) - return; + return true; bytesWritten = [self lowlevelWriteBuffer: _writeBuffer length: _writeBufferLength]; if (bytesWritten == 0) - return; + return false; if (bytesWritten == _writeBufferLength) { OFFreeMemory(_writeBuffer); _writeBuffer = NULL; _writeBufferLength = 0; + + return true; } OFEnsure(bytesWritten <= _writeBufferLength); memmove(_writeBuffer, _writeBuffer + bytesWritten, @@ -1084,10 +1086,12 @@ _writeBuffer = OFResizeMemory(_writeBuffer, _writeBufferLength, 1); } @catch (OFOutOfMemoryException *e) { /* We don't care, as we only made it smaller. */ } + + return false; } - (void)writeBuffer: (const void *)buffer length: (size_t)length { if (!_buffersWrites) {