Index: src/OFFile.m ================================================================== --- src/OFFile.m +++ src/OFFile.m @@ -617,22 +617,18 @@ isAtEndOfStream = YES; return ret; } -- (size_t)_writeNBytes: (size_t)length - fromBuffer: (const void*)buffer +- (void)_writeNBytes: (size_t)length + fromBuffer: (const void*)buffer { - size_t ret; - if (fileDescriptor == -1 || isAtEndOfStream || - (ret = write(fileDescriptor, buffer, length)) < length) + write(fileDescriptor, buffer, length) < length) @throw [OFWriteFailedException newWithClass: isa stream: self requestedLength: length]; - - return ret; } - (void)_seekToOffset: (off_t)offset { if (lseek(fileDescriptor, offset, SEEK_SET) == -1) Index: src/OFStream.h ================================================================== --- src/OFStream.h +++ src/OFStream.h @@ -277,14 +277,13 @@ /** * Writes from a buffer into the stream. * * \param buffer The buffer from which the data is written to the stream * \param length The length of the data that should be written - * \return The number of bytes written */ -- (size_t)writeNBytes: (size_t)length - fromBuffer: (const void*)buffer; +- (void)writeNBytes: (size_t)length + fromBuffer: (const void*)buffer; /** * Writes a uint8_t into the stream. * * \param int8 A uint8_t Index: src/OFStream.m ================================================================== --- src/OFStream.m +++ src/OFStream.m @@ -78,12 +78,12 @@ { @throw [OFNotImplementedException newWithClass: isa selector: _cmd]; } -- (size_t)_writeNBytes: (size_t)length - fromBuffer: (const void*)buffer +- (void)_writeNBytes: (size_t)length + fromBuffer: (const void*)buffer { @throw [OFNotImplementedException newWithClass: isa selector: _cmd]; } @@ -623,23 +623,21 @@ [self freeMemory: writeBuffer]; writeBuffer = NULL; writeBufferLength = 0; } -- (size_t)writeNBytes: (size_t)length - fromBuffer: (const void*)buffer +- (void)writeNBytes: (size_t)length + fromBuffer: (const void*)buffer { if (!buffersWrites) - return [self _writeNBytes: length - fromBuffer: buffer]; + [self _writeNBytes: length + fromBuffer: buffer]; else { writeBuffer = [self resizeMemory: writeBuffer toSize: writeBufferLength + length]; memcpy(writeBuffer + writeBufferLength, buffer, length); writeBufferLength += length; - - return length; } } - (void)writeInt8: (uint8_t)int8 { @@ -727,38 +725,46 @@ fromBuffer: (char*)&double_]; } - (size_t)writeDataArray: (OFDataArray*)dataArray { - return [self writeNBytes: [dataArray count] * [dataArray itemSize] - fromBuffer: [dataArray cArray]]; + size_t length = [dataArray count] * [dataArray itemSize]; + + [self writeNBytes: length + fromBuffer: [dataArray cArray]]; + + return [dataArray count] * [dataArray itemSize]; } - (size_t)writeString: (OFString*)string { - return [self writeNBytes: [string cStringLength] - fromBuffer: [string cString]]; + size_t length = [string cStringLength]; + + [self writeNBytes: length + fromBuffer: [string cString]]; + + return length; } - (size_t)writeLine: (OFString*)string { - size_t retLength, stringLength = [string cStringLength]; + size_t stringLength = [string cStringLength]; char *buffer; buffer = [self allocMemoryWithSize: stringLength + 1]; @try { memcpy(buffer, [string cString], stringLength); buffer[stringLength] = '\n'; - retLength = [self writeNBytes: stringLength + 1 - fromBuffer: buffer]; + [self writeNBytes: stringLength + 1 + fromBuffer: buffer]; } @finally { [self freeMemory: buffer]; } - return retLength; + return stringLength + 1; } - (size_t)writeFormat: (OFString*)format, ... { va_list arguments; @@ -785,18 +791,17 @@ if ((length = of_vasprintf(&cString, [format cString], arguments)) == -1) @throw [OFInvalidFormatException newWithClass: isa]; @try { - return [self writeNBytes: length - fromBuffer: cString]; + [self writeNBytes: length + fromBuffer: cString]; } @finally { free(cString); } - /* Get rid of a warning, never reached anyway */ - assert(0); + return length; } - (size_t)pendingBytes { return cacheLength; Index: src/OFStreamSocket.m ================================================================== --- src/OFStreamSocket.m +++ src/OFStreamSocket.m @@ -98,15 +98,13 @@ isAtEndOfStream = YES; return ret; } -- (size_t)_writeNBytes: (size_t)length - fromBuffer: (const void*)buffer +- (void)_writeNBytes: (size_t)length + fromBuffer: (const void*)buffer { - ssize_t ret; - if (sock == INVALID_SOCKET) @throw [OFNotConnectedException newWithClass: isa socket: self]; if (isAtEndOfStream) { @@ -122,16 +120,14 @@ #endif @throw e; } - if ((ret = send(sock, buffer, length, 0)) == -1) + if (send(sock, buffer, length, 0) < length) @throw [OFWriteFailedException newWithClass: isa stream: self requestedLength: length]; - - return ret; } #ifdef _WIN32 - (void)setBlocking: (BOOL)enable {