Index: src/OFSequencedPacketSocket.h ================================================================== --- src/OFSequencedPacketSocket.h +++ src/OFSequencedPacketSocket.h @@ -320,11 +320,11 @@ /** * @brief Accept an incoming connection. * * @return An autoreleased sequenced packet socket for the accepted connection. - * @throw OFAcceptFailedException Accepting failed + * @throw OFAcceptSocketFailedException Accepting failed * @throw OFNotOpenException The socket is not open */ - (instancetype)accept; /** Index: src/OFSequencedPacketSocket.m ================================================================== --- src/OFSequencedPacketSocket.m +++ src/OFSequencedPacketSocket.m @@ -33,11 +33,11 @@ #import "OFRunLoop+Private.h" #import "OFRunLoop.h" #import "OFSocket.h" #import "OFSocket+Private.h" -#import "OFAcceptFailedException.h" +#import "OFAcceptSocketFailedException.h" #import "OFInitializationFailedException.h" #import "OFInvalidArgumentException.h" #import "OFListenFailedException.h" #import "OFNotOpenException.h" #import "OFOutOfRangeException.h" @@ -335,26 +335,26 @@ #if defined(HAVE_PACCEPT) && defined(SOCK_CLOEXEC) if ((client->_socket = paccept(_socket, (struct sockaddr *)&client->_remoteAddress.sockaddr, &client->_remoteAddress.length, NULL, SOCK_CLOEXEC)) == OFInvalidSocketHandle) - @throw [OFAcceptFailedException + @throw [OFAcceptSocketFailedException exceptionWithSocket: self errNo: OFSocketErrNo()]; #elif defined(HAVE_ACCEPT4) && defined(SOCK_CLOEXEC) if ((client->_socket = accept4(_socket, (struct sockaddr *)&client->_remoteAddress.sockaddr, &client->_remoteAddress.length, SOCK_CLOEXEC)) == OFInvalidSocketHandle) - @throw [OFAcceptFailedException + @throw [OFAcceptSocketFailedException exceptionWithSocket: self errNo: OFSocketErrNo()]; #else if ((client->_socket = accept(_socket, (struct sockaddr *)&client->_remoteAddress.sockaddr, &client->_remoteAddress.length)) == OFInvalidSocketHandle) - @throw [OFAcceptFailedException + @throw [OFAcceptSocketFailedException exceptionWithSocket: self errNo: OFSocketErrNo()]; # if defined(HAVE_FCNTL) && defined(FD_CLOEXEC) if ((flags = fcntl(client->_socket, F_GETFD, 0)) != -1) Index: src/OFStreamSocket.h ================================================================== --- src/OFStreamSocket.h +++ src/OFStreamSocket.h @@ -121,11 +121,11 @@ /** * @brief Accept an incoming connection. * * @return An autoreleased OFStreamSocket for the accepted connection. - * @throw OFAcceptFailedException Accepting failed + * @throw OFAcceptSocketFailedException Accepting failed * @throw OFNotOpenException The socket is not open */ - (instancetype)accept; /** Index: src/OFStreamSocket.m ================================================================== --- src/OFStreamSocket.m +++ src/OFStreamSocket.m @@ -29,11 +29,11 @@ #import "OFStreamSocket+Private.h" #import "OFRunLoop.h" #import "OFRunLoop+Private.h" #import "OFSocket+Private.h" -#import "OFAcceptFailedException.h" +#import "OFAcceptSocketFailedException.h" #import "OFInitializationFailedException.h" #import "OFInvalidArgumentException.h" #import "OFListenFailedException.h" #import "OFNotImplementedException.h" #import "OFNotOpenException.h" @@ -256,26 +256,26 @@ #if defined(HAVE_PACCEPT) && defined(SOCK_CLOEXEC) if ((client->_socket = paccept(_socket, (struct sockaddr *)&client->_remoteAddress.sockaddr, &client->_remoteAddress.length, NULL, SOCK_CLOEXEC)) == OFInvalidSocketHandle) - @throw [OFAcceptFailedException + @throw [OFAcceptSocketFailedException exceptionWithSocket: self errNo: OFSocketErrNo()]; #elif defined(HAVE_ACCEPT4) && defined(SOCK_CLOEXEC) if ((client->_socket = accept4(_socket, (struct sockaddr * )&client->_remoteAddress.sockaddr, &client->_remoteAddress.length, SOCK_CLOEXEC)) == OFInvalidSocketHandle) - @throw [OFAcceptFailedException + @throw [OFAcceptSocketFailedException exceptionWithSocket: self errNo: OFSocketErrNo()]; #else if ((client->_socket = accept(_socket, (struct sockaddr *)&client->_remoteAddress.sockaddr, &client->_remoteAddress.length)) == OFInvalidSocketHandle) - @throw [OFAcceptFailedException + @throw [OFAcceptSocketFailedException exceptionWithSocket: self errNo: OFSocketErrNo()]; # if defined(HAVE_FCNTL) && defined(FD_CLOEXEC) if ((flags = fcntl(client->_socket, F_GETFD, 0)) != -1) Index: src/ObjFW.h ================================================================== --- src/ObjFW.h +++ src/ObjFW.h @@ -144,11 +144,11 @@ #endif #import "OFAllocFailedException.h" #import "OFException.h" #ifdef OF_HAVE_SOCKETS -# import "OFAcceptFailedException.h" +# import "OFAcceptSocketFailedException.h" # import "OFAlreadyConnectedException.h" # import "OFBindSocketFailedException.h" # import "OFBindIPSocketFailedException.h" # ifdef OF_HAVE_UNIX_SOCKETS # import "OFBindUNIXSocketFailedException.h" Index: src/exceptions/Makefile ================================================================== --- src/exceptions/Makefile +++ src/exceptions/Makefile @@ -51,11 +51,11 @@ ${USE_SRCS_THREADS} \ ${USE_SRCS_WINDOWS} SRCS_FILES = OFChangeCurrentDirectoryFailedException.m \ OFGetCurrentDirectoryFailedException.m SRCS_PLUGINS = OFLoadPluginFailedException.m -SRCS_SOCKETS = OFAcceptFailedException.m \ +SRCS_SOCKETS = OFAcceptSocketFailedException.m \ OFAlreadyConnectedException.m \ OFBindSocketFailedException.m \ OFBindIPSocketFailedException.m \ OFConnectSocketFailedException.m \ OFDNSQueryFailedException.m \ DELETED src/exceptions/OFAcceptFailedException.h Index: src/exceptions/OFAcceptFailedException.h ================================================================== --- src/exceptions/OFAcceptFailedException.h +++ src/exceptions/OFAcceptFailedException.h @@ -1,71 +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 OFAcceptFailedException \ - * OFAcceptFailedException.h ObjFW/OFAcceptFailedException.h - * - * @brief An exception indicating that accepting a connection failed. - */ -@interface OFAcceptFailedException: OFException -{ - id _socket; - int _errNo; - OF_RESERVE_IVARS(OFAcceptFailedException, 4) -} - -/** - * @brief The socket which could not accept a connection. - */ -@property (readonly, nonatomic) id socket; - -/** - * @brief The errno from when the exception was created. - */ -@property (readonly, nonatomic) int errNo; - -+ (instancetype)exception OF_UNAVAILABLE; - -/** - * @brief Creates a new, autoreleased accept failed exception. - * - * @param socket The socket which could not accept a connection - * @param errNo The errno for the error - * @return A new, autoreleased accept failed exception - */ -+ (instancetype)exceptionWithSocket: (id)socket errNo: (int)errNo; - -- (instancetype)init OF_UNAVAILABLE; - -/** - * @brief Initializes an already allocated accept failed exception. - * - * @param socket The socket which could not accept a connection - * @param errNo The errno for the error - * @return An initialized accept failed exception - */ -- (instancetype)initWithSocket: (id)socket - errNo: (int)errNo OF_DESIGNATED_INITIALIZER; -@end - -OF_ASSUME_NONNULL_END DELETED src/exceptions/OFAcceptFailedException.m Index: src/exceptions/OFAcceptFailedException.m ================================================================== --- src/exceptions/OFAcceptFailedException.m +++ src/exceptions/OFAcceptFailedException.m @@ -1,62 +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 "OFAcceptFailedException.h" -#import "OFString.h" - -@implementation OFAcceptFailedException -@synthesize socket = _socket, errNo = _errNo; - -+ (instancetype)exception -{ - OF_UNRECOGNIZED_SELECTOR -} - -+ (instancetype)exceptionWithSocket: (id)socket errNo: (int)errNo -{ - return [[[self alloc] initWithSocket: socket errNo: errNo] autorelease]; -} - -- (instancetype)init -{ - OF_INVALID_INIT_METHOD -} - -- (instancetype)initWithSocket: (id)socket errNo: (int)errNo -{ - self = [super init]; - - _socket = [socket retain]; - _errNo = errNo; - - return self; -} - -- (void)dealloc -{ - [_socket release]; - - [super dealloc]; -} - -- (OFString *)description -{ - return [OFString stringWithFormat: - @"Failed to accept connection in socket of class %@: %@", - [_socket class], OFStrError(_errNo)]; -} -@end ADDED src/exceptions/OFAcceptSocketFailedException.h Index: src/exceptions/OFAcceptSocketFailedException.h ================================================================== --- src/exceptions/OFAcceptSocketFailedException.h +++ src/exceptions/OFAcceptSocketFailedException.h @@ -0,0 +1,71 @@ +/* + * 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 OFAcceptSocketFailedException \ + * OFAcceptSocketFailedException.h ObjFW/OFAcceptSocketFailedException.h + * + * @brief An exception indicating that accepting a connection failed. + */ +@interface OFAcceptSocketFailedException: OFException +{ + id _socket; + int _errNo; + OF_RESERVE_IVARS(OFAcceptSocketFailedException, 4) +} + +/** + * @brief The socket which could not accept a connection. + */ +@property (readonly, nonatomic) id socket; + +/** + * @brief The errno from when the exception was created. + */ +@property (readonly, nonatomic) int errNo; + ++ (instancetype)exception OF_UNAVAILABLE; + +/** + * @brief Creates a new, autoreleased accept failed exception. + * + * @param socket The socket which could not accept a connection + * @param errNo The errno for the error + * @return A new, autoreleased accept failed exception + */ ++ (instancetype)exceptionWithSocket: (id)socket errNo: (int)errNo; + +- (instancetype)init OF_UNAVAILABLE; + +/** + * @brief Initializes an already allocated accept failed exception. + * + * @param socket The socket which could not accept a connection + * @param errNo The errno for the error + * @return An initialized accept failed exception + */ +- (instancetype)initWithSocket: (id)socket + errNo: (int)errNo OF_DESIGNATED_INITIALIZER; +@end + +OF_ASSUME_NONNULL_END ADDED src/exceptions/OFAcceptSocketFailedException.m Index: src/exceptions/OFAcceptSocketFailedException.m ================================================================== --- src/exceptions/OFAcceptSocketFailedException.m +++ src/exceptions/OFAcceptSocketFailedException.m @@ -0,0 +1,62 @@ +/* + * 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 "OFAcceptSocketFailedException.h" +#import "OFString.h" + +@implementation OFAcceptSocketFailedException +@synthesize socket = _socket, errNo = _errNo; + ++ (instancetype)exception +{ + OF_UNRECOGNIZED_SELECTOR +} + ++ (instancetype)exceptionWithSocket: (id)socket errNo: (int)errNo +{ + return [[[self alloc] initWithSocket: socket errNo: errNo] autorelease]; +} + +- (instancetype)init +{ + OF_INVALID_INIT_METHOD +} + +- (instancetype)initWithSocket: (id)socket errNo: (int)errNo +{ + self = [super init]; + + _socket = [socket retain]; + _errNo = errNo; + + return self; +} + +- (void)dealloc +{ + [_socket release]; + + [super dealloc]; +} + +- (OFString *)description +{ + return [OFString stringWithFormat: + @"Failed to accept connection in socket of class %@: %@", + [_socket class], OFStrError(_errNo)]; +} +@end