Index: src/OFEpollKernelEventObserver.m ================================================================== --- src/OFEpollKernelEventObserver.m +++ src/OFEpollKernelEventObserver.m @@ -29,11 +29,11 @@ #import "OFArray.h" #import "OFMapTable.h" #import "OFNull.h" #import "OFInitializationFailedException.h" -#import "OFObserveFailedException.h" +#import "OFObserveKernelEventsFailedException.h" #define eventListSize 64 static const OFMapTableFunctions mapFunctions = { NULL }; @@ -102,12 +102,13 @@ event.events = (int)events | addEvents; event.data.ptr = object; if (epoll_ctl(_epfd, (events == 0 ? EPOLL_CTL_ADD : EPOLL_CTL_MOD), fd, &event) == -1) - @throw [OFObserveFailedException exceptionWithObserver: self - errNo: errno]; + @throw [OFObserveKernelEventsFailedException + exceptionWithObserver: self + errNo: errno]; [_FDToEvents setObject: (void *)(events | addEvents) forKey: (void *)((intptr_t)fd + 1)]; } @@ -127,11 +128,11 @@ * When an async connect fails, it seems the socket is * automatically removed from epoll, meaning ENOENT is * returned when we try to remove it after it failed. */ if (errno != ENOENT) - @throw [OFObserveFailedException + @throw [OFObserveKernelEventsFailedException exceptionWithObserver: self errNo: errno]; [_FDToEvents removeObjectForKey: (void *)((intptr_t)fd + 1)]; } else { @@ -140,11 +141,11 @@ memset(&event, 0, sizeof(event)); event.events = (int)events; event.data.ptr = object; if (epoll_ctl(_epfd, EPOLL_CTL_MOD, fd, &event) == -1) - @throw [OFObserveFailedException + @throw [OFObserveKernelEventsFailedException exceptionWithObserver: self errNo: errno]; [_FDToEvents setObject: (void *)events forKey: (void *)((intptr_t)fd + 1)]; @@ -198,12 +199,13 @@ events = epoll_wait(_epfd, eventList, eventListSize, (timeInterval != -1 ? timeInterval * 1000 : -1)); if (events < 0) - @throw [OFObserveFailedException exceptionWithObserver: self - errNo: errno]; + @throw [OFObserveKernelEventsFailedException + exceptionWithObserver: self + errNo: errno]; for (int i = 0; i < events; i++) { if (eventList[i].events & EPOLLIN) { void *pool = objc_autoreleasePoolPush(); Index: src/OFKqueueKernelEventObserver.m ================================================================== --- src/OFKqueueKernelEventObserver.m +++ src/OFKqueueKernelEventObserver.m @@ -29,11 +29,11 @@ #import "OFKqueueKernelEventObserver.h" #import "OFArray.h" #import "OFInitializationFailedException.h" -#import "OFObserveFailedException.h" +#import "OFObserveKernelEventsFailedException.h" #import "OFOutOfRangeException.h" #define eventListSize 64 @implementation OFKqueueKernelEventObserver @@ -92,12 +92,13 @@ * switched this to `void *` in NetBSD 10. */ event.udata = (__typeof__(event.udata))object; if (kevent(_kernelQueue, &event, 1, NULL, 0, NULL) != 0) - @throw [OFObserveFailedException exceptionWithObserver: self - errNo: errno]; + @throw [OFObserveKernelEventsFailedException + exceptionWithObserver: self + errNo: errno]; [super addObjectForReading: object]; } - (void)addObjectForWriting: (id )object @@ -113,12 +114,13 @@ * switched this to `void *` in NetBSD 10. */ event.udata = (__typeof__(event.udata))object; if (kevent(_kernelQueue, &event, 1, NULL, 0, NULL) != 0) - @throw [OFObserveFailedException exceptionWithObserver: self - errNo: errno]; + @throw [OFObserveKernelEventsFailedException + exceptionWithObserver: self + errNo: errno]; [super addObjectForWriting: object]; } - (void)removeObjectForReading: (id )object @@ -129,12 +131,13 @@ event.ident = object.fileDescriptorForReading; event.filter = EVFILT_READ; event.flags = EV_DELETE; if (kevent(_kernelQueue, &event, 1, NULL, 0, NULL) != 0) - @throw [OFObserveFailedException exceptionWithObserver: self - errNo: errno]; + @throw [OFObserveKernelEventsFailedException + exceptionWithObserver: self + errNo: errno]; [super removeObjectForReading: object]; } - (void)removeObjectForWriting: (id )object @@ -145,12 +148,13 @@ event.ident = object.fileDescriptorForWriting; event.filter = EVFILT_WRITE; event.flags = EV_DELETE; if (kevent(_kernelQueue, &event, 1, NULL, 0, NULL) != 0) - @throw [OFObserveFailedException exceptionWithObserver: self - errNo: errno]; + @throw [OFObserveKernelEventsFailedException + exceptionWithObserver: self + errNo: errno]; [super removeObjectForWriting: object]; } - (void)observeForTimeInterval: (OFTimeInterval)timeInterval @@ -167,18 +171,19 @@ events = kevent(_kernelQueue, NULL, 0, eventList, eventListSize, (timeInterval != -1 ? &timeout : NULL)); if (events < 0) - @throw [OFObserveFailedException exceptionWithObserver: self - errNo: errno]; + @throw [OFObserveKernelEventsFailedException + exceptionWithObserver: self + errNo: errno]; for (int i = 0; i < events; i++) { void *pool; if (eventList[i].flags & EV_ERROR) - @throw [OFObserveFailedException + @throw [OFObserveKernelEventsFailedException exceptionWithObserver: self errNo: (int)eventList[i].data]; if (eventList[i].ident == (uintptr_t)_cancelFD[0]) { char buffer; Index: src/OFPollKernelEventObserver.m ================================================================== --- src/OFPollKernelEventObserver.m +++ src/OFPollKernelEventObserver.m @@ -26,11 +26,11 @@ #import "OFPollKernelEventObserver.h" #import "OFData.h" #import "OFSocket+Private.h" -#import "OFObserveFailedException.h" +#import "OFObserveKernelEventsFailedException.h" #import "OFOutOfRangeException.h" #ifdef OF_WII # define pollfd pollsd # define fd socket @@ -72,12 +72,13 @@ struct pollfd *FDs; size_t count; bool found; if (fd < 0) - @throw [OFObserveFailedException exceptionWithObserver: self - errNo: EBADF]; + @throw [OFObserveKernelEventsFailedException + exceptionWithObserver: self + errNo: EBADF]; FDs = self->_FDs.mutableItems; count = self->_FDs.count; found = false; @@ -108,12 +109,13 @@ { struct pollfd *FDs; size_t nFDs; if (fd < 0) - @throw [OFObserveFailedException exceptionWithObserver: self - errNo: EBADF]; + @throw [OFObserveKernelEventsFailedException + exceptionWithObserver: self + errNo: EBADF]; FDs = self->_FDs.mutableItems; nFDs = self->_FDs.count; for (size_t i = 0; i < nFDs; i++) { @@ -183,12 +185,13 @@ events = poll(FDs, (nfds_t)nFDs, (int)(timeInterval != -1 ? timeInterval * 1000 : -1)); if (events < 0) - @throw [OFObserveFailedException exceptionWithObserver: self - errNo: errno]; + @throw [OFObserveKernelEventsFailedException + exceptionWithObserver: self + errNo: errno]; for (size_t i = 0; i < nFDs; i++) { assert(FDs[i].fd <= _maxFD); if (FDs[i].revents & POLLIN) { Index: src/OFRunLoop.m ================================================================== --- src/OFRunLoop.m +++ src/OFRunLoop.m @@ -39,11 +39,11 @@ #import "OFSortedList.h" #import "OFTimer.h" #import "OFTimer+Private.h" #import "OFDate.h" -#import "OFObserveFailedException.h" +#import "OFObserveKernelEventsFailedException.h" #import "OFWriteFailedException.h" #include "OFRunLoopConstants.inc" static OFRunLoop *mainRunLoop = nil; @@ -1649,11 +1649,11 @@ #if defined(OF_HAVE_SOCKETS) @try { [state->_kernelEventObserver observeForTimeInterval: timeout]; - } @catch (OFObserveFailedException *e) { + } @catch (OFObserveKernelEventsFailedException *e) { if (e.errNo != EINTR) @throw e; } #elif defined(OF_HAVE_THREADS) [state->_condition lock]; @@ -1677,11 +1677,11 @@ * another thread, it cancels the observe. */ #if defined(OF_HAVE_SOCKETS) @try { [state->_kernelEventObserver observe]; - } @catch (OFObserveFailedException *e) { + } @catch (OFObserveKernelEventsFailedException *e) { if (e.errNo != EINTR) @throw e; } #elif defined(OF_HAVE_THREADS) [state->_condition lock]; Index: src/OFSelectKernelEventObserver.m ================================================================== --- src/OFSelectKernelEventObserver.m +++ src/OFSelectKernelEventObserver.m @@ -32,11 +32,11 @@ #import "OFSelectKernelEventObserver.h" #import "OFArray.h" #import "OFSocket+Private.h" #import "OFInitializationFailedException.h" -#import "OFObserveFailedException.h" +#import "OFObserveKernelEventsFailedException.h" #import "OFOutOfRangeException.h" #ifdef OF_AMIGAOS # include #endif @@ -82,12 +82,13 @@ - (void)addObjectForReading: (id )object { int fd = object.fileDescriptorForReading; if (fd < 0) - @throw [OFObserveFailedException exceptionWithObserver: self - errNo: EBADF]; + @throw [OFObserveKernelEventsFailedException + exceptionWithObserver: self + errNo: EBADF]; if (fd > INT_MAX - 1) @throw [OFOutOfRangeException exception]; #ifndef OF_WINDOWS @@ -106,12 +107,13 @@ - (void)addObjectForWriting: (id )object { int fd = object.fileDescriptorForWriting; if (fd < 0) - @throw [OFObserveFailedException exceptionWithObserver: self - errNo: EBADF]; + @throw [OFObserveKernelEventsFailedException + exceptionWithObserver: self + errNo: EBADF]; if (fd > INT_MAX - 1) @throw [OFOutOfRangeException exception]; #ifndef OF_WINDOWS @@ -132,12 +134,13 @@ /* TODO: Adjust _maxFD */ int fd = object.fileDescriptorForReading; if (fd < 0) - @throw [OFObserveFailedException exceptionWithObserver: self - errNo: EBADF]; + @throw [OFObserveKernelEventsFailedException + exceptionWithObserver: self + errNo: EBADF]; #ifndef OF_WINDOWS if (fd >= (int)FD_SETSIZE) @throw [OFOutOfRangeException exception]; #endif @@ -152,12 +155,13 @@ /* TODO: Adjust _maxFD */ int fd = object.fileDescriptorForWriting; if (fd < 0) - @throw [OFObserveFailedException exceptionWithObserver: self - errNo: EBADF]; + @throw [OFObserveKernelEventsFailedException + exceptionWithObserver: self + errNo: EBADF]; #ifndef OF_WINDOWS if (fd >= (int)FD_SETSIZE) @throw [OFOutOfRangeException exception]; @@ -204,12 +208,13 @@ #endif timeout.tv_usec = (int)((timeInterval - timeout.tv_sec) * 1000000); #ifdef OF_AMIGAOS if ((cancelSignal = AllocSignal(-1)) == (BYTE)-1) - @throw [OFObserveFailedException exceptionWithObserver: self - errNo: EAGAIN]; + @throw [OFObserveKernelEventsFailedException + exceptionWithObserver: self + errNo: EAGAIN]; execSignalMask = _execSignalMask | (1ul << cancelSignal); Forbid(); @@ -229,11 +234,11 @@ events = select(_maxFD + 1, &readFDs, &writeFDs, NULL, (timeInterval != -1 ? &timeout : NULL)); #endif if (events < 0) - @throw [OFObserveFailedException + @throw [OFObserveKernelEventsFailedException exceptionWithObserver: self errNo: OFSocketErrNo()]; #ifdef OF_AMIGAOS if (execSignalMask != 0 && Index: src/ObjFW.h ================================================================== --- src/ObjFW.h +++ src/ObjFW.h @@ -204,11 +204,11 @@ #import "OFMalformedXMLException.h" #import "OFMoveItemFailedException.h" #import "OFNotImplementedException.h" #import "OFNotOpenException.h" #ifdef OF_HAVE_SOCKETS -# import "OFObserveFailedException.h" +# import "OFObserveKernelEventsFailedException.h" #endif #import "OFOpenItemFailedException.h" #ifdef OF_WINDOWS # import "OFOpenWindowsRegistryKeyFailedException.h" #endif Index: src/exceptions/Makefile ================================================================== --- src/exceptions/Makefile +++ src/exceptions/Makefile @@ -58,11 +58,11 @@ OFBindFailedException.m \ OFConnectionFailedException.m \ OFDNSQueryFailedException.m \ OFHTTPRequestFailedException.m \ OFListenFailedException.m \ - OFObserveFailedException.m \ + OFObserveKernelEventsFailedException.m \ OFResolveHostFailedException.m \ OFTLSHandshakeFailedException.m SRCS_THREADS = OFConditionBroadcastFailedException.m \ OFConditionSignalFailedException.m \ OFConditionStillWaitingException.m \ DELETED src/exceptions/OFObserveFailedException.h Index: src/exceptions/OFObserveFailedException.h ================================================================== --- src/exceptions/OFObserveFailedException.h +++ src/exceptions/OFObserveFailedException.h @@ -1,70 +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" - -OF_ASSUME_NONNULL_BEGIN - -@class OFKernelEventObserver; - -/** - * @class OFObserveFailedException \ - * OFObserveFailedException.h ObjFW/OFObserveFailedException.h - * - * @brief An exception indicating that observing failed. - */ -@interface OFObserveFailedException: OFException -{ - OFKernelEventObserver *_observer; - int _errNo; - OF_RESERVE_IVARS(OFObserveFailedException, 4) -} - -/** - * @brief The observer which failed to observe. - */ -@property (readonly, nonatomic) OFKernelEventObserver *observer; - -/** - * @brief The errno of the error that occurred. - */ -@property (readonly, nonatomic) int errNo; - -/** - * @brief Creates a new, autoreleased observe failed exception. - * - * @param observer The observer which failed to observe - * @param errNo The errno of the error that occurred - * @return A new, autoreleased observe failed exception - */ -+ (instancetype)exceptionWithObserver: (OFKernelEventObserver *)observer - errNo: (int)errNo; - -+ (instancetype)exception OF_UNAVAILABLE; - -/** - * @brief Initializes an already allocated observe failed exception. - * - * @param observer The observer which failed to observe - * @param errNo The errno of the error that occurred - * @return An initialized observe failed exception - */ -- (instancetype)initWithObserver: (OFKernelEventObserver *)observer - errNo: (int)errNo OF_DESIGNATED_INITIALIZER; - -- (instancetype)init OF_UNAVAILABLE; -@end - -OF_ASSUME_NONNULL_END DELETED src/exceptions/OFObserveFailedException.m Index: src/exceptions/OFObserveFailedException.m ================================================================== --- src/exceptions/OFObserveFailedException.m +++ src/exceptions/OFObserveFailedException.m @@ -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. - */ - -#include "config.h" - -#import "OFObserveFailedException.h" -#import "OFString.h" -#import "OFKernelEventObserver.h" - -@implementation OFObserveFailedException -@synthesize observer = _observer, errNo = _errNo; - -+ (instancetype)exception -{ - OF_UNRECOGNIZED_SELECTOR -} - -+ (instancetype)exceptionWithObserver: (OFKernelEventObserver *)observer - errNo: (int)errNo -{ - return [[[self alloc] initWithObserver: observer - errNo: errNo] autorelease]; -} - -- (instancetype)init -{ - OF_INVALID_INIT_METHOD -} - -- (instancetype)initWithObserver: (OFKernelEventObserver *)observer - errNo: (int)errNo -{ - self = [super init]; - - @try { - _observer = [observer retain]; - _errNo = errNo; - } @catch (id e) { - [self release]; - @throw e; - } - - return self; -} - -- (void)dealloc -{ - [_observer release]; - - [super dealloc]; -} - -- (OFString *)description -{ - return [OFString stringWithFormat: - @"An observer of class %@ failed to observe: %@", - _observer.class, OFStrError(_errNo)]; -} -@end ADDED src/exceptions/OFObserveKernelEventsFailedException.h Index: src/exceptions/OFObserveKernelEventsFailedException.h ================================================================== --- src/exceptions/OFObserveKernelEventsFailedException.h +++ src/exceptions/OFObserveKernelEventsFailedException.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" + +OF_ASSUME_NONNULL_BEGIN + +@class OFKernelEventObserver; + +/** + * @class OFObserveKernelEventsFailedException \ + * OFObserveKernelEventsFailedException.h \ + * ObjFW/OFObserveKernelEventsFailedException.h + * + * @brief An exception indicating that observing failed. + */ +@interface OFObserveKernelEventsFailedException: OFException +{ + OFKernelEventObserver *_observer; + int _errNo; + OF_RESERVE_IVARS(OFObserveKernelEventsFailedException, 4) +} + +/** + * @brief The observer which failed to observe. + */ +@property (readonly, nonatomic) OFKernelEventObserver *observer; + +/** + * @brief The errno of the error that occurred. + */ +@property (readonly, nonatomic) int errNo; + +/** + * @brief Creates a new, autoreleased observe failed exception. + * + * @param observer The observer which failed to observe + * @param errNo The errno of the error that occurred + * @return A new, autoreleased observe failed exception + */ ++ (instancetype)exceptionWithObserver: (OFKernelEventObserver *)observer + errNo: (int)errNo; + ++ (instancetype)exception OF_UNAVAILABLE; + +/** + * @brief Initializes an already allocated observe failed exception. + * + * @param observer The observer which failed to observe + * @param errNo The errno of the error that occurred + * @return An initialized observe failed exception + */ +- (instancetype)initWithObserver: (OFKernelEventObserver *)observer + errNo: (int)errNo OF_DESIGNATED_INITIALIZER; + +- (instancetype)init OF_UNAVAILABLE; +@end + +OF_ASSUME_NONNULL_END ADDED src/exceptions/OFObserveKernelEventsFailedException.m Index: src/exceptions/OFObserveKernelEventsFailedException.m ================================================================== --- src/exceptions/OFObserveKernelEventsFailedException.m +++ src/exceptions/OFObserveKernelEventsFailedException.m @@ -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. + */ + +#include "config.h" + +#import "OFObserveKernelEventsFailedException.h" +#import "OFString.h" +#import "OFKernelEventObserver.h" + +@implementation OFObserveKernelEventsFailedException +@synthesize observer = _observer, errNo = _errNo; + ++ (instancetype)exception +{ + OF_UNRECOGNIZED_SELECTOR +} + ++ (instancetype)exceptionWithObserver: (OFKernelEventObserver *)observer + errNo: (int)errNo +{ + return [[[self alloc] initWithObserver: observer + errNo: errNo] autorelease]; +} + +- (instancetype)init +{ + OF_INVALID_INIT_METHOD +} + +- (instancetype)initWithObserver: (OFKernelEventObserver *)observer + errNo: (int)errNo +{ + self = [super init]; + + @try { + _observer = [observer retain]; + _errNo = errNo; + } @catch (id e) { + [self release]; + @throw e; + } + + return self; +} + +- (void)dealloc +{ + [_observer release]; + + [super dealloc]; +} + +- (OFString *)description +{ + return [OFString stringWithFormat: + @"An observer of class %@ failed to observe: %@", + _observer.class, OFStrError(_errNo)]; +} +@end