Index: src/OFIPXSocket.h ================================================================== --- src/OFIPXSocket.h +++ src/OFIPXSocket.h @@ -69,12 +69,12 @@ * * @param port The port (sometimes called socket number) to bind to. 0 means to * pick one and return via the returned socket address. * @param packetType The packet type to use on the socket * @return The address on which this socket can be reached - * @throw OFBindSocketFailedException Binding failed + * @throw OFBindIPXSocketFailedException Binding failed * @throw OFAlreadyConnectedException The socket is already bound */ - (OFSocketAddress)bindToPort: (uint16_t)port packetType: (uint8_t)packetType; @end OF_ASSUME_NONNULL_END Index: src/OFIPXSocket.m ================================================================== --- src/OFIPXSocket.m +++ src/OFIPXSocket.m @@ -24,11 +24,11 @@ #import "OFIPXSocket.h" #import "OFSocket.h" #import "OFSocket+Private.h" #import "OFAlreadyConnectedException.h" -#import "OFBindSocketFailedException.h" +#import "OFBindIPXSocketFailedException.h" @implementation OFIPXSocket @dynamic delegate; - (OFSocketAddress)bindToPort: (uint16_t)port packetType: (uint8_t)packetType @@ -51,11 +51,11 @@ _packetType = address.sockaddr.ipx.sipx_type = packetType; #endif if ((_socket = socket(address.sockaddr.ipx.sipx_family, SOCK_DGRAM | SOCK_CLOEXEC, protocol)) == OFInvalidSocketHandle) - @throw [OFBindSocketFailedException + @throw [OFBindIPXSocketFailedException exceptionWithPort: port packetType: packetType socket: self errNo: OFSocketErrNo()]; @@ -71,11 +71,11 @@ int errNo = OFSocketErrNo(); closesocket(_socket); _socket = OFInvalidSocketHandle; - @throw [OFBindSocketFailedException + @throw [OFBindIPXSocketFailedException exceptionWithPort: port packetType: packetType socket: self errNo: errNo]; } @@ -89,11 +89,11 @@ int errNo = OFSocketErrNo(); closesocket(_socket); _socket = OFInvalidSocketHandle; - @throw [OFBindSocketFailedException + @throw [OFBindIPXSocketFailedException exceptionWithPort: port packetType: packetType socket: self errNo: errNo]; } @@ -100,11 +100,11 @@ if (address.sockaddr.ipx.sipx_family != AF_IPX) { closesocket(_socket); _socket = OFInvalidSocketHandle; - @throw [OFBindSocketFailedException + @throw [OFBindIPXSocketFailedException exceptionWithPort: port packetType: packetType socket: self errNo: EAFNOSUPPORT]; } Index: src/OFSPXSocket.h ================================================================== --- src/OFSPXSocket.h +++ src/OFSPXSocket.h @@ -158,12 +158,12 @@ * @brief Bind the socket to the specified network, node and port. * * @param port The port (sometimes called socket number) to bind to. 0 means to * pick one and return via the returned socket address. * @return The address on which this socket can be reached - * @throw OFBindSocketFailedException Binding failed + * @throw OFBindIPXSocketFailedException Binding failed * @throw OFAlreadyConnectedException The socket is already connected or bound */ - (OFSocketAddress)bindToPort: (uint16_t)port; @end OF_ASSUME_NONNULL_END Index: src/OFSPXSocket.m ================================================================== --- src/OFSPXSocket.m +++ src/OFSPXSocket.m @@ -22,11 +22,11 @@ #import "OFRunLoop+Private.h" #import "OFSocket.h" #import "OFSocket+Private.h" #import "OFAlreadyConnectedException.h" -#import "OFBindSocketFailedException.h" +#import "OFBindIPXSocketFailedException.h" #import "OFConnectionFailedException.h" #import "OFNotOpenException.h" #ifndef NSPROTO_SPX # define NSPROTO_SPX 0 @@ -327,11 +327,11 @@ address = OFSocketAddressMakeIPX(0, zeroNode, port); if ((_socket = socket(address.sockaddr.ipx.sipx_family, SOCK_SEQPACKET | SOCK_CLOEXEC, NSPROTO_SPX)) == OFInvalidSocketHandle) - @throw [OFBindSocketFailedException + @throw [OFBindIPXSocketFailedException exceptionWithPort: port packetType: SPXPacketType socket: self errNo: OFSocketErrNo()]; @@ -347,11 +347,11 @@ int errNo = OFSocketErrNo(); closesocket(_socket); _socket = OFInvalidSocketHandle; - @throw [OFBindSocketFailedException + @throw [OFBindIPXSocketFailedException exceptionWithPort: port packetType: SPXPacketType socket: self errNo: errNo]; } @@ -365,11 +365,11 @@ int errNo = OFSocketErrNo(); closesocket(_socket); _socket = OFInvalidSocketHandle; - @throw [OFBindSocketFailedException + @throw [OFBindIPXSocketFailedException exceptionWithPort: port packetType: SPXPacketType socket: self errNo: errNo]; } @@ -376,15 +376,15 @@ if (address.sockaddr.ipx.sipx_family != AF_IPX) { closesocket(_socket); _socket = OFInvalidSocketHandle; - @throw [OFBindSocketFailedException + @throw [OFBindIPXSocketFailedException exceptionWithPort: port packetType: SPXPacketType socket: self errNo: EAFNOSUPPORT]; } return address; } @end Index: src/OFSPXStreamSocket.m ================================================================== --- src/OFSPXStreamSocket.m +++ src/OFSPXStreamSocket.m @@ -22,11 +22,11 @@ #import "OFRunLoop+Private.h" #import "OFSocket.h" #import "OFSocket+Private.h" #import "OFAlreadyConnectedException.h" -#import "OFBindSocketFailedException.h" +#import "OFBindIPXSocketFailedException.h" #import "OFConnectionFailedException.h" #import "OFNotOpenException.h" #ifndef NSPROTO_SPX # define NSPROTO_SPX 0 @@ -328,11 +328,11 @@ address = OFSocketAddressMakeIPX(0, zeroNode, port); if ((_socket = socket(address.sockaddr.ipx.sipx_family, SOCK_STREAM | SOCK_CLOEXEC, NSPROTO_SPX)) == OFInvalidSocketHandle) - @throw [OFBindSocketFailedException + @throw [OFBindIPXSocketFailedException exceptionWithPort: port packetType: SPXPacketType socket: self errNo: OFSocketErrNo()]; @@ -348,11 +348,11 @@ int errNo = OFSocketErrNo(); closesocket(_socket); _socket = OFInvalidSocketHandle; - @throw [OFBindSocketFailedException + @throw [OFBindIPXSocketFailedException exceptionWithPort: port packetType: SPXPacketType socket: self errNo: errNo]; } @@ -366,11 +366,11 @@ int errNo = OFSocketErrNo(); closesocket(_socket); _socket = OFInvalidSocketHandle; - @throw [OFBindSocketFailedException + @throw [OFBindIPXSocketFailedException exceptionWithPort: port packetType: SPXPacketType socket: self errNo: errNo]; } @@ -377,15 +377,15 @@ if (address.sockaddr.ipx.sipx_family != AF_IPX) { closesocket(_socket); _socket = OFInvalidSocketHandle; - @throw [OFBindSocketFailedException + @throw [OFBindIPXSocketFailedException exceptionWithPort: port packetType: SPXPacketType socket: self errNo: EAFNOSUPPORT]; } return address; } @end Index: src/OFTCPSocket.h ================================================================== --- src/OFTCPSocket.h +++ src/OFTCPSocket.h @@ -212,12 +212,12 @@ * @param host The host to bind to. Use `@"0.0.0.0"` for IPv4 or `@"::"` for * IPv6 to bind to all. * @param port The port to bind to. If the port is 0, an unused port will be * chosen, which can be obtained using the return value. * @return The port the socket was bound to - * @throw OFBindSocketFailedException Binding failed + * @throw OFBindIPSocketFailedException Binding failed * @throw OFAlreadyConnectedException The socket is already connected or bound */ - (uint16_t)bindToHost: (OFString *)host port: (uint16_t)port; @end OF_ASSUME_NONNULL_END Index: src/OFTCPSocket.m ================================================================== --- src/OFTCPSocket.m +++ src/OFTCPSocket.m @@ -42,11 +42,11 @@ #import "OFString.h" #import "OFTCPSocketSOCKS5Connector.h" #import "OFThread.h" #import "OFAlreadyConnectedException.h" -#import "OFBindSocketFailedException.h" +#import "OFBindIPSocketFailedException.h" #import "OFGetOptionFailedException.h" #import "OFNotImplementedException.h" #import "OFNotOpenException.h" #import "OFSetOptionFailedException.h" @@ -314,11 +314,11 @@ OFSocketAddressSetPort(&address, port); if ((_socket = socket( ((struct sockaddr *)&address.sockaddr)->sa_family, SOCK_STREAM | SOCK_CLOEXEC, 0)) == OFInvalidSocketHandle) - @throw [OFBindSocketFailedException + @throw [OFBindIPSocketFailedException exceptionWithHost: host port: port socket: self errNo: OFSocketErrNo()]; @@ -340,11 +340,11 @@ int errNo = OFSocketErrNo(); closesocket(_socket); _socket = OFInvalidSocketHandle; - @throw [OFBindSocketFailedException + @throw [OFBindIPSocketFailedException exceptionWithHost: host port: port socket: self errNo: errNo]; } @@ -370,11 +370,11 @@ int errNo = OFSocketErrNo(); closesocket(_socket); _socket = OFInvalidSocketHandle; - @throw [OFBindSocketFailedException + @throw [OFBindIPSocketFailedException exceptionWithHost: host port: port socket: self errNo: errNo]; } @@ -396,14 +396,14 @@ int errNo = OFSocketErrNo(); closesocket(_socket); _socket = OFInvalidSocketHandle; - @throw [OFBindSocketFailedException exceptionWithHost: host - port: port - socket: self - errNo: errNo]; + @throw [OFBindIPSocketFailedException exceptionWithHost: host + port: port + socket: self + errNo: errNo]; } switch (((struct sockaddr *)&address.sockaddr)->sa_family) { case AF_INET: return OFFromBigEndian16(address.sockaddr.in.sin_port); @@ -413,23 +413,23 @@ # endif default: closesocket(_socket); _socket = OFInvalidSocketHandle; - @throw [OFBindSocketFailedException + @throw [OFBindIPSocketFailedException exceptionWithHost: host port: port socket: self errNo: EAFNOSUPPORT]; } #else closesocket(_socket); _socket = OFInvalidSocketHandle; - @throw [OFBindSocketFailedException exceptionWithHost: host - port: port - socket: self - errNo: EADDRNOTAVAIL]; + @throw [OFBindIPSocketFailedException exceptionWithHost: host + port: port + socket: self + errNo: EADDRNOTAVAIL]; #endif } #if !defined(OF_WII) && !defined(OF_NINTENDO_3DS) - (void)setSendsKeepAlives: (bool)sendsKeepAlives Index: src/OFUDPSocket.h ================================================================== --- src/OFUDPSocket.h +++ src/OFUDPSocket.h @@ -70,12 +70,12 @@ * @param host The host to bind to. Use `@"0.0.0.0"` for IPv4 or `@"::"` for * IPv6 to bind to all. * @param port The port to bind to. If the port is 0, an unused port will be * chosen, which can be obtained using the return value. * @return The port the socket was bound to - * @throw OFBindSocketFailedException Binding failed + * @throw OFBindIPSocketFailedException Binding failed * @throw OFAlreadyConnectedException The socket is already bound */ - (uint16_t)bindToHost: (OFString *)host port: (uint16_t)port; @end OF_ASSUME_NONNULL_END Index: src/OFUDPSocket.m ================================================================== --- src/OFUDPSocket.m +++ src/OFUDPSocket.m @@ -33,11 +33,11 @@ #import "OFSocket.h" #import "OFSocket+Private.h" #import "OFThread.h" #import "OFAlreadyConnectedException.h" -#import "OFBindSocketFailedException.h" +#import "OFBindIPSocketFailedException.h" @implementation OFUDPSocket @dynamic delegate; - (uint16_t)of_bindToAddress: (OFSocketAddress *)address @@ -50,11 +50,11 @@ #endif if ((_socket = socket( ((struct sockaddr *)&address->sockaddr)->sa_family, SOCK_DGRAM | SOCK_CLOEXEC | extraType, 0)) == OFInvalidSocketHandle) - @throw [OFBindSocketFailedException + @throw [OFBindIPSocketFailedException exceptionWithHost: OFSocketAddressString(address) port: OFSocketAddressPort(address) socket: self errNo: OFSocketErrNo()]; @@ -75,11 +75,11 @@ int errNo = OFSocketErrNo(); closesocket(_socket); _socket = OFInvalidSocketHandle; - @throw [OFBindSocketFailedException + @throw [OFBindIPSocketFailedException exceptionWithHost: OFSocketAddressString(address) port: OFSocketAddressPort(address) socket: self errNo: errNo]; } @@ -105,11 +105,11 @@ port = OFSocketAddressPort(address); closesocket(_socket); _socket = OFInvalidSocketHandle; - @throw [OFBindSocketFailedException + @throw [OFBindIPSocketFailedException exceptionWithHost: host port: port socket: self errNo: errNo]; } @@ -131,11 +131,11 @@ int errNo = OFSocketErrNo(); closesocket(_socket); _socket = OFInvalidSocketHandle; - @throw [OFBindSocketFailedException + @throw [OFBindIPSocketFailedException exceptionWithHost: OFSocketAddressString(address) port: OFSocketAddressPort(address) socket: self errNo: errNo]; } @@ -149,21 +149,21 @@ # endif default: closesocket(_socket); _socket = OFInvalidSocketHandle; - @throw [OFBindSocketFailedException + @throw [OFBindIPSocketFailedException exceptionWithHost: OFSocketAddressString(address) port: OFSocketAddressPort(address) socket: self errNo: EAFNOSUPPORT]; } #else closesocket(_socket); _socket = OFInvalidSocketHandle; - @throw [OFBindSocketFailedException + @throw [OFBindIPSocketFailedException exceptionWithHost: OFSocketAddressString(address) port: OFSocketAddressPort(address) socket: self errNo: EADDRNOTAVAIL]; #endif Index: src/OFUNIXDatagramSocket.h ================================================================== --- src/OFUNIXDatagramSocket.h +++ src/OFUNIXDatagramSocket.h @@ -63,12 +63,12 @@ /** * @brief Bind the socket to the specified path. * * @param path The path to bind to * @return The address on which this socket can be reached - * @throw OFBindSocketFailedException Binding failed + * @throw OFBindUNIXSocketFailedException Binding failed * @throw OFAlreadyConnectedException The socket is already bound */ - (OFSocketAddress)bindToPath: (OFString *)path; @end OF_ASSUME_NONNULL_END Index: src/OFUNIXDatagramSocket.m ================================================================== --- src/OFUNIXDatagramSocket.m +++ src/OFUNIXDatagramSocket.m @@ -23,11 +23,11 @@ #import "OFSocket.h" #import "OFSocket+Private.h" #import "OFString.h" #import "OFAlreadyConnectedException.h" -#import "OFBindSocketFailedException.h" +#import "OFBindUNIXSocketFailedException.h" @implementation OFUNIXDatagramSocket @dynamic delegate; - (OFSocketAddress)bindToPath: (OFString *)path @@ -42,11 +42,11 @@ address = OFSocketAddressMakeUNIX(path); if ((_socket = socket(address.sockaddr.un.sun_family, SOCK_DGRAM | SOCK_CLOEXEC, 0)) == OFInvalidSocketHandle) - @throw [OFBindSocketFailedException + @throw [OFBindUNIXSocketFailedException exceptionWithPath: path socket: self errNo: OFSocketErrNo()]; _canBlock = true; @@ -61,13 +61,14 @@ int errNo = OFSocketErrNo(); closesocket(_socket); _socket = OFInvalidSocketHandle; - @throw [OFBindSocketFailedException exceptionWithPath: path - socket: self - errNo: errNo]; + @throw [OFBindUNIXSocketFailedException + exceptionWithPath: path + socket: self + errNo: errNo]; } return address; } @end Index: src/OFUNIXStreamSocket.h ================================================================== --- src/OFUNIXStreamSocket.h +++ src/OFUNIXStreamSocket.h @@ -61,12 +61,12 @@ /** * @brief Binds the socket to the specified host and port. * * @param path The path to bind to - * @throw OFBindSocketFailedException Binding failed + * @throw OFBindUNIXSocketFailedException Binding failed * @throw OFAlreadyConnectedException The socket is already connected or bound */ - (void)bindToPath: (OFString *)path; @end OF_ASSUME_NONNULL_END Index: src/OFUNIXStreamSocket.m ================================================================== --- src/OFUNIXStreamSocket.m +++ src/OFUNIXStreamSocket.m @@ -23,11 +23,11 @@ #import "OFSocket.h" #import "OFSocket+Private.h" #import "OFString.h" #import "OFAlreadyConnectedException.h" -#import "OFBindSocketFailedException.h" +#import "OFBindUNIXSocketFailedException.h" #import "OFConnectionFailedException.h" @implementation OFUNIXStreamSocket @dynamic delegate; @@ -82,11 +82,11 @@ address = OFSocketAddressMakeUNIX(path); if ((_socket = socket(address.sockaddr.un.sun_family, SOCK_STREAM | SOCK_CLOEXEC, 0)) == OFInvalidSocketHandle) - @throw [OFBindSocketFailedException + @throw [OFBindUNIXSocketFailedException exceptionWithPath: path socket: self errNo: OFSocketErrNo()]; _canBlock = true; @@ -101,11 +101,12 @@ int errNo = OFSocketErrNo(); closesocket(_socket); _socket = OFInvalidSocketHandle; - @throw [OFBindSocketFailedException exceptionWithPath: path - socket: self - errNo: errNo]; + @throw [OFBindUNIXSocketFailedException + exceptionWithPath: path + socket: self + errNo: errNo]; } } @end Index: src/ObjFW.h ================================================================== --- src/ObjFW.h +++ src/ObjFW.h @@ -147,10 +147,17 @@ #import "OFException.h" #ifdef OF_HAVE_SOCKETS # import "OFAcceptFailedException.h" # import "OFAlreadyConnectedException.h" # import "OFBindSocketFailedException.h" +# import "OFBindIPSocketFailedException.h" +# ifdef OF_HAVE_UNIX_SOCKETS +# import "OFBindUNIXSocketFailedException.h" +# endif +# ifdef OF_HAVE_IPX +# import "OFBindIPXSocketFailedException.h" +# endif #endif #import "OFChangeCurrentDirectoryFailedException.h" #import "OFChecksumMismatchException.h" #ifdef OF_HAVE_THREADS # import "OFConditionBroadcastFailedException.h" Index: src/exceptions/Makefile ================================================================== --- src/exceptions/Makefile +++ src/exceptions/Makefile @@ -54,17 +54,22 @@ OFGetCurrentDirectoryFailedException.m SRCS_PLUGINS = OFLoadPluginFailedException.m SRCS_SOCKETS = OFAcceptFailedException.m \ OFAlreadyConnectedException.m \ OFBindSocketFailedException.m \ + OFBindIPSocketFailedException.m \ OFConnectionFailedException.m \ OFDNSQueryFailedException.m \ OFHTTPRequestFailedException.m \ OFListenFailedException.m \ OFObserveKernelEventsFailedException.m \ OFResolveHostFailedException.m \ - OFTLSHandshakeFailedException.m + OFTLSHandshakeFailedException.m \ + ${USE_SRCS_IPX} \ + ${USE_SRCS_UNIX_SOCKETS} +SRCS_IPX = OFBindIPXSocketFailedException.m +SRCS_UNIX_SOCKETS = OFBindUNIXSocketFailedException.m SRCS_THREADS = OFConditionBroadcastFailedException.m \ OFConditionSignalFailedException.m \ OFConditionStillWaitingException.m \ OFConditionWaitFailedException.m \ OFThreadJoinFailedException.m \ ADDED src/exceptions/OFBindIPSocketFailedException.h Index: src/exceptions/OFBindIPSocketFailedException.h ================================================================== --- src/exceptions/OFBindIPSocketFailedException.h +++ src/exceptions/OFBindIPSocketFailedException.h @@ -0,0 +1,81 @@ +/* + * 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 + * the packaging of this file. + * + * Alternatively, it may be distributed under the terms of the GNU General + * Public License, either version 2 or 3, which can be found in the file + * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this + * file. + */ + +#import "OFBindSocketFailedException.h" + +#ifndef OF_HAVE_SOCKETS +# error No sockets available! +#endif + +OF_ASSUME_NONNULL_BEGIN + +/** + * @class OFBindIPSocketFailedException \ + * OFBindIPSocketFailedException.h ObjFW/OFBindIPSocketFailedException.h + * + * @brief An exception indicating that binding an IP socket failed. + */ +OF_SUBCLASSING_RESTRICTED +@interface OFBindIPSocketFailedException: OFBindSocketFailedException +{ + OFString *_Nullable _host; + uint16_t _port; +} + +/** + * @brief The host on which binding failed. + */ +@property OF_NULLABLE_PROPERTY (readonly, nonatomic) OFString *host; + +/** + * @brief The port on which binding failed. + */ +@property (readonly, nonatomic) uint16_t port; + +/** + * @brief Creates a new, autoreleased bind IP socket failed exception. + * + * @param host The host on which binding failed + * @param port The port on which binding failed + * @param socket The socket which could not be bound + * @param errNo The errno of the error that occurred + * @return A new, autoreleased bind IP socket failed exception + */ ++ (instancetype)exceptionWithHost: (OFString *)host + port: (uint16_t)port + socket: (id)socket + errNo: (int)errNo; + ++ (instancetype)exceptionWithSocket: (id)socket + errNo: (int)errNo OF_UNAVAILABLE; + +/** + * @brief Initializes an already allocated bind IP socket failed exception. + * + * @param host The host on which binding failed + * @param port The port on which binding failed + * @param socket The socket which could not be bound + * @param errNo The errno of the error that occurred + * @return An initialized bind IP socket failed exception + */ +- (instancetype)initWithHost: (OFString *)host + port: (uint16_t)port + socket: (id)socket + errNo: (int)errNo OF_DESIGNATED_INITIALIZER; + +- (instancetype)initWithSocket: (id)socket errNo: (int)errNo OF_UNAVAILABLE; +@end + +OF_ASSUME_NONNULL_END ADDED src/exceptions/OFBindIPSocketFailedException.m Index: src/exceptions/OFBindIPSocketFailedException.m ================================================================== --- src/exceptions/OFBindIPSocketFailedException.m +++ src/exceptions/OFBindIPSocketFailedException.m @@ -0,0 +1,77 @@ +/* + * 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 + * the packaging of this file. + * + * Alternatively, it may be distributed under the terms of the GNU General + * Public License, either version 2 or 3, which can be found in the file + * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this + * file. + */ + +#include "config.h" + +#import "OFBindIPSocketFailedException.h" +#import "OFString.h" + +@implementation OFBindIPSocketFailedException +@synthesize host = _host, port = _port; + ++ (instancetype)exceptionWithSocket: (id)sock errNo: (int)errNo +{ + OF_UNRECOGNIZED_SELECTOR +} + ++ (instancetype)exceptionWithHost: (OFString *)host + port: (uint16_t)port + socket: (id)sock + errNo: (int)errNo +{ + return [[[self alloc] initWithHost: host + port: port + socket: sock + errNo: errNo] autorelease]; +} + +- (instancetype)initWithSocket: (id)sock errNo: (int)errNo +{ + OF_INVALID_INIT_METHOD +} + +- (instancetype)initWithHost: (OFString *)host + port: (uint16_t)port + socket: (id)sock + errNo: (int)errNo +{ + self = [super initWithSocket: sock errNo: errNo]; + + @try { + _host = [host copy]; + _port = port; + } @catch (id e) { + [self release]; + @throw e; + } + + return self; +} + +- (void)dealloc +{ + [_host release]; + + [super dealloc]; +} + +- (OFString *)description +{ + return [OFString stringWithFormat: + @"Binding to port %" @PRIu16 @" on host %@ failed in socket of " + @"type %@: %@", + _port, _host, [_socket class], OFStrError(_errNo)]; +} +@end ADDED src/exceptions/OFBindIPXSocketFailedException.h Index: src/exceptions/OFBindIPXSocketFailedException.h ================================================================== --- src/exceptions/OFBindIPXSocketFailedException.h +++ src/exceptions/OFBindIPXSocketFailedException.h @@ -0,0 +1,78 @@ +/* + * 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 + * the packaging of this file. + * + * Alternatively, it may be distributed under the terms of the GNU General + * Public License, either version 2 or 3, which can be found in the file + * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this + * file. + */ + +#import "OFBindSocketFailedException.h" + +OF_ASSUME_NONNULL_BEGIN + +/** + * @class OFBindIPXSocketFailedException \ + * OFBindIPXSocketFailedException.h \ + * ObjFW/OFBindIPXSocketFailedException.h + * + * @brief An exception indicating that binding an IPX socket failed. + */ +OF_SUBCLASSING_RESTRICTED +@interface OFBindIPXSocketFailedException: OFBindSocketFailedException +{ + uint16_t _port; + uint8_t _packetType; +} + +/** + * @brief The IPX port on which binding failed. + */ +@property (readonly, nonatomic) uint16_t port; + +/** + * @brief The IPX packet type for which binding failed. + */ +@property (readonly, nonatomic) uint8_t packetType; + +/** + * @brief Creates a new, autoreleased bind IPX socket failed exception. + * + * @param port The IPX port to which binding failed + * @param packetType The IPX packet type for which binding failed + * @param socket The socket which could not be bound + * @param errNo The errno of the error that occurred + * @return A new, autoreleased bind IPX socket failed exception + */ ++ (instancetype)exceptionWithPort: (uint16_t)port + packetType: (uint8_t)packetType + socket: (id)socket + errNo: (int)errNo; + ++ (instancetype)exceptionWithSocket: (id)socket + errNo: (int)errNo OF_UNAVAILABLE; + +/** + * @brief Initializes an already allocated bind IPX socket failed exception. + * + * @param port The IPX port to which binding failed + * @param packetType The IPX packet type for which binding failed + * @param socket The socket which could not be bound + * @param errNo The errno of the error that occurred + * @return An initialized bind IPX socket failed exception + */ +- (instancetype)initWithPort: (uint16_t)port + packetType: (uint8_t)packetType + socket: (id)socket + errNo: (int)errNo OF_DESIGNATED_INITIALIZER; + +- (instancetype)initWithSocket: (id)socket errNo: (int)errNo OF_UNAVAILABLE; +@end + +OF_ASSUME_NONNULL_END ADDED src/exceptions/OFBindIPXSocketFailedException.m Index: src/exceptions/OFBindIPXSocketFailedException.m ================================================================== --- src/exceptions/OFBindIPXSocketFailedException.m +++ src/exceptions/OFBindIPXSocketFailedException.m @@ -0,0 +1,70 @@ +/* + * 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 + * the packaging of this file. + * + * Alternatively, it may be distributed under the terms of the GNU General + * Public License, either version 2 or 3, which can be found in the file + * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this + * file. + */ + +#include "config.h" + +#import "OFBindIPXSocketFailedException.h" +#import "OFString.h" + +@implementation OFBindIPXSocketFailedException +@synthesize port = _port, packetType = _packetType; + ++ (instancetype)exceptionWithSocket: (id)sock errNo: (int)errNo +{ + OF_UNRECOGNIZED_SELECTOR +} + ++ (instancetype)exceptionWithPort: (uint16_t)port + packetType: (uint8_t)packetType + socket: (id)sock + errNo: (int)errNo +{ + return [[[self alloc] initWithPort: port + packetType: packetType + socket: sock + errNo: errNo] autorelease]; +} + +- (instancetype)initWithSocket: (id)sock errNo: (int)errNo +{ + OF_INVALID_INIT_METHOD +} + +- (instancetype)initWithPort: (uint16_t)port + packetType: (uint8_t)packetType + socket: (id)sock + errNo: (int)errNo +{ + self = [super initWithSocket: sock errNo: errNo]; + + @try { + _port = port; + _packetType = packetType; + } @catch (id e) { + [self release]; + @throw e; + } + + return self; +} + +- (OFString *)description +{ + return [OFString stringWithFormat: + @"Binding to port %" @PRIx16 @" for packet type %" @PRIx8 + @" failed in socket of type %@: %@", + _port, _packetType, [_socket class], OFStrError(_errNo)]; +} +@end Index: src/exceptions/OFBindSocketFailedException.h ================================================================== --- src/exceptions/OFBindSocketFailedException.h +++ src/exceptions/OFBindSocketFailedException.h @@ -29,42 +29,15 @@ * * @brief An exception indicating that binding a socket failed. */ @interface OFBindSocketFailedException: OFException { - /* IP */ - OFString *_Nullable _host; - uint16_t _port; - /* IPX */ - uint8_t _packetType; - /* UNIX socket */ - OFString *_Nullable _path; id _socket; int _errNo; OF_RESERVE_IVARS(OFBindSocketFailedException, 4) } -/** - * @brief The host on which binding failed. - */ -@property OF_NULLABLE_PROPERTY (readonly, nonatomic) OFString *host; - -/** - * @brief The port on which binding failed. - */ -@property (readonly, nonatomic) uint16_t port; - -/** - * @brief The IPX packet type for which binding failed. - */ -@property (readonly, nonatomic) uint8_t packetType; - -/** - * @brief The path on which binding failed. - */ -@property OF_NULLABLE_PROPERTY (readonly, nonatomic) OFString *path; - /** * @brief The socket which could not be bound. */ @property (readonly, nonatomic) id socket; @@ -72,89 +45,29 @@ * @brief The errno of the error that occurred. */ @property (readonly, nonatomic) int errNo; /** - * @brief Creates a new, autoreleased bind failed exception. + * @brief Creates a new, autoreleased bind socket failed exception. * - * @param host The host on which binding failed - * @param port The port on which binding failed * @param socket The socket which could not be bound * @param errNo The errno of the error that occurred - * @return A new, autoreleased bind failed exception + * @return A new, autoreleased bind socket failed exception */ -+ (instancetype)exceptionWithHost: (OFString *)host - port: (uint16_t)port - socket: (id)socket - errNo: (int)errNo; ++ (instancetype)exceptionWithSocket: (id)socket errNo: (int)errNo; + (instancetype)exception OF_UNAVAILABLE; /** - * @brief Creates a new, autoreleased bind failed exception. - * - * @param port The IPX port to which binding failed - * @param packetType The IPX packet type for which binding failed - * @param socket The socket which could not be bound - * @param errNo The errno of the error that occurred - * @return A new, autoreleased bind failed exception - */ -+ (instancetype)exceptionWithPort: (uint16_t)port - packetType: (uint8_t)packetType - socket: (id)socket - errNo: (int)errNo; - -/** - * @brief Creates a new, autoreleased bind failed exception. - * - * @param path The path on which binding failed - * @param socket The socket which could not be bound - * @param errNo The errno of the error that occurred - * @return A new, autoreleased bind failed exception - */ -+ (instancetype)exceptionWithPath: (OFString *)path - socket: (id)socket - errNo: (int)errNo; - -/** - * @brief Initializes an already allocated bind failed exception. - * - * @param host The host on which binding failed - * @param port The port on which binding failed - * @param socket The socket which could not be bound - * @param errNo The errno of the error that occurred - * @return An initialized bind failed exception - */ -- (instancetype)initWithHost: (OFString *)host - port: (uint16_t)port - socket: (id)socket - errNo: (int)errNo; - -/** - * @brief Initializes an already allocated bind failed exception. - * - * @param port The IPX port to which binding failed - * @param packetType The IPX packet type for which binding failed - * @param socket The socket which could not be bound - * @param errNo The errno of the error that occurred - * @return An initialized bind failed exception - */ -- (instancetype)initWithPort: (uint16_t)port - packetType: (uint8_t)packetType - socket: (id)socket - errNo: (int)errNo; -/** - * @brief Initializes an already allocated bind failed exception. - * - * @param path The path on which binding failed - * @param socket The socket which could not be bound - * @param errNo The errno of the error that occurred - * @return An initialized bind failed exception - */ -- (instancetype)initWithPath: (OFString *)path - socket: (id)socket - errNo: (int)errNo; + * @brief Initializes an already allocated bind socket failed exception. + * + * @param socket The socket which could not be bound + * @param errNo The errno of the error that occurred + * @return An initialized bind socket failed exception + */ +- (instancetype)initWithSocket: (id)socket + errNo: (int)errNo OF_DESIGNATED_INITIALIZER; - (instancetype)init OF_UNAVAILABLE; @end OF_ASSUME_NONNULL_END Index: src/exceptions/OFBindSocketFailedException.m ================================================================== --- src/exceptions/OFBindSocketFailedException.m +++ src/exceptions/OFBindSocketFailedException.m @@ -17,102 +17,32 @@ #import "OFBindSocketFailedException.h" #import "OFString.h" @implementation OFBindSocketFailedException -@synthesize host = _host, port = _port, packetType = _packetType, path = _path; @synthesize socket = _socket, errNo = _errNo; + (instancetype)exception { OF_UNRECOGNIZED_SELECTOR } -+ (instancetype)exceptionWithHost: (OFString *)host - port: (uint16_t)port - socket: (id)sock - errNo: (int)errNo -{ - return [[[self alloc] initWithHost: host - port: port - socket: sock - errNo: errNo] autorelease]; -} - -+ (instancetype)exceptionWithPort: (uint16_t)port - packetType: (uint8_t)packetType - socket: (id)sock - errNo: (int)errNo -{ - return [[[self alloc] initWithPort: port - packetType: packetType - socket: sock - errNo: errNo] autorelease]; -} - -+ (instancetype)exceptionWithPath: (OFString *)path - socket: (id)sock - errNo: (int)errNo -{ - return [[[self alloc] initWithPath: path - socket: sock - errNo: errNo] autorelease]; ++ (instancetype)exceptionWithSocket: (id)sock errNo: (int)errNo +{ + return [[[self alloc] initWithSocket: sock errNo: errNo] autorelease]; } - (instancetype)init { OF_INVALID_INIT_METHOD } -- (instancetype)initWithHost: (OFString *)host - port: (uint16_t)port - socket: (id)sock - errNo: (int)errNo -{ - self = [super init]; - - @try { - _host = [host copy]; - _port = port; - _socket = [sock retain]; - _errNo = errNo; - } @catch (id e) { - [self release]; - @throw e; - } - - return self; -} - -- (instancetype)initWithPort: (uint16_t)port - packetType: (uint8_t)packetType - socket: (id)sock - errNo: (int)errNo -{ - self = [super init]; - - @try { - _port = port; - _packetType = packetType; - _socket = [sock retain]; - _errNo = errNo; - } @catch (id e) { - [self release]; - @throw e; - } - - return self; -} - -- (instancetype)initWithPath: (OFString *)path - socket: (id)sock - errNo: (int)errNo -{ - self = [super init]; - - @try { - _path = [path copy]; +- (instancetype)initWithSocket: (id)sock errNo: (int)errNo +{ + self = [super init]; + + @try { _socket = [sock retain]; _errNo = errNo; } @catch (id e) { [self release]; @throw e; @@ -121,30 +51,17 @@ return self; } - (void)dealloc { - [_host release]; - [_path release]; [_socket release]; [super dealloc]; } - (OFString *)description { - if (_path != nil) - return [OFString stringWithFormat: - @"Binding to path %@ failed in socket of type %@: %@", - _path, [_socket class], OFStrError(_errNo)]; - else if (_host != nil) - return [OFString stringWithFormat: - @"Binding to port %" @PRIu16 @" on host %@ failed in " - @"socket of type %@: %@", - _port, _host, [_socket class], OFStrError(_errNo)]; - else - return [OFString stringWithFormat: - @"Binding to port %" @PRIx16 @" for packet type %" @PRIx8 - @" failed in socket of type %@: %@", - _port, _packetType, [_socket class], OFStrError(_errNo)]; + return [OFString stringWithFormat: + @"Binding a socket of type %@ failed: %@", + [_socket class], OFStrError(_errNo)]; } @end ADDED src/exceptions/OFBindUNIXSocketFailedException.h Index: src/exceptions/OFBindUNIXSocketFailedException.h ================================================================== --- src/exceptions/OFBindUNIXSocketFailedException.h +++ src/exceptions/OFBindUNIXSocketFailedException.h @@ -0,0 +1,68 @@ +/* + * 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 + * the packaging of this file. + * + * Alternatively, it may be distributed under the terms of the GNU General + * Public License, either version 2 or 3, which can be found in the file + * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this + * file. + */ + +#import "OFBindSocketFailedException.h" + +OF_ASSUME_NONNULL_BEGIN + +/** + * @class OFBindUNIXSocketFailedException \ + * OFBindUNIXSocketFailedException.h \ + * ObjFW/OFBindUNIXSocketFailedException.h + * + * @brief An exception indicating that binding a UNIX socket failed. + */ +OF_SUBCLASSING_RESTRICTED +@interface OFBindUNIXSocketFailedException: OFBindSocketFailedException +{ + OFString *_Nullable _path; +} + +/** + * @brief The path on which binding failed. + */ +@property OF_NULLABLE_PROPERTY (readonly, nonatomic) OFString *path; + +/** + * @brief Creates a new, autoreleased bind UNIX socket failed exception. + * + * @param path The path on which binding failed + * @param socket The socket which could not be bound + * @param errNo The errno of the error that occurred + * @return A new, autoreleased bind UNIX socket failed exception + */ ++ (instancetype)exceptionWithPath: (OFString *)path + socket: (id)socket + errNo: (int)errNo; + ++ (instancetype)exceptionWithSocket: (id)socket + errNo: (int)errNo OF_UNAVAILABLE; + +/** + * @brief Initializes an already allocated bind UNIX socket failed exception. + * + * @param path The path on which binding failed + * @param socket The socket which could not be bound + * @param errNo The errno of the error that occurred + * @return An initialized bind UNIX socket failed exception + */ +- (instancetype)initWithPath: (OFString *)path + socket: (id)socket + errNo: (int)errNo OF_DESIGNATED_INITIALIZER; + +- (instancetype)initWithSocket: (id)socket errNo: (int)errNo OF_UNAVAILABLE; +@end + +OF_ASSUME_NONNULL_END ADDED src/exceptions/OFBindUNIXSocketFailedException.m Index: src/exceptions/OFBindUNIXSocketFailedException.m ================================================================== --- src/exceptions/OFBindUNIXSocketFailedException.m +++ src/exceptions/OFBindUNIXSocketFailedException.m @@ -0,0 +1,72 @@ +/* + * 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 + * the packaging of this file. + * + * Alternatively, it may be distributed under the terms of the GNU General + * Public License, either version 2 or 3, which can be found in the file + * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this + * file. + */ + +#include "config.h" + +#import "OFBindUNIXSocketFailedException.h" +#import "OFString.h" + +@implementation OFBindUNIXSocketFailedException +@synthesize path = _path; + ++ (instancetype)exceptionWithSocket: (id)sock errNo: (int)errNo +{ + OF_UNRECOGNIZED_SELECTOR +} + ++ (instancetype)exceptionWithPath: (OFString *)path + socket: (id)sock + errNo: (int)errNo +{ + return [[[self alloc] initWithPath: path + socket: sock + errNo: errNo] autorelease]; +} + +- (instancetype)initWithSocket: (id)sock errNo: (int)errNo +{ + OF_INVALID_INIT_METHOD +} + +- (instancetype)initWithPath: (OFString *)path + socket: (id)sock + errNo: (int)errNo +{ + self = [super initWithSocket: sock errNo: errNo]; + + @try { + _path = [path copy]; + } @catch (id e) { + [self release]; + @throw e; + } + + return self; +} + +- (void)dealloc +{ + [_path release]; + + [super dealloc]; +} + +- (OFString *)description +{ + return [OFString stringWithFormat: + @"Binding to path %@ failed in socket of type %@: %@", + _path, [_socket class], OFStrError(_errNo)]; +} +@end