@@ -21,37 +21,57 @@ #import "OFTCPSocket.h" #import "common.h" @implementation OFAddressTranslationFailedException -+ (instancetype)exceptionWithClass: (Class)class - socket: (OFTCPSocket*)socket - host: (OFString*)host ++ (instancetype)exceptionWithSocket: (OFTCPSocket*)socket +{ + return [[[self alloc] initWithSocket: socket] autorelease]; +} + ++ (instancetype)exceptionWithHost: (OFString*)host + socket: (OFTCPSocket*)socket +{ + return [[[self alloc] initWithHost: host + socket: socket] autorelease]; +} + +- init { - return [[[self alloc] initWithClass: class - socket: socket - host: host] autorelease]; + @try { + [self doesNotRecognizeSelector: _cmd]; + } @catch (id e) { + [self release]; + @throw e; + } + + abort(); } -- initWithClass: (Class)class +- initWithSocket: (OFTCPSocket*)socket { - self = [super initWithClass: class]; + self = [super init]; - _errNo = GET_AT_ERRNO; + @try { + _socket = [socket retain]; + _errNo = GET_AT_ERRNO; + } @catch (id e) { + [self release]; + @throw e; + } return self; } -- initWithClass: (Class)class - socket: (OFTCPSocket*)socket - host: (OFString*)host +- initWithHost: (OFString*)host + socket: (OFTCPSocket*)socket { - self = [super initWithClass: class]; + self = [super init]; @try { - _socket = [socket retain]; _host = [host copy]; + _socket = [socket retain]; _errNo = GET_AT_ERRNO; } @catch (id e) { [self release]; @throw e; } @@ -59,41 +79,43 @@ return self; } - (void)dealloc { - [_socket release]; [_host release]; + [_socket release]; [super dealloc]; } - (OFString*)description { if (_host != nil) return [OFString stringWithFormat: - @"The host %@ could not be translated to an address in " - @"class %@. This means that either the host was not found, " - @"there was a problem with the name server, there was a " - @"problem with your network connection or you specified an " - @"invalid host. " ERRFMT, _host, _inClass, AT_ERRPARAM]; + @"The host %@ could not be translated to an address for a " + @"socket of type %@. This means that either the host was " + @"not found, there was a problem with the name server, " + @"there was a problem with your network connection or you " + @"specified an invalid host. " ERRFMT, _host, + [_socket class], AT_ERRPARAM]; else return [OFString stringWithFormat: - @"An address translation failed in class %@! " ERRFMT, - _inClass, AT_ERRPARAM]; + @"An address could not be translated translation for a " + @"socket of type %@! " ERRFMT, [_socket class], + AT_ERRPARAM]; +} + +- (OFString*)host +{ + OF_GETTER(_host, false) } - (OFTCPSocket*)socket { OF_GETTER(_socket, false) } -- (OFString*)host -{ - OF_GETTER(_host, false) -} - - (int)errNo { return _errNo; } @end