Index: src/OFFile.m ================================================================== --- src/OFFile.m +++ src/OFFile.m @@ -568,10 +568,11 @@ { size_t ret; if (fd == -1 || eos) @throw [OFReadFailedException newWithClass: isa + stream: self requestedSize: size]; if ((ret = read(fd, buf, size)) == 0) eos = YES; return ret; @@ -582,37 +583,41 @@ { size_t ret; if (fd == -1 || eos || (ret = write(fd, buf, size)) < size) @throw [OFWriteFailedException newWithClass: isa + stream: self requestedSize: size]; return ret; } - (void)_seekToOffset: (off_t)offset { if (lseek(fd, offset, SEEK_SET) == -1) - @throw [OFSeekFailedException newWithClass: isa]; + @throw [OFSeekFailedException newWithClass: isa + stream: self]; } - (off_t)_seekForwardWithOffset: (off_t)offset { off_t ret; if ((ret = lseek(fd, offset, SEEK_CUR)) == -1) - @throw [OFSeekFailedException newWithClass: isa]; + @throw [OFSeekFailedException newWithClass: isa + stream: self]; return ret; } - (off_t)_seekToOffsetRelativeToEnd: (off_t)offset { off_t ret; if ((ret = lseek(fd, offset, SEEK_END)) == -1) - @throw [OFSeekFailedException newWithClass: isa]; + @throw [OFSeekFailedException newWithClass: isa + stream: self]; return ret; } - (int)fileDescriptor Index: src/OFStream.m ================================================================== --- src/OFStream.m +++ src/OFStream.m @@ -714,19 +714,21 @@ int flags; isBlocking = enable; if ((flags = fcntl([self fileDescriptor], F_GETFL)) == -1) - @throw [OFSetOptionFailedException newWithClass: isa]; + @throw [OFSetOptionFailedException newWithClass: isa + stream: self]; if (enable) flags &= ~O_NONBLOCK; else flags |= O_NONBLOCK; if (fcntl([self fileDescriptor], F_SETFL, flags) == -1) - @throw [OFSetOptionFailedException newWithClass: isa]; + @throw [OFSetOptionFailedException newWithClass: isa + stream: self]; #else @throw [OFNotImplementedException newWithClass: isa selector: _cmd]; #endif } Index: src/OFStreamSocket.m ================================================================== --- src/OFStreamSocket.m +++ src/OFStreamSocket.m @@ -74,10 +74,11 @@ if (eos) { OFReadFailedException *e; e = [OFReadFailedException newWithClass: isa + stream: self requestedSize: size]; #ifndef _WIN32 e->errNo = ENOTCONN; #else e->errNo = WSAENOTCONN; @@ -86,10 +87,11 @@ @throw e; } if ((ret = recv(sock, buf, size, 0)) < 0) @throw [OFReadFailedException newWithClass: isa + stream: self requestedSize: size]; if (ret == 0) eos = YES; @@ -107,10 +109,11 @@ if (eos) { OFWriteFailedException *e; e = [OFWriteFailedException newWithClass: isa + stream: self requestedSize: size]; #ifndef _WIN32 e->errNo = ENOTCONN; #else e->errNo = WSAENOTCONN; @@ -119,10 +122,11 @@ @throw e; } if ((ret = send(sock, buf, size, 0)) == -1) @throw [OFWriteFailedException newWithClass: isa + stream: self requestedSize: size]; /* This is safe, as we already checked for -1 */ return ret; } @@ -132,11 +136,12 @@ { u_long v = enable; isBlocking = enable; if (ioctlsocket(sock, FIONBIO, &v) == SOCKET_ERROR) - @throw [OFSetOptionFailedException newWithClass: isa]; + @throw [OFSetOptionFailedException newWithClass: isa + stream: stream]; } #endif - (int)fileDescriptor { Index: src/OFTCPSocket.m ================================================================== --- src/OFTCPSocket.m +++ src/OFTCPSocket.m @@ -342,11 +342,12 @@ - (void)setKeepAlivesEnabled: (BOOL)enable { int v = enable; if (setsockopt(sock, SOL_SOCKET, SO_KEEPALIVE, (char*)&v, sizeof(v))) - @throw [OFSetOptionFailedException newWithClass: isa]; + @throw [OFSetOptionFailedException newWithClass: isa + stream: self]; } - (OFString*)remoteAddress { if (sockAddr == NULL || sockAddrLen == 0) Index: src/exceptions/OFAcceptFailedException.m ================================================================== --- src/exceptions/OFAcceptFailedException.m +++ src/exceptions/OFAcceptFailedException.m @@ -17,19 +17,29 @@ #include "config.h" #import "OFAcceptFailedException.h" #import "OFString.h" +#import "OFNotImplementedException.h" + #import "common.h" @implementation OFAcceptFailedException + newWithClass: (Class)class_ socket: (OFTCPSocket*)socket { return [[self alloc] initWithClass: class_ socket: socket]; } + +- initWithClass: (Class)class_ +{ + Class c = isa; + [self release]; + @throw [OFNotImplementedException newWithClass: c + selector: _cmd]; +} - initWithClass: (Class)class_ socket: (OFTCPSocket*)socket_ { self = [super initWithClass: class_]; Index: src/exceptions/OFAlreadyConnectedException.m ================================================================== --- src/exceptions/OFAlreadyConnectedException.m +++ src/exceptions/OFAlreadyConnectedException.m @@ -16,18 +16,28 @@ #include "config.h" #import "OFAlreadyConnectedException.h" #import "OFString.h" + +#import "OFNotImplementedException.h" @implementation OFAlreadyConnectedException + newWithClass: (Class)class_ socket: (OFTCPSocket*)socket { return [[self alloc] initWithClass: class_ socket: socket]; } + +- initWithClass: (Class)class_ +{ + Class c = isa; + [self release]; + @throw [OFNotImplementedException newWithClass: c + selector: _cmd]; +} - initWithClass: (Class)class_ socket: (OFTCPSocket*)socket_ { self = [super initWithClass: class_]; Index: src/exceptions/OFNotConnectedException.m ================================================================== --- src/exceptions/OFNotConnectedException.m +++ src/exceptions/OFNotConnectedException.m @@ -16,18 +16,28 @@ #include "config.h" #import "OFNotConnectedException.h" #import "OFString.h" + +#import "OFNotImplementedException.h" @implementation OFNotConnectedException + newWithClass: (Class)class_ socket: (OFStreamSocket*)socket { return [[self alloc] initWithClass: class_ socket: socket]; } + +- initWithClass: (Class)class_ +{ + Class c = isa; + [self release]; + @throw [OFNotImplementedException newWithClass: c + selector: _cmd]; +} - initWithClass: (Class)class_ socket: (OFStreamSocket*)socket_ { self = [super initWithClass: class_]; Index: src/exceptions/OFReadOrWriteFailedException.h ================================================================== --- src/exceptions/OFReadOrWriteFailedException.h +++ src/exceptions/OFReadOrWriteFailedException.h @@ -14,48 +14,61 @@ * file. */ #import "OFException.h" +@class OFStream; + /** * \brief An exception indicating a read or write to a stream failed. */ @interface OFReadOrWriteFailedException: OFException { - size_t requestedSize; + OFStream *stream; + size_t requestedSize; @public - int errNo; + int errNo; } #ifdef OF_HAVE_PROPERTIES +@property (readonly, nonatomic) OFStream *stream; @property (readonly) size_t requestedSize; @property (readonly) int errNo; #endif /** * \param class_ The class of the object which caused the exception + * \param stream The stream which caused the read or write failed exception * \param size The requested size of the data that couldn't be read / written * \return A new open file failed exception */ + newWithClass: (Class)class_ + stream: (OFStream*)stream requestedSize: (size_t)size; /** * Initializes an already allocated read or write failed exception. * * \param class_ The class of the object which caused the exception + * \param stream The stream which caused the read or write failed exception * \param size The requested size of the data that couldn't be read / written * \return A new open file failed exception */ - initWithClass: (Class)class_ + stream: (OFStream*)stream requestedSize: (size_t)size; /** - * \return The errno from when the exception was created + * \return The stream which caused the read or write failed exception */ -- (int)errNo; +- (OFStream*)stream; /** * \return The requested size of the data that couldn't be read / written */ - (size_t)requestedSize; + +/** + * \return The errno from when the exception was created + */ +- (int)errNo; @end Index: src/exceptions/OFReadOrWriteFailedException.m ================================================================== --- src/exceptions/OFReadOrWriteFailedException.m +++ src/exceptions/OFReadOrWriteFailedException.m @@ -24,13 +24,15 @@ #import "common.h" @implementation OFReadOrWriteFailedException + newWithClass: (Class)class_ + stream: (OFStream*)stream requestedSize: (size_t)size { return [[self alloc] initWithClass: class_ + stream: stream requestedSize: size]; } - initWithClass: (Class)class_ { @@ -39,29 +41,47 @@ @throw [OFNotImplementedException newWithClass: c selector: _cmd]; } - initWithClass: (Class)class_ + stream: (OFStream*)stream_ requestedSize: (size_t)size { self = [super initWithClass: class_]; - requestedSize = size; + @try { + stream = [stream_ retain]; + requestedSize = size; - if ([class_ isSubclassOfClass: [OFStreamSocket class]]) - errNo = GET_SOCK_ERRNO; - else - errNo = GET_ERRNO; + if ([class_ isSubclassOfClass: [OFStreamSocket class]]) + errNo = GET_SOCK_ERRNO; + else + errNo = GET_ERRNO; + } @catch (id e) { + return e; + } return self; } -- (int)errNo +- (void)dealloc +{ + [stream release]; + + [super dealloc]; +} + +- (OFStream*)stream { - return errNo; + return stream; } - (size_t)requestedSize { return requestedSize; } + +- (int)errNo +{ + return errNo; +} @end Index: src/exceptions/OFSeekFailedException.h ================================================================== --- src/exceptions/OFSeekFailedException.h +++ src/exceptions/OFSeekFailedException.h @@ -14,22 +14,47 @@ * file. */ #import "OFException.h" +@class OFSeekableStream; + /** * \brief An exception indicating that seeking in a stream failed. */ @interface OFSeekFailedException: OFException { - int errNo; + OFSeekableStream *stream; + int errNo; } #ifdef OF_HAVE_PROPERTIES +@property (readonly, nonatomic) OFSeekableStream *stream; @property (readonly) int errNo; #endif +/** + * \param stream The stream for which seeking failed + * \return A new seek failed exception + */ ++ newWithClass: (Class)class_ + stream: (OFSeekableStream*)stream; + +/** + * Initializes an already allocated seek failed exception. + * + * \param stream The stream for which seeking failed + * \return An initialized seek failed exception + */ +- initWithClass: (Class)class_ + stream: (OFSeekableStream*)stream; + +/** + * \return The stream for which seeking failed + */ +- (OFSeekableStream*)stream; + /** * \return The errno from when the exception was created */ - (int)errNo; @end Index: src/exceptions/OFSeekFailedException.m ================================================================== --- src/exceptions/OFSeekFailedException.m +++ src/exceptions/OFSeekFailedException.m @@ -17,21 +17,52 @@ #include "config.h" #import "OFSeekFailedException.h" #import "OFString.h" +#import "OFNotImplementedException.h" + #import "common.h" @implementation OFSeekFailedException ++ newWithClass: (Class)class_ + stream: (OFSeekableStream*)stream +{ + return [[self alloc] initWithClass: class_ + stream: stream]; +} + +- initWithClass: (Class)class_ +{ + Class c = isa; + [self release]; + @throw [OFNotImplementedException newWithClass: c + selector: _cmd]; +} + - initWithClass: (Class)class_ + stream: (OFSeekableStream*)stream_ { self = [super initWithClass: class_]; - errNo = GET_ERRNO; + @try { + stream = [stream_ retain]; + errNo = GET_ERRNO; + } @catch (id e) { + [self release]; + @throw e; + } return self; } + +- (void)dealloc +{ + [stream release]; + + [super dealloc]; +} - (OFString*)description { if (description != nil) return description; @@ -39,11 +70,16 @@ description = [[OFString alloc] initWithFormat: @"Seeking failed in class %@! " ERRFMT, inClass, ERRPARAM]; return description; } + +- (OFSeekableStream*)stream +{ + return stream; +} - (int)errNo { return errNo; } @end Index: src/exceptions/OFSetOptionFailedException.h ================================================================== --- src/exceptions/OFSetOptionFailedException.h +++ src/exceptions/OFSetOptionFailedException.h @@ -14,10 +14,40 @@ * file. */ #import "OFException.h" +@class OFStream; + /** - * \brief An exception indicating that setting an option failed. + * \brief An exception indicating that setting an option for a stream failed. */ @interface OFSetOptionFailedException: OFException +{ + OFStream *stream; +} + +#ifdef OF_HAVE_PROPERTIES +@property (readonly, nonatomic) OFStream *stream; +#endif + +/** + * \param stream The stream for which the option could not be set + * \return A new set option failed exception + */ ++ newWithClass: (Class)class_ + stream: (OFStream*)stream; + +/** + * Initializes an already allocated set option failed exception. + * + * \param stream The stream for which the option could not be set + * \return An initialized set option failed exception + */ +- initWithClass: (Class)class_ + stream: (OFStream*)stream; + +/** + * \return The stream for which the option could not be set + */ +- (OFStream*)stream; @end Index: src/exceptions/OFSetOptionFailedException.m ================================================================== --- src/exceptions/OFSetOptionFailedException.m +++ src/exceptions/OFSetOptionFailedException.m @@ -16,12 +16,51 @@ #include "config.h" #import "OFSetOptionFailedException.h" #import "OFString.h" + +#import "OFNotImplementedException.h" @implementation OFSetOptionFailedException ++ newWithClass: (Class)class_ + stream: (OFStream*)stream +{ + return [[self alloc] initWithClass: class_ + stream: stream]; +} + +- initWithClass: (Class)class_ +{ + Class c = isa; + [self release]; + @throw [OFNotImplementedException newWithClass: c + selector: _cmd]; +} + +- initWithClass: (Class)class_ + stream: (OFStream*)stream_ +{ + self = [super initWithClass: class_]; + + @try { + stream = [stream_ retain]; + } @catch (id e) { + [self release]; + @throw e; + } + + return self; +} + +- (void)dealloc +{ + [stream release]; + + [super dealloc]; +} + - (OFString*)description { if (description != nil) return description; @@ -28,6 +67,11 @@ description = [[OFString alloc] initWithFormat: @"Setting an option in class %@ failed!", inClass]; return description; } + +- (OFStream*)stream +{ + return stream; +} @end