@@ -1,7 +1,7 @@ /* - * Copyright (c) 2008-2021 Jonathan Schleifer + * Copyright (c) 2008-2022 Jonathan Schleifer * * All rights reserved. * * This file is part of ObjFW. It may be distributed under the terms of the * Q Public License 1.0, which can be found in the file LICENSE.QPL included in @@ -17,17 +17,12 @@ #import "OFConnectionFailedException.h" #import "OFString.h" @implementation OFConnectionFailedException -@synthesize host = _host, port = _port, network = _network, socket = _socket; -@synthesize errNo = _errNo; - -+ (instancetype)exception -{ - OF_UNRECOGNIZED_SELECTOR -} +@synthesize host = _host, port = _port, path = _path, network = _network; +@synthesize socket = _socket, errNo = _errNo; + (instancetype)exceptionWithHost: (OFString *)host port: (uint16_t)port socket: (id)sock errNo: (int)errNo @@ -36,26 +31,35 @@ port: port socket: sock errNo: errNo] autorelease]; } -+ (instancetype)exceptionWithNode: (unsigned char [IPX_NODE_LEN])node - network: (uint32_t)network - port: (uint16_t)port ++ (instancetype)exception +{ + OF_UNRECOGNIZED_SELECTOR +} + ++ (instancetype)exceptionWithPath: (OFString *)path socket: (id)sock errNo: (int)errNo { - return [[[self alloc] initWithNode: node - network: network - port: port + return [[[self alloc] initWithPath: path socket: sock errNo: errNo] autorelease]; } -- (instancetype)init ++ (instancetype)exceptionWithNetwork: (uint32_t)network + node: (unsigned char [IPX_NODE_LEN])node + port: (uint16_t)port + socket: (id)sock + errNo: (int)errNo { - OF_INVALID_INIT_METHOD + return [[[self alloc] initWithNetwork: network + node: node + port: port + socket: sock + errNo: errNo] autorelease]; } - (instancetype)initWithHost: (OFString *)host port: (uint16_t)port socket: (id)sock @@ -74,21 +78,39 @@ } return self; } -- (instancetype)initWithNode: (unsigned char [IPX_NODE_LEN])node - network: (uint32_t)network - port: (uint16_t)port +- (instancetype)initWithPath: (OFString *)path socket: (id)sock errNo: (int)errNo { self = [super init]; @try { - memcpy(_node, node, IPX_NODE_LEN); + _path = [path copy]; + _socket = [sock retain]; + _errNo = errNo; + } @catch (id e) { + [self release]; + @throw e; + } + + return self; +} + +- (instancetype)initWithNetwork: (uint32_t)network + node: (unsigned char [IPX_NODE_LEN])node + port: (uint16_t)port + socket: (id)sock + errNo: (int)errNo +{ + self = [super init]; + + @try { _network = network; + memcpy(_node, node, IPX_NODE_LEN); _port = port; _socket = [sock retain]; _errNo = errNo; } @catch (id e) { [self release]; @@ -95,14 +117,20 @@ @throw e; } return self; } + +- (instancetype)init +{ + OF_INVALID_INIT_METHOD +} - (void)dealloc { [_host release]; + [_path release]; [_socket release]; [super dealloc]; } @@ -111,11 +139,16 @@ return _node; } - (OFString *)description { - if (_host != nil) + if (_path != nil) + return [OFString stringWithFormat: + @"A connection to %@ could not be established in socket of " + @"type %@: %@", + _path, [_socket class], OFStrError(_errNo)]; + else if (_host != nil) return [OFString stringWithFormat: @"A connection to %@ on port %" @PRIu16 @" could not be " @"established in socket of type %@: %@", _host, _port, [_socket class], OFStrError(_errNo)]; else if (memcmp(_node, "\0\0\0\0\0", IPX_NODE_LEN) == 0)