@@ -40,10 +40,11 @@ #import "OFTimer.h" #import "OFTimer+Private.h" #import "OFDate.h" #import "OFObserveFailedException.h" +#import "OFWriteFailedException.h" #include "OFRunLoopConstants.inc" static OFRunLoop *mainRunLoop = nil; @@ -567,19 +568,24 @@ size_t dataLength = _data.count * _data.itemSize; OFData *newData, *oldData; @try { const char *dataItems = _data.items; + length = dataLength - _writtenLength; + [object writeBuffer: dataItems + _writtenLength length: length]; + } @catch (OFWriteFailedException *e) { + length = e.bytesWritten; - length = [object writeBuffer: dataItems + _writtenLength - length: dataLength - _writtenLength]; + if (e.errNo != EWOULDBLOCK) + exception = e; } @catch (id e) { length = 0; exception = e; } _writtenLength += length; + OFEnsure(_writtenLength <= dataLength); if (_writtenLength != dataLength && exception == nil) return true; # ifdef OF_HAVE_BLOCKS @@ -639,19 +645,24 @@ size_t cStringLength = [_string cStringLengthWithEncoding: _encoding]; OFString *newString, *oldString; @try { const char *cString = [_string cStringWithEncoding: _encoding]; + length = cStringLength - _writtenLength; + [object writeBuffer: cString + _writtenLength length: length]; + } @catch (OFWriteFailedException *e) { + length = e.bytesWritten; - length = [object writeBuffer: cString + _writtenLength - length: cStringLength - _writtenLength]; + if (e.errNo != EWOULDBLOCK) + exception = e; } @catch (id e) { length = 0; exception = e; } _writtenLength += length; + OFEnsure(_writtenLength <= cStringLength); if (_writtenLength != cStringLength && exception == nil) return true; # ifdef OF_HAVE_BLOCKS