Comment: | OFKernelEventObserver: Remove queueing of actions
This removes the ability to let a thread add or remove objects for |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA3-256: |
24eff635db9642ec8e3301754afcae13 |
User & Date: | js on 2020-01-07 20:28:41 |
Other Links: | manifest | tags |
2020-01-07
| ||
20:36 | OFStream: Always cancel async requests on close check-in: 321fa12f9a user: js tags: trunk | |
20:28 | OFKernelEventObserver: Remove queueing of actions check-in: 24eff635db user: js tags: trunk | |
2020-01-06
| ||
00:38 | OFPollKernelEventObserver: Handle POLLHUP check-in: ca45e83bb0 user: js tags: trunk | |
Modified src/OFEpollKernelEventObserver.m from [e20baf20e3] to [3f87d51ce3].
︙ | ︙ | |||
25 26 27 28 29 30 31 | #endif #include "unistd_wrapper.h" #include <sys/epoll.h> #import "OFEpollKernelEventObserver.h" #import "OFArray.h" | < < < < < | 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | #endif #include "unistd_wrapper.h" #include <sys/epoll.h> #import "OFEpollKernelEventObserver.h" #import "OFArray.h" #import "OFMapTable.h" #import "OFNull.h" #import "OFInitializationFailedException.h" #import "OFObserveFailedException.h" #define EVENTLIST_SIZE 64 |
︙ | ︙ | |||
154 155 156 157 158 159 160 | errNo: errno]; [_FDToEvents setObject: (void *)events forKey: (void *)((intptr_t)fd + 1)]; } } | | | | | < < | 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 | errNo: errno]; [_FDToEvents setObject: (void *)events forKey: (void *)((intptr_t)fd + 1)]; } } - (void)addObjectForReading: (id <OFReadyForReadingObserving>)object { [self of_addObject: object fileDescriptor: object.fileDescriptorForReading events: EPOLLIN]; } - (void)addObjectForWriting: (id <OFReadyForWritingObserving>)object { [self of_addObject: object fileDescriptor: object.fileDescriptorForWriting events: EPOLLOUT]; } - (void)removeObjectForReading: (id <OFReadyForReadingObserving>)object { [self of_removeObject: object fileDescriptor: object.fileDescriptorForReading events: EPOLLIN]; } - (void)removeObjectForWriting: (id <OFReadyForWritingObserving>)object { [self of_removeObject: object fileDescriptor: object.fileDescriptorForWriting events: EPOLLOUT]; } - (void)observeForTimeInterval: (of_time_interval_t)timeInterval { OFNull *nullObject = [OFNull null]; struct epoll_event eventList[EVENTLIST_SIZE]; int events; if ([self of_processReadBuffers]) return; events = epoll_wait(_epfd, eventList, EVENTLIST_SIZE, (timeInterval != -1 ? timeInterval * 1000 : -1)); if (events < 0) |
︙ | ︙ |
Deleted src/OFKernelEventObserver+Private.h version [55f1e4e05d].
|
| < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < |
Modified src/OFKernelEventObserver.h from [587b828b7b] to [f3b368ad12].
︙ | ︙ | |||
132 133 134 135 136 137 138 | #else of_socket_t _cancelFD[2]; struct sockaddr_in _cancelAddr; #endif #ifdef OF_AMIGAOS ULONG _execSignalMask; #endif | < < < < < < | 132 133 134 135 136 137 138 139 140 141 142 143 144 145 | #else of_socket_t _cancelFD[2]; struct sockaddr_in _cancelAddr; #endif #ifdef OF_AMIGAOS ULONG _execSignalMask; #endif OF_RESERVE_IVARS(4) } /*! * @brief The delegate for the OFKernelEventObserver. */ @property OF_NULLABLE_PROPERTY (assign, nonatomic) |
︙ | ︙ | |||
230 231 232 233 234 235 236 | * @param date The until which to observe */ - (void)observeUntilDate: (OFDate *)date; /*! * @brief Cancels the currently blocking observe call. * | | < | > > > > > > > | 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 | * @param date The until which to observe */ - (void)observeUntilDate: (OFDate *)date; /*! * @brief Cancels the currently blocking observe call. * * This is the only method that can and should be called from another thread * than the one using the observer. */ - (void)cancel; /*! * @brief This method should be called by subclasses in @ref observeUntilDate: * as the first thing to handle all sockets that currently have data in * the read buffer. */ - (bool)of_processReadBuffers; @end #endif OF_ASSUME_NONNULL_END |
Modified src/OFKernelEventObserver.m from [fac1be8914] to [6cc4e842a3].
︙ | ︙ | |||
18 19 20 21 22 23 24 | #define __NO_EXT_QNX #include "config.h" #include <errno.h> #import "OFKernelEventObserver.h" | < < < < | 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | #define __NO_EXT_QNX #include "config.h" #include <errno.h> #import "OFKernelEventObserver.h" #import "OFArray.h" #import "OFData.h" #import "OFDate.h" #import "OFStream.h" #import "OFStream+Private.h" #ifndef OF_HAVE_PIPE # import "OFStreamSocket.h" #endif #ifdef HAVE_KQUEUE |
︙ | ︙ | |||
166 167 168 169 170 171 172 | if (of_socket_errno() != EADDRINUSE) @throw [OFInitializationFailedException exceptionWithClass: self.class]; } # endif #endif | < < < < < < < < | 162 163 164 165 166 167 168 169 170 171 172 173 174 175 | if (of_socket_errno() != EADDRINUSE) @throw [OFInitializationFailedException exceptionWithClass: self.class]; } # endif #endif } @catch (id e) { [self release]; @throw e; } return self; } |
︙ | ︙ | |||
197 198 199 200 201 202 203 | if (_cancelFD[1] != _cancelFD[0]) closesocket(_cancelFD[1]); #endif [_readObjects release]; [_writeObjects release]; | < < < < < < < < < < < < | < < < < < | < < < < < < < < < | < < < < < | < < < < < < < < < | < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < | 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 | if (_cancelFD[1] != _cancelFD[0]) closesocket(_cancelFD[1]); #endif [_readObjects release]; [_writeObjects release]; [super dealloc]; } - (void)addObjectForReading: (id <OFReadyForReadingObserving>)object { OF_UNRECOGNIZED_SELECTOR } - (void)addObjectForWriting: (id <OFReadyForWritingObserving>)object { OF_UNRECOGNIZED_SELECTOR } - (void)removeObjectForReading: (id <OFReadyForReadingObserving>)object { OF_UNRECOGNIZED_SELECTOR } - (void)removeObjectForWriting: (id <OFReadyForWritingObserving>)object { OF_UNRECOGNIZED_SELECTOR } - (bool)of_processReadBuffers { bool foundInReadBuffer = false; for (id object in _readObjects) { |
︙ | ︙ |
Modified src/OFKqueueKernelEventObserver.m from [bba062bb20] to [e2ae904e52].
︙ | ︙ | |||
27 28 29 30 31 32 33 | #include <sys/types.h> #include <sys/event.h> #include <sys/time.h> #import "OFKqueueKernelEventObserver.h" #import "OFArray.h" | < < < < < | 27 28 29 30 31 32 33 34 35 36 37 38 39 40 | #include <sys/types.h> #include <sys/event.h> #include <sys/time.h> #import "OFKqueueKernelEventObserver.h" #import "OFArray.h" #import "OFInitializationFailedException.h" #import "OFObserveFailedException.h" #import "OFOutOfRangeException.h" #define EVENTLIST_SIZE 64 |
︙ | ︙ | |||
82 83 84 85 86 87 88 | - (void)dealloc { close(_kernelQueue); [super dealloc]; } | | | | | < < | 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 | - (void)dealloc { close(_kernelQueue); [super dealloc]; } - (void)addObjectForReading: (id <OFReadyForReadingObserving>)object { struct kevent event; memset(&event, 0, sizeof(event)); event.ident = object.fileDescriptorForReading; event.filter = EVFILT_READ; event.flags = EV_ADD; #ifndef OF_NETBSD event.udata = object; #else event.udata = (intptr_t)object; #endif if (kevent(_kernelQueue, &event, 1, NULL, 0, NULL) != 0) @throw [OFObserveFailedException exceptionWithObserver: self errNo: errno]; } - (void)addObjectForWriting: (id <OFReadyForWritingObserving>)object { struct kevent event; memset(&event, 0, sizeof(event)); event.ident = object.fileDescriptorForWriting; event.filter = EVFILT_WRITE; event.flags = EV_ADD; #ifndef OF_NETBSD event.udata = object; #else event.udata = (intptr_t)object; #endif if (kevent(_kernelQueue, &event, 1, NULL, 0, NULL) != 0) @throw [OFObserveFailedException exceptionWithObserver: self errNo: errno]; } - (void)removeObjectForReading: (id <OFReadyForReadingObserving>)object { struct kevent event; memset(&event, 0, sizeof(event)); 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]; } - (void)removeObjectForWriting: (id <OFReadyForWritingObserving>)object { struct kevent event; memset(&event, 0, sizeof(event)); 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]; } - (void)observeForTimeInterval: (of_time_interval_t)timeInterval { struct timespec timeout; struct kevent eventList[EVENTLIST_SIZE]; int events; if ([self of_processReadBuffers]) return; timeout.tv_sec = (time_t)timeInterval; timeout.tv_nsec = (timeInterval - timeout.tv_sec) * 1000000000; events = kevent(_kernelQueue, NULL, 0, eventList, EVENTLIST_SIZE, |
︙ | ︙ |
Modified src/OFPollKernelEventObserver.m from [2d8d57de4f] to [899a665da2].
︙ | ︙ | |||
24 25 26 27 28 29 30 | #ifdef HAVE_POLL_H # include <poll.h> #endif #import "OFPollKernelEventObserver.h" #import "OFData.h" | < < | 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | #ifdef HAVE_POLL_H # include <poll.h> #endif #import "OFPollKernelEventObserver.h" #import "OFData.h" #import "OFObserveFailedException.h" #import "OFOutOfRangeException.h" #import "socket_helpers.h" #ifdef OF_WII |
︙ | ︙ | |||
122 123 124 125 126 127 128 | } break; } } } | | | | | < < | 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 | } break; } } } - (void)addObjectForReading: (id <OFReadyForReadingObserving>)object { [self of_addObject: object fileDescriptor: object.fileDescriptorForReading events: POLLIN]; } - (void)addObjectForWriting: (id <OFReadyForWritingObserving>)object { [self of_addObject: object fileDescriptor: object.fileDescriptorForWriting events: POLLOUT]; } - (void)removeObjectForReading: (id <OFReadyForReadingObserving>)object { [self of_removeObject: object fileDescriptor: object.fileDescriptorForReading events: POLLIN]; } - (void)removeObjectForWriting: (id <OFReadyForWritingObserving>)object { [self of_removeObject: object fileDescriptor: object.fileDescriptorForWriting events: POLLOUT]; } - (void)observeForTimeInterval: (of_time_interval_t)timeInterval { struct pollfd *FDs; int events; size_t nFDs; if ([self of_processReadBuffers]) return; FDs = _FDs.mutableItems; nFDs = _FDs.count; #ifdef OPEN_MAX |
︙ | ︙ |
Modified src/OFSelectKernelEventObserver.m from [c790e3741d] to [2d6e268dc3].
︙ | ︙ | |||
29 30 31 32 33 34 35 | #include <errno.h> #include <string.h> #include <sys/time.h> #import "OFSelectKernelEventObserver.h" #import "OFArray.h" | < < | 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | #include <errno.h> #include <string.h> #include <sys/time.h> #import "OFSelectKernelEventObserver.h" #import "OFArray.h" #import "OFInitializationFailedException.h" #import "OFObserveFailedException.h" #import "OFOutOfRangeException.h" #import "socket_helpers.h" |
︙ | ︙ | |||
69 70 71 72 73 74 75 | _maxFD = (int)_cancelFD[0]; #endif return self; } | | | | | | 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 | _maxFD = (int)_cancelFD[0]; #endif return self; } - (void)addObjectForReading: (id <OFReadyForReadingObserving>)object { int fd = object.fileDescriptorForReading; if (fd < 0 || fd > INT_MAX - 1) @throw [OFOutOfRangeException exception]; #ifndef OF_WINDOWS if (fd >= (int)FD_SETSIZE) @throw [OFOutOfRangeException exception]; #endif if (fd > _maxFD) _maxFD = fd; FD_SET((of_socket_t)fd, &_readFDs); } - (void)addObjectForWriting: (id <OFReadyForWritingObserving>)object { int fd = object.fileDescriptorForWriting; if (fd < 0 || fd > INT_MAX - 1) @throw [OFOutOfRangeException exception]; #ifndef OF_WINDOWS if (fd >= (int)FD_SETSIZE) @throw [OFOutOfRangeException exception]; #endif if (fd > _maxFD) _maxFD = fd; FD_SET((of_socket_t)fd, &_writeFDs); } - (void)removeObjectForReading: (id <OFReadyForReadingObserving>)object { /* TODO: Adjust _maxFD */ int fd = object.fileDescriptorForReading; if (fd < 0) @throw [OFOutOfRangeException exception]; #ifndef OF_WINDOWS if (fd >= (int)FD_SETSIZE) @throw [OFOutOfRangeException exception]; #endif FD_CLR((of_socket_t)fd, &_readFDs); } - (void)removeObjectForWriting: (id <OFReadyForWritingObserving>)object { /* TODO: Adjust _maxFD */ int fd = object.fileDescriptorForWriting; if (fd < 0) @throw [OFOutOfRangeException exception]; |
︙ | ︙ | |||
151 152 153 154 155 156 157 | struct timeval timeout; int events; #ifdef OF_AMIGAOS ULONG execSignalMask, cancelSignal; #endif size_t count; | < < | 149 150 151 152 153 154 155 156 157 158 159 160 161 162 | struct timeval timeout; int events; #ifdef OF_AMIGAOS ULONG execSignalMask, cancelSignal; #endif size_t count; if ([self of_processReadBuffers]) return; #ifdef FD_COPY FD_COPY(&_readFDs, &readFDs); FD_COPY(&_writeFDs, &writeFDs); #else |
︙ | ︙ |
Modified src/OFTCPSocket.m from [e3f56ac740] to [6288b956d6].
︙ | ︙ | |||
220 221 222 223 224 225 226 227 228 229 230 231 | #endif } - (void)of_socketDidConnect: (OFTCPSocket *)sock exception: (id)exception { if (exception != nil) { [sock of_closeSocket]; if (_socketAddressesIndex >= _socketAddresses.count) { _exception = [exception retain]; [self didConnect]; | > > > > > > > | > > > > > > > | > > > > > > > | > | 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 | #endif } - (void)of_socketDidConnect: (OFTCPSocket *)sock exception: (id)exception { if (exception != nil) { /* * self might be retained only by the pending async requests, * which we're about to cancel. */ [[self retain] autorelease]; [sock cancelAsyncRequests]; [sock of_closeSocket]; if (_socketAddressesIndex >= _socketAddresses.count) { _exception = [exception retain]; [self didConnect]; } else { /* * We must not call it before returning, as otherwise * the new socket would be removed from the queue upon * return. */ OFRunLoop *runLoop = [OFRunLoop currentRunLoop]; SEL selector = @selector(tryNextAddressWithRunLoopMode:); OFTimer *timer = [OFTimer timerWithTimeInterval: 0 target: self selector: selector object: runLoop.currentMode repeats: false]; [runLoop addTimer: timer forMode: runLoop.currentMode]; } return; } if (_SOCKS5Host != nil) [self sendSOCKS5Request]; else |
︙ | ︙ |