@@ -26,26 +26,26 @@ #ifdef HAVE_FCNTL_H # include #endif -#ifdef OF_HAVE_SOCKETS -# import "socket_helpers.h" -#endif - #include "platform.h" #if !defined(OF_WINDOWS) && !defined(OF_MORPHOS) # include #endif #import "OFStream.h" #import "OFStream+Private.h" +#import "OFASPrintF.h" #import "OFData.h" #import "OFKernelEventObserver.h" #import "OFRunLoop+Private.h" #import "OFRunLoop.h" +#ifdef OF_HAVE_SOCKETS +# import "OFSocket+Private.h" +#endif #import "OFString.h" #import "OFSystemInfo.h" #import "OFInvalidArgumentException.h" #import "OFInvalidFormatException.h" @@ -54,13 +54,11 @@ #import "OFOutOfRangeException.h" #import "OFSetOptionFailedException.h" #import "OFTruncatedDataException.h" #import "OFWriteFailedException.h" -#import "of_asprintf.h" - -#define MIN_READ_SIZE 512 +#define minReadSize 512 @implementation OFStream @synthesize buffersWrites = _buffersWrites; @synthesize of_waitingForDelimiter = _waitingForDelimiter, delegate = _delegate; @@ -91,12 +89,12 @@ return self; } - (void)dealloc { - free(_readBufferMemory); - free(_writeBuffer); + OFFreeMemory(_readBufferMemory); + OFFreeMemory(_writeBuffer); [super dealloc]; } - (bool)lowlevelIsAtEndOfStream @@ -133,22 +131,22 @@ /* * For small sizes, it is cheaper to read more and cache the * remainder - even if that means more copying of data - than * to do a syscall for every read. */ - if (length < MIN_READ_SIZE) { - char tmp[MIN_READ_SIZE], *readBuffer; + if (length < minReadSize) { + char tmp[minReadSize], *readBuffer; size_t bytesRead; - bytesRead = [self - lowlevelReadIntoBuffer: tmp - length: MIN_READ_SIZE]; + bytesRead = [self lowlevelReadIntoBuffer: tmp + length: minReadSize]; if (bytesRead > length) { memcpy(buffer, tmp, length); - readBuffer = of_alloc(bytesRead - length, 1); + readBuffer = OFAllocMemory(bytesRead - length, + 1); memcpy(readBuffer, tmp + length, bytesRead - length); _readBuffer = _readBufferMemory = readBuffer; _readBufferLength = bytesRead - length; @@ -165,11 +163,11 @@ if (length >= _readBufferLength) { size_t ret = _readBufferLength; memcpy(buffer, _readBuffer, _readBufferLength); - free(_readBufferMemory); + OFFreeMemory(_readBufferMemory); _readBuffer = _readBufferMemory = NULL; _readBufferLength = 0; return ret; } else { @@ -198,16 +196,16 @@ #ifdef OF_HAVE_SOCKETS - (void)asyncReadIntoBuffer: (void *)buffer length: (size_t)length { [self asyncReadIntoBuffer: buffer length: length - runLoopMode: of_run_loop_mode_default]; + runLoopMode: OFDefaultRunLoopMode]; } - (void)asyncReadIntoBuffer: (void *)buffer length: (size_t)length - runLoopMode: (of_run_loop_mode_t)runLoopMode + runLoopMode: (OFRunLoopMode)runLoopMode { OFStream *stream = (OFStream *)self; [OFRunLoop of_addAsyncReadForStream: stream @@ -222,16 +220,16 @@ - (void)asyncReadIntoBuffer: (void *)buffer exactLength: (size_t)length { [self asyncReadIntoBuffer: buffer exactLength: length - runLoopMode: of_run_loop_mode_default]; + runLoopMode: OFDefaultRunLoopMode]; } - (void)asyncReadIntoBuffer: (void *)buffer exactLength: (size_t)length - runLoopMode: (of_run_loop_mode_t)runLoopMode + runLoopMode: (OFRunLoopMode)runLoopMode { OFStream *stream = (OFStream *)self; [OFRunLoop of_addAsyncReadForStream: stream @@ -245,22 +243,22 @@ } # ifdef OF_HAVE_BLOCKS - (void)asyncReadIntoBuffer: (void *)buffer length: (size_t)length - block: (of_stream_async_read_block_t)block + block: (OFStreamAsyncReadBlock)block { [self asyncReadIntoBuffer: buffer length: length - runLoopMode: of_run_loop_mode_default + runLoopMode: OFDefaultRunLoopMode block: block]; } - (void)asyncReadIntoBuffer: (void *)buffer length: (size_t)length - runLoopMode: (of_run_loop_mode_t)runLoopMode - block: (of_stream_async_read_block_t)block + runLoopMode: (OFRunLoopMode)runLoopMode + block: (OFStreamAsyncReadBlock)block { OFStream *stream = (OFStream *)self; [OFRunLoop of_addAsyncReadForStream: stream @@ -271,22 +269,22 @@ delegate: nil]; } - (void)asyncReadIntoBuffer: (void *)buffer exactLength: (size_t)length - block: (of_stream_async_read_block_t)block + block: (OFStreamAsyncReadBlock)block { [self asyncReadIntoBuffer: buffer exactLength: length - runLoopMode: of_run_loop_mode_default + runLoopMode: OFDefaultRunLoopMode block: block]; } - (void)asyncReadIntoBuffer: (void *)buffer exactLength: (size_t)length - runLoopMode: (of_run_loop_mode_t)runLoopMode - block: (of_stream_async_read_block_t)block + runLoopMode: (OFRunLoopMode)runLoopMode + block: (OFStreamAsyncReadBlock)block { OFStream *stream = (OFStream *)self; [OFRunLoop of_addAsyncReadForStream: stream @@ -308,39 +306,39 @@ - (uint16_t)readBigEndianInt16 { uint16_t ret; [self readIntoBuffer: (char *)&ret exactLength: 2]; - return OF_BSWAP16_IF_LE(ret); + return OFFromBigEndian16(ret); } - (uint32_t)readBigEndianInt32 { uint32_t ret; [self readIntoBuffer: (char *)&ret exactLength: 4]; - return OF_BSWAP32_IF_LE(ret); + return OFFromBigEndian32(ret); } - (uint64_t)readBigEndianInt64 { uint64_t ret; [self readIntoBuffer: (char *)&ret exactLength: 8]; - return OF_BSWAP64_IF_LE(ret); + return OFFromBigEndian64(ret); } - (float)readBigEndianFloat { float ret; [self readIntoBuffer: (char *)&ret exactLength: 4]; - return OF_BSWAP_FLOAT_IF_LE(ret); + return OFFromBigEndianFloat(ret); } - (double)readBigEndianDouble { double ret; [self readIntoBuffer: (char *)&ret exactLength: 8]; - return OF_BSWAP_DOUBLE_IF_LE(ret); + return OFFromBigEndianDouble(ret); } - (size_t)readBigEndianInt16sIntoBuffer: (uint16_t *)buffer count: (size_t)count { size_t size; @@ -352,11 +350,11 @@ [self readIntoBuffer: buffer exactLength: size]; #ifndef OF_BIG_ENDIAN for (size_t i = 0; i < count; i++) - buffer[i] = OF_BSWAP16(buffer[i]); + buffer[i] = OFByteSwap16(buffer[i]); #endif return size; } @@ -371,11 +369,11 @@ [self readIntoBuffer: buffer exactLength: size]; #ifndef OF_BIG_ENDIAN for (size_t i = 0; i < count; i++) - buffer[i] = OF_BSWAP32(buffer[i]); + buffer[i] = OFByteSwap32(buffer[i]); #endif return size; } @@ -390,11 +388,11 @@ [self readIntoBuffer: buffer exactLength: size]; #ifndef OF_BIG_ENDIAN for (size_t i = 0; i < count; i++) - buffer[i] = OF_BSWAP64(buffer[i]); + buffer[i] = OFByteSwap64(buffer[i]); #endif return size; } @@ -409,11 +407,11 @@ [self readIntoBuffer: buffer exactLength: size]; #ifndef OF_FLOAT_BIG_ENDIAN for (size_t i = 0; i < count; i++) - buffer[i] = OF_BSWAP_FLOAT(buffer[i]); + buffer[i] = OFByteSwapFloat(buffer[i]); #endif return size; } @@ -428,49 +426,49 @@ [self readIntoBuffer: buffer exactLength: size]; #ifndef OF_FLOAT_BIG_ENDIAN for (size_t i = 0; i < count; i++) - buffer[i] = OF_BSWAP_DOUBLE(buffer[i]); + buffer[i] = OFByteSwapDouble(buffer[i]); #endif return size; } - (uint16_t)readLittleEndianInt16 { uint16_t ret; [self readIntoBuffer: (char *)&ret exactLength: 2]; - return OF_BSWAP16_IF_BE(ret); + return OFFromLittleEndian16(ret); } - (uint32_t)readLittleEndianInt32 { uint32_t ret; [self readIntoBuffer: (char *)&ret exactLength: 4]; - return OF_BSWAP32_IF_BE(ret); + return OFFromLittleEndian32(ret); } - (uint64_t)readLittleEndianInt64 { uint64_t ret; [self readIntoBuffer: (char *)&ret exactLength: 8]; - return OF_BSWAP64_IF_BE(ret); + return OFFromLittleEndian64(ret); } - (float)readLittleEndianFloat { float ret; [self readIntoBuffer: (char *)&ret exactLength: 4]; - return OF_BSWAP_FLOAT_IF_BE(ret); + return OFFromLittleEndianFloat(ret); } - (double)readLittleEndianDouble { double ret; [self readIntoBuffer: (char *)&ret exactLength: 8]; - return OF_BSWAP_DOUBLE_IF_BE(ret); + return OFFromLittleEndianDouble(ret); } - (size_t)readLittleEndianInt16sIntoBuffer: (uint16_t *)buffer count: (size_t)count { @@ -483,11 +481,11 @@ [self readIntoBuffer: buffer exactLength: size]; #ifdef OF_BIG_ENDIAN for (size_t i = 0; i < count; i++) - buffer[i] = OF_BSWAP16(buffer[i]); + buffer[i] = OFByteSwap16(buffer[i]); #endif return size; } @@ -503,11 +501,11 @@ [self readIntoBuffer: buffer exactLength: size]; #ifdef OF_BIG_ENDIAN for (size_t i = 0; i < count; i++) - buffer[i] = OF_BSWAP32(buffer[i]); + buffer[i] = OFByteSwap32(buffer[i]); #endif return size; } @@ -523,11 +521,11 @@ [self readIntoBuffer: buffer exactLength: size]; #ifdef OF_BIG_ENDIAN for (size_t i = 0; i < count; i++) - buffer[i] = OF_BSWAP64(buffer[i]); + buffer[i] = OFByteSwap64(buffer[i]); #endif return size; } @@ -543,11 +541,11 @@ [self readIntoBuffer: buffer exactLength: size]; #ifdef OF_FLOAT_BIG_ENDIAN for (size_t i = 0; i < count; i++) - buffer[i] = OF_BSWAP_FLOAT(buffer[i]); + buffer[i] = OFByteSwapFloat(buffer[i]); #endif return size; } @@ -563,11 +561,11 @@ [self readIntoBuffer: buffer exactLength: size]; #ifdef OF_FLOAT_BIG_ENDIAN for (size_t i = 0; i < count; i++) - buffer[i] = OF_BSWAP_DOUBLE(buffer[i]); + buffer[i] = OFByteSwapDouble(buffer[i]); #endif return size; } @@ -582,19 +580,19 @@ char *buffer; if OF_UNLIKELY (count > SIZE_MAX / itemSize) @throw [OFOutOfRangeException exception]; - buffer = of_alloc(count, itemSize); + buffer = OFAllocMemory(count, itemSize); @try { [self readIntoBuffer: buffer exactLength: count * itemSize]; ret = [OFData dataWithItemsNoCopy: buffer count: count itemSize: itemSize freeWhenDone: true]; } @catch (id e) { - free(buffer); + OFFreeMemory(buffer); @throw e; } return ret; } @@ -601,50 +599,50 @@ - (OFData *)readDataUntilEndOfStream { OFMutableData *data = [OFMutableData data]; size_t pageSize = [OFSystemInfo pageSize]; - char *buffer = of_alloc(1, pageSize); + char *buffer = OFAllocMemory(1, pageSize); @try { while (!self.atEndOfStream) { size_t length = [self readIntoBuffer: buffer length: pageSize]; [data addItems: buffer count: length]; } } @finally { - free(buffer); + OFFreeMemory(buffer); } [data makeImmutable]; return data; } - (OFString *)readStringWithLength: (size_t)length { return [self readStringWithLength: length - encoding: OF_STRING_ENCODING_UTF_8]; + encoding: OFStringEncodingUTF8]; } - (OFString *)readStringWithLength: (size_t)length - encoding: (of_string_encoding_t)encoding + encoding: (OFStringEncoding)encoding { OFString *ret; - char *buffer = of_alloc(length + 1, 1); + char *buffer = OFAllocMemory(length + 1, 1); buffer[length] = 0; @try { [self readIntoBuffer: buffer exactLength: length]; ret = [OFString stringWithCString: buffer encoding: encoding]; } @finally { - free(buffer); + OFFreeMemory(buffer); } return ret; } -- (OFString *)tryReadLineWithEncoding: (of_string_encoding_t)encoding +- (OFString *)tryReadLineWithEncoding: (OFStringEncoding)encoding { size_t pageSize, bufferLength; char *buffer, *readBuffer; OFString *ret; @@ -671,11 +669,11 @@ } } /* Read and see if we got a newline or \0 */ pageSize = [OFSystemInfo pageSize]; - buffer = of_alloc(1, pageSize); + buffer = OFAllocMemory(1, pageSize); @try { if ([self lowlevelIsAtEndOfStream]) { size_t retLength; @@ -691,11 +689,11 @@ ret = [OFString stringWithCString: _readBuffer encoding: encoding length: retLength]; - free(_readBufferMemory); + OFFreeMemory(_readBufferMemory); _readBuffer = _readBufferMemory = NULL; _readBufferLength = 0; _waitingForDelimiter = false; return ret; @@ -707,11 +705,11 @@ /* Look if there's a newline or \0 */ for (size_t i = 0; i < bufferLength; i++) { if OF_UNLIKELY (buffer[i] == '\n' || buffer[i] == '\0') { size_t retLength = _readBufferLength + i; - char *retCString = of_alloc(retLength, 1); + char *retCString = OFAllocMemory(retLength, 1); if (_readBuffer != NULL) memcpy(retCString, _readBuffer, _readBufferLength); memcpy(retCString + _readBufferLength, @@ -730,38 +728,39 @@ if (bufferLength > 0) { /* * Append data to _readBuffer * to prevent loss of data. */ - readBuffer = of_alloc( + readBuffer = OFAllocMemory( _readBufferLength + bufferLength, 1); memcpy(readBuffer, _readBuffer, _readBufferLength); memcpy(readBuffer + _readBufferLength, buffer, bufferLength); - free(_readBufferMemory); + OFFreeMemory(_readBufferMemory); _readBuffer = readBuffer; _readBufferMemory = readBuffer; _readBufferLength += bufferLength; } @throw e; } @finally { - free(retCString); + OFFreeMemory(retCString); } - readBuffer = of_alloc(bufferLength - i - 1, 1); + readBuffer = OFAllocMemory(bufferLength - i - 1, + 1); if (readBuffer != NULL) memcpy(readBuffer, buffer + i + 1, bufferLength - i - 1); - free(_readBufferMemory); + OFFreeMemory(_readBufferMemory); _readBuffer = _readBufferMemory = readBuffer; _readBufferLength = bufferLength - i - 1; _waitingForDelimiter = false; return ret; @@ -768,35 +767,35 @@ } } /* There was no newline or \0 */ if (bufferLength > 0) { - readBuffer = of_alloc(_readBufferLength + bufferLength, - 1); + readBuffer = OFAllocMemory( + _readBufferLength + bufferLength, 1); memcpy(readBuffer, _readBuffer, _readBufferLength); memcpy(readBuffer + _readBufferLength, buffer, bufferLength); - free(_readBufferMemory); + OFFreeMemory(_readBufferMemory); _readBuffer = _readBufferMemory = readBuffer; _readBufferLength += bufferLength; } } @finally { - free(buffer); + OFFreeMemory(buffer); } _waitingForDelimiter = true; return nil; } - (OFString *)readLine { - return [self readLineWithEncoding: OF_STRING_ENCODING_UTF_8]; + return [self readLineWithEncoding: OFStringEncodingUTF8]; } -- (OFString *)readLineWithEncoding: (of_string_encoding_t)encoding +- (OFString *)readLineWithEncoding: (OFStringEncoding)encoding { OFString *line = nil; while ((line = [self tryReadLineWithEncoding: encoding]) == nil) if (self.atEndOfStream) @@ -806,22 +805,22 @@ } #ifdef OF_HAVE_SOCKETS - (void)asyncReadLine { - [self asyncReadLineWithEncoding: OF_STRING_ENCODING_UTF_8 - runLoopMode: of_run_loop_mode_default]; + [self asyncReadLineWithEncoding: OFStringEncodingUTF8 + runLoopMode: OFDefaultRunLoopMode]; } -- (void)asyncReadLineWithEncoding: (of_string_encoding_t)encoding +- (void)asyncReadLineWithEncoding: (OFStringEncoding)encoding { [self asyncReadLineWithEncoding: encoding - runLoopMode: of_run_loop_mode_default]; + runLoopMode: OFDefaultRunLoopMode]; } -- (void)asyncReadLineWithEncoding: (of_string_encoding_t)encoding - runLoopMode: (of_run_loop_mode_t)runLoopMode +- (void)asyncReadLineWithEncoding: (OFStringEncoding)encoding + runLoopMode: (OFRunLoopMode)runLoopMode { OFStream *stream = (OFStream *)self; [OFRunLoop of_addAsyncReadLineForStream: stream @@ -832,28 +831,28 @@ # endif delegate: _delegate]; } # ifdef OF_HAVE_BLOCKS -- (void)asyncReadLineWithBlock: (of_stream_async_read_line_block_t)block +- (void)asyncReadLineWithBlock: (OFStreamAsyncReadLineBlock)block { - [self asyncReadLineWithEncoding: OF_STRING_ENCODING_UTF_8 - runLoopMode: of_run_loop_mode_default + [self asyncReadLineWithEncoding: OFStringEncodingUTF8 + runLoopMode: OFDefaultRunLoopMode block: block]; } -- (void)asyncReadLineWithEncoding: (of_string_encoding_t)encoding - block: (of_stream_async_read_line_block_t)block +- (void)asyncReadLineWithEncoding: (OFStringEncoding)encoding + block: (OFStreamAsyncReadLineBlock)block { [self asyncReadLineWithEncoding: encoding - runLoopMode: of_run_loop_mode_default + runLoopMode: OFDefaultRunLoopMode block: block]; } -- (void)asyncReadLineWithEncoding: (of_string_encoding_t)encoding - runLoopMode: (of_run_loop_mode_t)runLoopMode - block: (of_stream_async_read_line_block_t)block +- (void)asyncReadLineWithEncoding: (OFStringEncoding)encoding + runLoopMode: (OFRunLoopMode)runLoopMode + block: (OFStreamAsyncReadLineBlock)block { OFStream *stream = (OFStream *)self; [OFRunLoop of_addAsyncReadLineForStream: stream @@ -865,15 +864,15 @@ # endif #endif - (OFString *)tryReadLine { - return [self tryReadLineWithEncoding: OF_STRING_ENCODING_UTF_8]; + return [self tryReadLineWithEncoding: OFStringEncodingUTF8]; } - (OFString *)tryReadTillDelimiter: (OFString *)delimiter - encoding: (of_string_encoding_t)encoding + encoding: (OFStringEncoding)encoding { const char *delimiterCString; size_t j, delimiterLength, pageSize, bufferLength; char *buffer, *readBuffer; OFString *ret; @@ -909,11 +908,11 @@ } } /* Read and see if we got a delimiter or \0 */ pageSize = [OFSystemInfo pageSize]; - buffer = of_alloc(1, pageSize); + buffer = OFAllocMemory(1, pageSize); @try { if ([self lowlevelIsAtEndOfStream]) { if (_readBuffer == NULL) { _waitingForDelimiter = false; @@ -922,11 +921,11 @@ ret = [OFString stringWithCString: _readBuffer encoding: encoding length: _readBufferLength]; - free(_readBufferMemory); + OFFreeMemory(_readBufferMemory); _readBuffer = _readBufferMemory = NULL; _readBufferLength = 0; _waitingForDelimiter = false; return ret; @@ -947,11 +946,11 @@ if (buffer[i] == '\0') delimiterLength = 1; retLength = _readBufferLength + i + 1 - delimiterLength; - retCString = of_alloc(retLength, 1); + retCString = OFAllocMemory(retLength, 1); if (_readBuffer != NULL && _readBufferLength <= retLength) memcpy(retCString, _readBuffer, _readBufferLength); @@ -971,38 +970,39 @@ if (bufferLength > 0) { /* * Append data to _readBuffer * to prevent loss of data. */ - readBuffer = of_alloc( + readBuffer = OFAllocMemory( _readBufferLength + bufferLength, 1); memcpy(readBuffer, _readBuffer, _readBufferLength); memcpy(readBuffer + _readBufferLength, buffer, bufferLength); - free(_readBufferMemory); + OFFreeMemory(_readBufferMemory); _readBuffer = readBuffer; _readBufferMemory = readBuffer; _readBufferLength += bufferLength; } @throw e; } @finally { - free(retCString); + OFFreeMemory(retCString); } - readBuffer = of_alloc(bufferLength - i - 1, 1); + readBuffer = OFAllocMemory(bufferLength - i - 1, + 1); if (readBuffer != NULL) memcpy(readBuffer, buffer + i + 1, bufferLength - i - 1); - free(_readBufferMemory); + OFFreeMemory(_readBufferMemory); _readBuffer = _readBufferMemory = readBuffer; _readBufferLength = bufferLength - i - 1; _waitingForDelimiter = false; return ret; @@ -1009,23 +1009,23 @@ } } /* Neither the delimiter nor \0 was found */ if (bufferLength > 0) { - readBuffer = of_alloc(_readBufferLength + bufferLength, - 1); + readBuffer = OFAllocMemory( + _readBufferLength + bufferLength, 1); memcpy(readBuffer, _readBuffer, _readBufferLength); memcpy(readBuffer + _readBufferLength, buffer, bufferLength); - free(_readBufferMemory); + OFFreeMemory(_readBufferMemory); _readBuffer = _readBufferMemory = readBuffer; _readBufferLength += bufferLength; } } @finally { - free(buffer); + OFFreeMemory(buffer); } _waitingForDelimiter = true; return nil; } @@ -1032,15 +1032,15 @@ - (OFString *)readTillDelimiter: (OFString *)delimiter { return [self readTillDelimiter: delimiter - encoding: OF_STRING_ENCODING_UTF_8]; + encoding: OFStringEncodingUTF8]; } - (OFString *)readTillDelimiter: (OFString *)delimiter - encoding: (of_string_encoding_t)encoding + encoding: (OFStringEncoding)encoding { OFString *ret = nil; while ((ret = [self tryReadTillDelimiter: delimiter encoding: encoding]) == nil) @@ -1051,21 +1051,21 @@ } - (OFString *)tryReadTillDelimiter: (OFString *)delimiter { return [self tryReadTillDelimiter: delimiter - encoding: OF_STRING_ENCODING_UTF_8]; + encoding: OFStringEncodingUTF8]; } - (void)flushWriteBuffer { if (_writeBuffer == NULL) return; [self lowlevelWriteBuffer: _writeBuffer length: _writeBufferLength]; - free(_writeBuffer); + OFFreeMemory(_writeBuffer); _writeBuffer = NULL; _writeBufferLength = 0; } - (size_t)writeBuffer: (const void *)buffer @@ -1082,11 +1082,11 @@ bytesWritten: bytesWritten errNo: 0]; return bytesWritten; } else { - _writeBuffer = of_realloc(_writeBuffer, + _writeBuffer = OFResizeMemory(_writeBuffer, _writeBufferLength + length, 1); memcpy(_writeBuffer + _writeBufferLength, buffer, length); _writeBufferLength += length; return length; @@ -1094,15 +1094,14 @@ } #ifdef OF_HAVE_SOCKETS - (void)asyncWriteData: (OFData *)data { - [self asyncWriteData: data runLoopMode: of_run_loop_mode_default]; + [self asyncWriteData: data runLoopMode: OFDefaultRunLoopMode]; } -- (void)asyncWriteData: (OFData *)data - runLoopMode: (of_run_loop_mode_t)runLoopMode +- (void)asyncWriteData: (OFData *)data runLoopMode: (OFRunLoopMode)runLoopMode { OFStream *stream = (OFStream *)self; [OFRunLoop of_addAsyncWriteForStream: stream @@ -1115,25 +1114,25 @@ } - (void)asyncWriteString: (OFString *)string { [self asyncWriteString: string - encoding: OF_STRING_ENCODING_UTF_8 - runLoopMode: of_run_loop_mode_default]; + encoding: OFStringEncodingUTF8 + runLoopMode: OFDefaultRunLoopMode]; } - (void)asyncWriteString: (OFString *)string - encoding: (of_string_encoding_t)encoding + encoding: (OFStringEncoding)encoding { [self asyncWriteString: string encoding: encoding - runLoopMode: of_run_loop_mode_default]; + runLoopMode: OFDefaultRunLoopMode]; } - (void)asyncWriteString: (OFString *)string - encoding: (of_string_encoding_t)encoding - runLoopMode: (of_run_loop_mode_t)runLoopMode + encoding: (OFStringEncoding)encoding + runLoopMode: (OFRunLoopMode)runLoopMode { OFStream *stream = (OFStream *)self; [OFRunLoop of_addAsyncWriteForStream: stream @@ -1145,21 +1144,20 @@ # endif delegate: _delegate]; } # ifdef OF_HAVE_BLOCKS -- (void)asyncWriteData: (OFData *)data - block: (of_stream_async_write_data_block_t)block +- (void)asyncWriteData: (OFData *)data block: (OFStreamAsyncWriteDataBlock)block { [self asyncWriteData: data - runLoopMode: of_run_loop_mode_default + runLoopMode: OFDefaultRunLoopMode block: block]; } - (void)asyncWriteData: (OFData *)data - runLoopMode: (of_run_loop_mode_t)runLoopMode - block: (of_stream_async_write_data_block_t)block + runLoopMode: (OFRunLoopMode)runLoopMode + block: (OFStreamAsyncWriteDataBlock)block { OFStream *stream = (OFStream *)self; [OFRunLoop of_addAsyncWriteForStream: stream @@ -1168,32 +1166,32 @@ block: block delegate: nil]; } - (void)asyncWriteString: (OFString *)string - block: (of_stream_async_write_string_block_t)block + block: (OFStreamAsyncWriteStringBlock)block { [self asyncWriteString: string - encoding: OF_STRING_ENCODING_UTF_8 - runLoopMode: of_run_loop_mode_default + encoding: OFStringEncodingUTF8 + runLoopMode: OFDefaultRunLoopMode block: block]; } - (void)asyncWriteString: (OFString *)string - encoding: (of_string_encoding_t)encoding - block: (of_stream_async_write_string_block_t)block + encoding: (OFStringEncoding)encoding + block: (OFStreamAsyncWriteStringBlock)block { [self asyncWriteString: string encoding: encoding - runLoopMode: of_run_loop_mode_default + runLoopMode: OFDefaultRunLoopMode block: block]; } - (void)asyncWriteString: (OFString *)string - encoding: (of_string_encoding_t)encoding - runLoopMode: (of_run_loop_mode_t)runLoopMode - block: (of_stream_async_write_string_block_t)block + encoding: (OFStringEncoding)encoding + runLoopMode: (OFRunLoopMode)runLoopMode + block: (OFStreamAsyncWriteStringBlock)block { OFStream *stream = (OFStream *)self; [OFRunLoop of_addAsyncWriteForStream: stream @@ -1211,35 +1209,35 @@ [self writeBuffer: (char *)&int8 length: 1]; } - (void)writeBigEndianInt16: (uint16_t)int16 { - int16 = OF_BSWAP16_IF_LE(int16); + int16 = OFToBigEndian16(int16); [self writeBuffer: (char *)&int16 length: 2]; } - (void)writeBigEndianInt32: (uint32_t)int32 { - int32 = OF_BSWAP32_IF_LE(int32); + int32 = OFToBigEndian32(int32); [self writeBuffer: (char *)&int32 length: 4]; } - (void)writeBigEndianInt64: (uint64_t)int64 { - int64 = OF_BSWAP64_IF_LE(int64); + int64 = OFToBigEndian64(int64); [self writeBuffer: (char *)&int64 length: 8]; } - (void)writeBigEndianFloat: (float)float_ { - float_ = OF_BSWAP_FLOAT_IF_LE(float_); + float_ = OFToBigEndianFloat(float_); [self writeBuffer: (char *)&float_ length: 4]; } - (void)writeBigEndianDouble: (double)double_ { - double_ = OF_BSWAP_DOUBLE_IF_LE(double_); + double_ = OFToBigEndianDouble(double_); [self writeBuffer: (char *)&double_ length: 8]; } - (size_t)writeBigEndianInt16s: (const uint16_t *)buffer count: (size_t)count { @@ -1251,19 +1249,19 @@ size = count * sizeof(uint16_t); #ifdef OF_BIG_ENDIAN [self writeBuffer: buffer length: size]; #else - uint16_t *tmp = of_alloc(count, sizeof(uint16_t)); + uint16_t *tmp = OFAllocMemory(count, sizeof(uint16_t)); @try { for (size_t i = 0; i < count; i++) - tmp[i] = OF_BSWAP16(buffer[i]); + tmp[i] = OFByteSwap16(buffer[i]); [self writeBuffer: tmp length: size]; } @finally { - free(tmp); + OFFreeMemory(tmp); } #endif return size; } @@ -1278,19 +1276,19 @@ size = count * sizeof(uint32_t); #ifdef OF_BIG_ENDIAN [self writeBuffer: buffer length: size]; #else - uint32_t *tmp = of_alloc(count, sizeof(uint32_t)); + uint32_t *tmp = OFAllocMemory(count, sizeof(uint32_t)); @try { for (size_t i = 0; i < count; i++) - tmp[i] = OF_BSWAP32(buffer[i]); + tmp[i] = OFByteSwap32(buffer[i]); [self writeBuffer: tmp length: size]; } @finally { - free(tmp); + OFFreeMemory(tmp); } #endif return size; } @@ -1305,19 +1303,19 @@ size = count * sizeof(uint64_t); #ifdef OF_BIG_ENDIAN [self writeBuffer: buffer length: size]; #else - uint64_t *tmp = of_alloc(count, sizeof(uint64_t)); + uint64_t *tmp = OFAllocMemory(count, sizeof(uint64_t)); @try { for (size_t i = 0; i < count; i++) - tmp[i] = OF_BSWAP64(buffer[i]); + tmp[i] = OFByteSwap64(buffer[i]); [self writeBuffer: tmp length: size]; } @finally { - free(tmp); + OFFreeMemory(tmp); } #endif return size; } @@ -1332,19 +1330,19 @@ size = count * sizeof(float); #ifdef OF_FLOAT_BIG_ENDIAN [self writeBuffer: buffer length: size]; #else - float *tmp = of_alloc(count, sizeof(float)); + float *tmp = OFAllocMemory(count, sizeof(float)); @try { for (size_t i = 0; i < count; i++) - tmp[i] = OF_BSWAP_FLOAT(buffer[i]); + tmp[i] = OFByteSwapFloat(buffer[i]); [self writeBuffer: tmp length: size]; } @finally { - free(tmp); + OFFreeMemory(tmp); } #endif return size; } @@ -1359,52 +1357,52 @@ size = count * sizeof(double); #ifdef OF_FLOAT_BIG_ENDIAN [self writeBuffer: buffer length: size]; #else - double *tmp = of_alloc(count, sizeof(double)); + double *tmp = OFAllocMemory(count, sizeof(double)); @try { for (size_t i = 0; i < count; i++) - tmp[i] = OF_BSWAP_DOUBLE(buffer[i]); + tmp[i] = OFByteSwapDouble(buffer[i]); [self writeBuffer: tmp length: size]; } @finally { - free(tmp); + OFFreeMemory(tmp); } #endif return size; } - (void)writeLittleEndianInt16: (uint16_t)int16 { - int16 = OF_BSWAP16_IF_BE(int16); + int16 = OFToLittleEndian16(int16); [self writeBuffer: (char *)&int16 length: 2]; } - (void)writeLittleEndianInt32: (uint32_t)int32 { - int32 = OF_BSWAP32_IF_BE(int32); + int32 = OFToLittleEndian32(int32); [self writeBuffer: (char *)&int32 length: 4]; } - (void)writeLittleEndianInt64: (uint64_t)int64 { - int64 = OF_BSWAP64_IF_BE(int64); + int64 = OFToLittleEndian64(int64); [self writeBuffer: (char *)&int64 length: 8]; } - (void)writeLittleEndianFloat: (float)float_ { - float_ = OF_BSWAP_FLOAT_IF_BE(float_); + float_ = OFToLittleEndianFloat(float_); [self writeBuffer: (char *)&float_ length: 4]; } - (void)writeLittleEndianDouble: (double)double_ { - double_ = OF_BSWAP_DOUBLE_IF_BE(double_); + double_ = OFToLittleEndianDouble(double_); [self writeBuffer: (char *)&double_ length: 8]; } - (size_t)writeLittleEndianInt16s: (const uint16_t *)buffer count: (size_t)count { @@ -1416,19 +1414,19 @@ size = count * sizeof(uint16_t); #ifndef OF_BIG_ENDIAN [self writeBuffer: buffer length: size]; #else - uint16_t *tmp = of_alloc(count, sizeof(uint16_t)); + uint16_t *tmp = OFAllocMemory(count, sizeof(uint16_t)); @try { for (size_t i = 0; i < count; i++) - tmp[i] = OF_BSWAP16(buffer[i]); + tmp[i] = OFByteSwap16(buffer[i]); [self writeBuffer: tmp length: size]; } @finally { - free(tmp); + OFFreeMemory(tmp); } #endif return size; } @@ -1443,19 +1441,19 @@ size = count * sizeof(uint32_t); #ifndef OF_BIG_ENDIAN [self writeBuffer: buffer length: size]; #else - uint32_t *tmp = of_alloc(count, sizeof(uint32_t)); + uint32_t *tmp = OFAllocMemory(count, sizeof(uint32_t)); @try { for (size_t i = 0; i < count; i++) - tmp[i] = OF_BSWAP32(buffer[i]); + tmp[i] = OFByteSwap32(buffer[i]); [self writeBuffer: tmp length: size]; } @finally { - free(tmp); + OFFreeMemory(tmp); } #endif return size; } @@ -1470,19 +1468,19 @@ size = count * sizeof(uint64_t); #ifndef OF_BIG_ENDIAN [self writeBuffer: buffer length: size]; #else - uint64_t *tmp = of_alloc(count, sizeof(uint64_t)); + uint64_t *tmp = OFAllocMemory(count, sizeof(uint64_t)); @try { for (size_t i = 0; i < count; i++) - tmp[i] = OF_BSWAP64(buffer[i]); + tmp[i] = OFByteSwap64(buffer[i]); [self writeBuffer: tmp length: size]; } @finally { - free(tmp); + OFFreeMemory(tmp); } #endif return size; } @@ -1497,19 +1495,19 @@ size = count * sizeof(float); #ifndef OF_FLOAT_BIG_ENDIAN [self writeBuffer: buffer length: size]; #else - float *tmp = of_alloc(count, sizeof(float)); + float *tmp = OFAllocMemory(count, sizeof(float)); @try { for (size_t i = 0; i < count; i++) - tmp[i] = OF_BSWAP_FLOAT(buffer[i]); + tmp[i] = OFByteSwapFloat(buffer[i]); [self writeBuffer: tmp length: size]; } @finally { - free(tmp); + OFFreeMemory(tmp); } #endif return size; } @@ -1524,19 +1522,19 @@ size = count * sizeof(double); #ifndef OF_FLOAT_BIG_ENDIAN [self writeBuffer: buffer length: size]; #else - double *tmp = of_alloc(count, sizeof(double)); + double *tmp = OFAllocMemory(count, sizeof(double)); @try { for (size_t i = 0; i < count; i++) - tmp[i] = OF_BSWAP_DOUBLE(buffer[i]); + tmp[i] = OFByteSwapDouble(buffer[i]); [self writeBuffer: tmp length: size]; } @finally { - free(tmp); + OFFreeMemory(tmp); } #endif return size; } @@ -1559,15 +1557,14 @@ return length; } - (size_t)writeString: (OFString *)string { - return [self writeString: string encoding: OF_STRING_ENCODING_UTF_8]; + return [self writeString: string encoding: OFStringEncodingUTF8]; } -- (size_t)writeString: (OFString *)string - encoding: (of_string_encoding_t)encoding +- (size_t)writeString: (OFString *)string encoding: (OFStringEncoding)encoding { void *pool; size_t length; if (string == nil) @@ -1584,28 +1581,28 @@ return length; } - (size_t)writeLine: (OFString *)string { - return [self writeLine: string encoding: OF_STRING_ENCODING_UTF_8]; + return [self writeLine: string encoding: OFStringEncodingUTF8]; } -- (size_t)writeLine: (OFString *)string encoding: (of_string_encoding_t)encoding +- (size_t)writeLine: (OFString *)string encoding: (OFStringEncoding)encoding { size_t stringLength = [string cStringLengthWithEncoding: encoding]; char *buffer; - buffer = of_alloc(stringLength + 1, 1); + buffer = OFAllocMemory(stringLength + 1, 1); @try { memcpy(buffer, [string cStringWithEncoding: encoding], stringLength); buffer[stringLength] = '\n'; [self writeBuffer: buffer length: stringLength + 1]; } @finally { - free(buffer); + OFFreeMemory(buffer); } return stringLength + 1; } @@ -1627,11 +1624,11 @@ int length; if (format == nil) @throw [OFInvalidArgumentException exception]; - if ((length = of_vasprintf(&UTF8String, format.UTF8String, + if ((length = OFVASPrintF(&UTF8String, format.UTF8String, arguments)) == -1) @throw [OFInvalidFormatException exception]; @try { [self writeBuffer: UTF8String length: length]; @@ -1731,11 +1728,11 @@ #ifdef OF_HAVE_SOCKETS - (void)cancelAsyncRequests { [OFRunLoop of_cancelAsyncRequestsForObject: self - mode: of_run_loop_mode_default]; + mode: OFDefaultRunLoopMode]; } #endif - (void)unreadFromBuffer: (const void *)buffer length: (size_t)length { @@ -1742,28 +1739,28 @@ char *readBuffer; if (length > SIZE_MAX - _readBufferLength) @throw [OFOutOfRangeException exception]; - readBuffer = of_alloc(_readBufferLength + length, 1); + readBuffer = OFAllocMemory(_readBufferLength + length, 1); memcpy(readBuffer, buffer, length); memcpy(readBuffer + length, _readBuffer, _readBufferLength); - free(_readBufferMemory); + OFFreeMemory(_readBufferMemory); _readBuffer = _readBufferMemory = readBuffer; _readBufferLength += length; } - (void)close { - free(_readBufferMemory); + OFFreeMemory(_readBufferMemory); _readBuffer = _readBufferMemory = NULL; _readBufferLength = 0; - free(_writeBuffer); + OFFreeMemory(_writeBuffer); _writeBuffer = NULL; _writeBufferLength = 0; _buffersWrites = false; _waitingForDelimiter = false; } @end