Index: src/OFSequencedPacketSocket.h ================================================================== --- src/OFSequencedPacketSocket.h +++ src/OFSequencedPacketSocket.h @@ -303,19 +303,19 @@ /** * @brief Listen on the socket. * * @param backlog Maximum length for the queue of pending connections. - * @throw OFListenFailedException Listening failed + * @throw OFListenOnSocketFailedException Listening failed * @throw OFNotOpenException The socket is not open */ - (void)listenWithBacklog: (int)backlog; /** * @brief Listen on the socket. * - * @throw OFListenFailedException Listening failed + * @throw OFListenOnSocketFailedException Listening failed * @throw OFNotOpenException The socket is not open */ - (void)listen; /** Index: src/OFSequencedPacketSocket.m ================================================================== --- src/OFSequencedPacketSocket.m +++ src/OFSequencedPacketSocket.m @@ -36,11 +36,11 @@ #import "OFSocket+Private.h" #import "OFAcceptSocketFailedException.h" #import "OFInitializationFailedException.h" #import "OFInvalidArgumentException.h" -#import "OFListenFailedException.h" +#import "OFListenOnSocketFailedException.h" #import "OFNotOpenException.h" #import "OFOutOfRangeException.h" #import "OFReadFailedException.h" #import "OFSetOptionFailedException.h" #import "OFWriteFailedException.h" @@ -306,11 +306,11 @@ { if (_socket == OFInvalidSocketHandle) @throw [OFNotOpenException exceptionWithObject: self]; if (listen(_socket, backlog) == -1) - @throw [OFListenFailedException + @throw [OFListenOnSocketFailedException exceptionWithSocket: self backlog: backlog errNo: OFSocketErrNo()]; _listening = true; Index: src/OFStreamSocket.h ================================================================== --- src/OFStreamSocket.h +++ src/OFStreamSocket.h @@ -104,19 +104,19 @@ /** * @brief Listen on the socket. * * @param backlog Maximum length for the queue of pending connections. - * @throw OFListenFailedException Listening failed + * @throw OFListenOnSocketFailedException Listening failed * @throw OFNotOpenException The socket is not open */ - (void)listenWithBacklog: (int)backlog; /** * @brief Listen on the socket. * - * @throw OFListenFailedException Listening failed + * @throw OFListenOnSocketFailedException Listening failed * @throw OFNotOpenException The socket is not open */ - (void)listen; /** Index: src/OFStreamSocket.m ================================================================== --- src/OFStreamSocket.m +++ src/OFStreamSocket.m @@ -32,11 +32,11 @@ #import "OFSocket+Private.h" #import "OFAcceptSocketFailedException.h" #import "OFInitializationFailedException.h" #import "OFInvalidArgumentException.h" -#import "OFListenFailedException.h" +#import "OFListenOnSocketFailedException.h" #import "OFNotImplementedException.h" #import "OFNotOpenException.h" #import "OFOutOfRangeException.h" #import "OFReadFailedException.h" #import "OFSetOptionFailedException.h" @@ -231,11 +231,11 @@ { if (_socket == OFInvalidSocketHandle) @throw [OFNotOpenException exceptionWithObject: self]; if (listen(_socket, backlog) == -1) - @throw [OFListenFailedException + @throw [OFListenOnSocketFailedException exceptionWithSocket: self backlog: backlog errNo: OFSocketErrNo()]; _listening = true; Index: src/ObjFW.h ================================================================== --- src/ObjFW.h +++ src/ObjFW.h @@ -208,11 +208,11 @@ #import "OFInvalidFormatException.h" #import "OFInvalidJSONException.h" #import "OFInvalidServerResponseException.h" #import "OFLinkItemFailedException.h" #ifdef OF_HAVE_SOCKETS -# import "OFListenFailedException.h" +# import "OFListenOnSocketFailedException.h" #endif #ifdef OF_HAVE_PLUGINS # import "OFLoadPluginFailedException.h" #endif #import "OFLockFailedException.h" Index: src/exceptions/Makefile ================================================================== --- src/exceptions/Makefile +++ src/exceptions/Makefile @@ -59,11 +59,11 @@ OFBindSocketFailedException.m \ OFConnectIPSocketFailedException.m \ OFConnectSocketFailedException.m \ OFDNSQueryFailedException.m \ OFHTTPRequestFailedException.m \ - OFListenFailedException.m \ + OFListenOnSocketFailedException.m \ OFObserveKernelEventsFailedException.m \ OFResolveHostFailedException.m \ OFTLSHandshakeFailedException.m \ ${USE_SRCS_IPX} \ ${USE_SRCS_UNIX_SOCKETS} DELETED src/exceptions/OFListenFailedException.h Index: src/exceptions/OFListenFailedException.h ================================================================== --- src/exceptions/OFListenFailedException.h +++ src/exceptions/OFListenFailedException.h @@ -1,81 +0,0 @@ -/* - * 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 "OFException.h" - -#ifndef OF_HAVE_SOCKETS -# error No sockets available! -#endif - -OF_ASSUME_NONNULL_BEGIN - -/** - * @class OFListenFailedException \ - * OFListenFailedException.h ObjFW/OFListenFailedException.h - * - * @brief An exception indicating that listening on the socket failed. - */ -@interface OFListenFailedException: OFException -{ - id _socket; - int _backlog, _errNo; - OF_RESERVE_IVARS(OFListenFailedException, 4) -} - -/** - * @brief The socket which failed to listen. - */ -@property (readonly, nonatomic) id socket; - -/** - * @brief The requested back log. - */ -@property (readonly, nonatomic) int backlog; - -/** - * @brief The errno of the error that occurred. - */ -@property (readonly, nonatomic) int errNo; - -/** - * @brief Creates a new, autoreleased listen failed exception. - * - * @param socket The socket which failed to listen - * @param backlog The requested size of the back log - * @param errNo The errno of the error that occurred - * @return A new, autoreleased listen failed exception - */ -+ (instancetype)exceptionWithSocket: (id)socket - backlog: (int)backlog - errNo: (int)errNo; - -+ (instancetype)exception OF_UNAVAILABLE; - -/** - * @brief Initializes an already allocated listen failed exception. - * - * @param socket The socket which failed to listen - * @param backlog The requested size of the back log - * @param errNo The errno of the error that occurred - * @return An initialized listen failed exception - */ -- (instancetype)initWithSocket: (id)socket - backlog: (int)backlog - errNo: (int)errNo OF_DESIGNATED_INITIALIZER; - -- (instancetype)init OF_UNAVAILABLE; -@end - -OF_ASSUME_NONNULL_END DELETED src/exceptions/OFListenFailedException.m Index: src/exceptions/OFListenFailedException.m ================================================================== --- src/exceptions/OFListenFailedException.m +++ src/exceptions/OFListenFailedException.m @@ -1,67 +0,0 @@ -/* - * 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 "OFListenFailedException.h" -#import "OFString.h" - -@implementation OFListenFailedException -@synthesize socket = _socket, backlog = _backlog, errNo = _errNo; - -+ (instancetype)exception -{ - OF_UNRECOGNIZED_SELECTOR -} - -+ (instancetype)exceptionWithSocket: (id)sock - backlog: (int)backlog - errNo: (int)errNo -{ - return [[[self alloc] initWithSocket: sock - backlog: backlog - errNo: errNo] autorelease]; -} - -- (instancetype)init -{ - OF_INVALID_INIT_METHOD -} - -- (instancetype)initWithSocket: (id)sock backlog: (int)backlog errNo: (int)errNo -{ - self = [super init]; - - _socket = [sock retain]; - _backlog = backlog; - _errNo = errNo; - - return self; -} - -- (void)dealloc -{ - [_socket release]; - - [super dealloc]; -} - -- (OFString *)description -{ - return [OFString stringWithFormat: - @"Failed to listen in socket of type %@ with a back log of %d: %@", - [_socket class], _backlog, OFStrError(_errNo)]; -} -@end ADDED src/exceptions/OFListenOnSocketFailedException.h Index: src/exceptions/OFListenOnSocketFailedException.h ================================================================== --- src/exceptions/OFListenOnSocketFailedException.h +++ src/exceptions/OFListenOnSocketFailedException.h @@ -0,0 +1,82 @@ +/* + * 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 "OFException.h" + +#ifndef OF_HAVE_SOCKETS +# error No sockets available! +#endif + +OF_ASSUME_NONNULL_BEGIN + +/** + * @class OFListenOnSocketFailedException \ + * OFListenOnSocketFailedException.h \ + * ObjFW/OFListenOnSocketFailedException.h + * + * @brief An exception indicating that listening on the socket failed. + */ +@interface OFListenOnSocketFailedException: OFException +{ + id _socket; + int _backlog, _errNo; + OF_RESERVE_IVARS(OFListenOnSocketFailedException, 4) +} + +/** + * @brief The socket which failed to listen. + */ +@property (readonly, nonatomic) id socket; + +/** + * @brief The requested back log. + */ +@property (readonly, nonatomic) int backlog; + +/** + * @brief The errno of the error that occurred. + */ +@property (readonly, nonatomic) int errNo; + +/** + * @brief Creates a new, autoreleased listen failed exception. + * + * @param socket The socket which failed to listen + * @param backlog The requested size of the back log + * @param errNo The errno of the error that occurred + * @return A new, autoreleased listen failed exception + */ ++ (instancetype)exceptionWithSocket: (id)socket + backlog: (int)backlog + errNo: (int)errNo; + ++ (instancetype)exception OF_UNAVAILABLE; + +/** + * @brief Initializes an already allocated listen failed exception. + * + * @param socket The socket which failed to listen + * @param backlog The requested size of the back log + * @param errNo The errno of the error that occurred + * @return An initialized listen failed exception + */ +- (instancetype)initWithSocket: (id)socket + backlog: (int)backlog + errNo: (int)errNo OF_DESIGNATED_INITIALIZER; + +- (instancetype)init OF_UNAVAILABLE; +@end + +OF_ASSUME_NONNULL_END ADDED src/exceptions/OFListenOnSocketFailedException.m Index: src/exceptions/OFListenOnSocketFailedException.m ================================================================== --- src/exceptions/OFListenOnSocketFailedException.m +++ src/exceptions/OFListenOnSocketFailedException.m @@ -0,0 +1,67 @@ +/* + * 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 "OFListenOnSocketFailedException.h" +#import "OFString.h" + +@implementation OFListenOnSocketFailedException +@synthesize socket = _socket, backlog = _backlog, errNo = _errNo; + ++ (instancetype)exception +{ + OF_UNRECOGNIZED_SELECTOR +} + ++ (instancetype)exceptionWithSocket: (id)sock + backlog: (int)backlog + errNo: (int)errNo +{ + return [[[self alloc] initWithSocket: sock + backlog: backlog + errNo: errNo] autorelease]; +} + +- (instancetype)init +{ + OF_INVALID_INIT_METHOD +} + +- (instancetype)initWithSocket: (id)sock backlog: (int)backlog errNo: (int)errNo +{ + self = [super init]; + + _socket = [sock retain]; + _backlog = backlog; + _errNo = errNo; + + return self; +} + +- (void)dealloc +{ + [_socket release]; + + [super dealloc]; +} + +- (OFString *)description +{ + return [OFString stringWithFormat: + @"Failed to listen in socket of type %@ with a back log of %d: %@", + [_socket class], _backlog, OFStrError(_errNo)]; +} +@end