Index: src/OFFile.m
==================================================================
--- src/OFFile.m
+++ src/OFFile.m
@@ -683,20 +683,20 @@
fd = fileDescriptor;
return self;
}
-- (BOOL)_isAtEndOfStream
+- (BOOL)lowlevelIsAtEndOfStream
{
if (fd == -1)
return YES;
return atEndOfStream;
}
-- (size_t)_readIntoBuffer: (void*)buffer
- length: (size_t)length
+- (size_t)lowlevelReadIntoBuffer: (void*)buffer
+ length: (size_t)length
{
ssize_t ret;
if (fd == -1 || atEndOfStream || (ret = read(fd, buffer, length)) < 0)
@throw [OFReadFailedException exceptionWithClass: [self class]
@@ -707,29 +707,29 @@
atEndOfStream = YES;
return ret;
}
-- (void)_writeBuffer: (const void*)buffer
- length: (size_t)length
+- (void)lowlevelWriteBuffer: (const void*)buffer
+ length: (size_t)length
{
if (fd == -1 || atEndOfStream || write(fd, buffer, length) < length)
@throw [OFWriteFailedException exceptionWithClass: [self class]
stream: self
requestedLength: length];
}
-- (void)_seekToOffset: (off_t)offset
+- (void)lowlevelSeekToOffset: (off_t)offset
{
if (lseek(fd, offset, SEEK_SET) == -1)
@throw [OFSeekFailedException exceptionWithClass: [self class]
stream: self
offset: offset
whence: SEEK_SET];
}
-- (off_t)_seekForwardWithOffset: (off_t)offset
+- (off_t)lowlevelSeekForwardWithOffset: (off_t)offset
{
off_t ret;
if ((ret = lseek(fd, offset, SEEK_CUR)) == -1)
@throw [OFSeekFailedException exceptionWithClass: [self class]
@@ -738,11 +738,11 @@
whence: SEEK_CUR];
return ret;
}
-- (off_t)_seekToOffsetRelativeToEnd: (off_t)offset
+- (off_t)lowlevelSeekToOffsetRelativeToEnd: (off_t)offset
{
off_t ret;
if ((ret = lseek(fd, offset, SEEK_END)) == -1)
@throw [OFSeekFailedException exceptionWithClass: [self class]
@@ -821,23 +821,23 @@
@throw [OFNotImplementedException exceptionWithClass: [self class]
selector: _cmd];
[super dealloc]; /* Get rid of stupid warning */
}
-- (void)_seekToOffset: (off_t)offset
+- (void)lowlevelSeekToOffset: (off_t)offset
{
@throw [OFNotImplementedException exceptionWithClass: [self class]
selector: _cmd];
}
-- (off_t)_seekForwardWithOffset: (off_t)offset
+- (off_t)lowlevelSeekForwardWithOffset: (off_t)offset
{
@throw [OFNotImplementedException exceptionWithClass: [self class]
selector: _cmd];
}
-- (off_t)_seekToOffsetRelativeToEnd: (off_t)offset
+- (off_t)lowlevelSeekToOffsetRelativeToEnd: (off_t)offset
{
@throw [OFNotImplementedException exceptionWithClass: [self class]
selector: _cmd];
}
@end
Index: src/OFProcess.m
==================================================================
--- src/OFProcess.m
+++ src/OFProcess.m
@@ -223,11 +223,11 @@
}
return self;
}
-- (BOOL)_isAtEndOfStream
+- (BOOL)lowlevelIsAtEndOfStream
{
#ifndef _WIN32
if (readPipe[0] == -1)
#else
if (readPipe[0] == NULL)
@@ -235,12 +235,12 @@
return YES;
return atEndOfStream;
}
-- (size_t)_readIntoBuffer: (void*)buffer
- length: (size_t)length
+- (size_t)lowlevelReadIntoBuffer: (void*)buffer
+ length: (size_t)length
{
#ifndef _WIN32
ssize_t ret;
#else
DWORD ret;
@@ -267,12 +267,12 @@
atEndOfStream = YES;
return ret;
}
-- (void)_writeBuffer: (const void*)buffer
- length: (size_t)length
+- (void)lowlevelWriteBuffer: (const void*)buffer
+ length: (size_t)length
{
#ifndef _WIN32
if (writePipe[1] == -1 || atEndOfStream ||
write(writePipe[1], buffer, length) < length)
#else
Index: src/OFSeekableStream.h
==================================================================
--- src/OFSeekableStream.h
+++ src/OFSeekableStream.h
@@ -26,16 +26,17 @@
#import "OFStream.h"
/**
* \brief A stream that supports seeking.
*
- * IMPORTANT: If you want to subclass this, override _seekToOffset:,
- * _seekForwardWithOffset: and _seekToOffsetRelativeToEnd:, but nothing else.
- * Those are not defined in the headers, but do the actual work.
- * OFSeekableStream uses those and makes them work together with the caching of
- * OFStream. If you override these methods without the _ prefix, you *WILL*
- * break caching, get broken results and seek to the wrong position!
+ * \note If you want to subclass this, override lowlevelSeekToOffset:,
+ * lowlevelSeekForwardWithOffset: and lowlevelSeekToOffsetRelativeToEnd:,
+ * but nothing else. Those are not defined in the headers, but do the
+ * actual work. OFSeekableStream uses those and makes them work together
+ * with the caching of OFStream. If you override these methods without
+ * the lowlevel prefix, you will break caching, get broken results
+ * and seek to the wrong position!
*/
@interface OFSeekableStream: OFStream
/**
* \brief Seeks to the specified absolute offset.
*
@@ -56,6 +57,42 @@
*
* \param offset The offset relative to the end of the stream
* \return The absolute offset
*/
- (off_t)seekToOffsetRelativeToEnd: (off_t)offset;
+
+/**
+ * \brief Seek the stream on the lowlevel.
+ *
+ * \warning Do not call this directly!
+ *
+ * Override this with this method with your actual seek implementation when
+ * subclassing!
+ *
+ * \param offset The offset to seek to
+ */
+- (void)lowlevelSeekToOffset: (off_t)offset;
+
+/**
+ * \brief Seek the stream on the lowlevel.
+ *
+ * \warning Do not call this directly!
+ *
+ * Override this with this method with your actual seek implementation when
+ * subclassing!
+ *
+ * \param offset The offset to seek forward to
+ */
+- (off_t)lowlevelSeekForwardWithOffset: (off_t)offset;
+
+/**
+ * \brief Seek the stream on the lowlevel.
+ *
+ * \warning Do not call this directly!
+ *
+ * Override this with this method with your actual seek implementation when
+ * subclassing!
+ *
+ * \param offset The offset to seek to, relative to the end
+ */
+- (off_t)lowlevelSeekToOffsetRelativeToEnd: (off_t)offset;
@end
Index: src/OFSeekableStream.m
==================================================================
--- src/OFSeekableStream.m
+++ src/OFSeekableStream.m
@@ -17,31 +17,31 @@
#import "OFSeekableStream.h"
#import "OFNotImplementedException.h"
@implementation OFSeekableStream
-- (void)_seekToOffset: (off_t)offset
+- (void)lowlevelSeekToOffset: (off_t)offset
{
@throw [OFNotImplementedException exceptionWithClass: [self class]
selector: _cmd];
}
-- (off_t)_seekForwardWithOffset: (off_t)offset
+- (off_t)lowlevelSeekForwardWithOffset: (off_t)offset
{
@throw [OFNotImplementedException exceptionWithClass: [self class]
selector: _cmd];
}
-- (off_t)_seekToOffsetRelativeToEnd: (off_t)offset
+- (off_t)lowlevelSeekToOffsetRelativeToEnd: (off_t)offset
{
@throw [OFNotImplementedException exceptionWithClass: [self class]
selector: _cmd];
}
- (void)seekToOffset: (off_t)offset
{
- [self _seekToOffset: offset];
+ [self lowlevelSeekToOffset: offset];
[self freeMemory: cache];
cache = NULL;
cacheLength = 0;
}
@@ -48,11 +48,11 @@
- (off_t)seekForwardWithOffset: (off_t)offset
{
off_t ret;
- ret = [self _seekForwardWithOffset: offset - cacheLength];
+ ret = [self lowlevelSeekForwardWithOffset: offset - cacheLength];
[self freeMemory: cache];
cache = NULL;
cacheLength = 0;
@@ -61,14 +61,14 @@
- (off_t)seekToOffsetRelativeToEnd: (off_t)offset
{
off_t ret;
- ret = [self _seekToOffsetRelativeToEnd: offset];
+ ret = [self lowlevelSeekToOffsetRelativeToEnd: offset];
[self freeMemory: cache];
cache = NULL;
cacheLength = 0;
return ret;
}
@end
Index: src/OFStream.h
==================================================================
--- src/OFStream.h
+++ src/OFStream.h
@@ -42,16 +42,16 @@
* retains it. This is so that the stream can be used as a key for a
* dictionary, so context can be associated with a stream. Using a
* stream in more than one thread at the same time is not thread-safe,
* even if copy was called to create one "instance" for every thread!
*
- * \warning If you want to subclass this, override _readIntoBuffer:length:,
- * _writeBuffer:length: and _isAtEndOfStream, but nothing else, as
- * those are are the methods that do the actual work. OFStream uses
- * those for all other methods and does all the caching and other
- * stuff for you. If you override these methods without the _ prefix,
- * you will break caching and get broken results!
+ * \note If you want to subclass this, override lowlevelReadIntoBuffer:length:,
+ * lowlevelWriteBuffer:length: and lowlevelIsAtEndOfStream, but nothing
+ * else, as those are are the methods that do the actual work. OFStream
+ * uses those for all other methods and does all the caching and other
+ * stuff for you. If you override these methods without the lowlevel
+ * prefix, you will break caching and get broken results!
*/
@interface OFStream: OFObject
{
char *cache;
char *writeBuffer;
@@ -881,13 +881,47 @@
/**
* \brief Closes the stream.
*/
- (void)close;
-- (size_t)_readIntoBuffer: (void*)buffer
- length: (size_t)length;
-- (void)_writeBuffer: (const void*)buffer
- length: (size_t)length;
-- (BOOL)_isAtEndOfStream;
+/**
+ * \brief Performs a lowlevel read.
+ *
+ * \warning Do not call this directly!
+ *
+ * Override this method with your actual read implementation when subclassing!
+ *
+ * \param buffer The buffer for the data to read
+ * \param length The length of the buffer
+ * \return The number of bytes read
+ */
+- (size_t)lowlevelReadIntoBuffer: (void*)buffer
+ length: (size_t)length;
+
+
+/**
+ * \brief Performs a lowlevel write.
+ *
+ * \warning Do not call this directly!
+ *
+ * Override this method with your actual write implementation when subclassing!
+ *
+ * \param buffer The buffer with the data to write
+ * \param length The length of the data to write
+ */
+- (void)lowlevelWriteBuffer: (const void*)buffer
+ length: (size_t)length;
+
+/**
+ * \brief Returns whether the lowlevel is at the end of the stream.
+ *
+ * \warning Do not call this directly!
+ *
+ * Override this method with your actual end of stream checking implementation
+ * when subclassing!
+ *
+ * \return Whether the lowlevel is at the end of the stream
+ */
+- (BOOL)lowlevelIsAtEndOfStream;
- (BOOL)OF_isWaitingForDelimiter;
@end
Index: src/OFStream.m
==================================================================
--- src/OFStream.m
+++ src/OFStream.m
@@ -69,25 +69,25 @@
blocking = YES;
return self;
}
-- (BOOL)_isAtEndOfStream
+- (BOOL)lowlevelIsAtEndOfStream
{
@throw [OFNotImplementedException exceptionWithClass: [self class]
selector: _cmd];
}
-- (size_t)_readIntoBuffer: (void*)buffer
- length: (size_t)length
+- (size_t)lowlevelReadIntoBuffer: (void*)buffer
+ length: (size_t)length
{
@throw [OFNotImplementedException exceptionWithClass: [self class]
selector: _cmd];
}
-- (void)_writeBuffer: (const void*)buffer
- length: (size_t)length
+- (void)lowlevelWriteBuffer: (const void*)buffer
+ length: (size_t)length
{
@throw [OFNotImplementedException exceptionWithClass: [self class]
selector: _cmd];
}
@@ -99,19 +99,19 @@
- (BOOL)isAtEndOfStream
{
if (cache != NULL)
return NO;
- return [self _isAtEndOfStream];
+ return [self lowlevelIsAtEndOfStream];
}
- (size_t)readIntoBuffer: (void*)buffer
length: (size_t)length
{
if (cache == NULL)
- return [self _readIntoBuffer: buffer
- length: length];
+ return [self lowlevelReadIntoBuffer: buffer
+ length: length];
if (length >= cacheLength) {
size_t ret = cacheLength;
memcpy(buffer, cache, cacheLength);
@@ -560,11 +560,11 @@
/* Read and see if we get a newline or \0 */
buffer = [self allocMemoryWithSize: of_pagesize];
@try {
- if ([self _isAtEndOfStream]) {
+ if ([self lowlevelIsAtEndOfStream]) {
if (cache == NULL) {
waitingForDelimiter = NO;
return nil;
}
@@ -583,12 +583,12 @@
waitingForDelimiter = NO;
return ret;
}
- bufferLength = [self _readIntoBuffer: buffer
- length: of_pagesize];
+ bufferLength = [self lowlevelReadIntoBuffer: buffer
+ length: of_pagesize];
/* Look if there's a newline or \0 */
for (i = 0; i < bufferLength; i++) {
if OF_UNLIKELY (buffer[i] == '\n' ||
buffer[i] == '\0') {
@@ -756,11 +756,11 @@
/* Read and see if we get a delimiter or \0 */
buffer = [self allocMemoryWithSize: of_pagesize];
@try {
- if ([self _isAtEndOfStream]) {
+ if ([self lowlevelIsAtEndOfStream]) {
if (cache == NULL) {
waitingForDelimiter = NO;
return nil;
}
@@ -774,12 +774,12 @@
waitingForDelimiter = NO;
return ret;
}
- bufferLength = [self _readIntoBuffer: buffer
- length: of_pagesize];
+ bufferLength = [self lowlevelReadIntoBuffer: buffer
+ length: of_pagesize];
/* Look if there's a delimiter or \0 */
for (i = 0; i < bufferLength; i++) {
if (buffer[i] != delimiterUTF8String[j++])
j = 0;
@@ -889,12 +889,12 @@
- (void)flushWriteBuffer
{
if (writeBuffer == NULL)
return;
- [self _writeBuffer: writeBuffer
- length: writeBufferLength];
+ [self lowlevelWriteBuffer: writeBuffer
+ length: writeBufferLength];
[self freeMemory: writeBuffer];
writeBuffer = NULL;
writeBufferLength = 0;
}
@@ -901,12 +901,12 @@
- (void)writeBuffer: (const void*)buffer
length: (size_t)length
{
if (!writeBufferEnabled)
- [self _writeBuffer: buffer
- length: length];
+ [self lowlevelWriteBuffer: buffer
+ length: length];
else {
writeBuffer = [self resizeMemory: writeBuffer
size: writeBufferLength + length];
memcpy(writeBuffer + writeBufferLength, buffer, length);
writeBufferLength += length;
Index: src/OFStreamSocket.m
==================================================================
--- src/OFStreamSocket.m
+++ src/OFStreamSocket.m
@@ -63,17 +63,17 @@
+ socket
{
return [[[self alloc] init] autorelease];
}
-- (BOOL)_isAtEndOfStream
+- (BOOL)lowlevelIsAtEndOfStream
{
return atEndOfStream;
}
-- (size_t)_readIntoBuffer: (void*)buffer
- length: (size_t)length
+- (size_t)lowlevelReadIntoBuffer: (void*)buffer
+ length: (size_t)length
{
ssize_t ret;
if (sock == INVALID_SOCKET)
@throw [OFNotConnectedException exceptionWithClass: [self class]
@@ -103,12 +103,12 @@
atEndOfStream = YES;
return ret;
}
-- (void)_writeBuffer: (const void*)buffer
- length: (size_t)length
+- (void)lowlevelWriteBuffer: (const void*)buffer
+ length: (size_t)length
{
if (sock == INVALID_SOCKET)
@throw [OFNotConnectedException exceptionWithClass: [self class]
socket: self];
Index: tests/OFStreamTests.m
==================================================================
--- tests/OFStreamTests.m
+++ tests/OFStreamTests.m
@@ -31,17 +31,17 @@
int state;
}
@end
@implementation StreamTester
-- (BOOL)_isAtEndOfStream
+- (BOOL)lowlevelIsAtEndOfStream
{
return (state > 1 ? YES : NO);
}
-- (size_t)_readIntoBuffer: (void*)buffer
- length: (size_t)size
+- (size_t)lowlevelReadIntoBuffer: (void*)buffer
+ length: (size_t)size
{
switch (state) {
case 0:
if (size < 1)
return 0;