Differences From Artifact [76859e1d9d]:
- File
src/OFKernelEventObserver_kqueue.m
— part of check-in
[13ee56edf3]
at
2014-06-21 21:43:43
on branch trunk
— Move all macros from OFObject.h to macros.h
This means that OFObject.h imports macros.h now, making it unnecessary
to manually import macros.h in almost every file. And while at it, also
import autorelease.h in OFObject.h, so that this doesn't need to be
manually imported in almost every file as well. (user: js, size: 4845) [annotate] [blame] [check-ins using]
To Artifact [70736e006a]:
- File
src/OFKernelEventObserver_kqueue.m
— part of check-in
[1dbe9a4e4e]
at
2014-08-22 19:09:34
on branch trunk
— Retain sockets until after removal from observer
Not retaining them caused kevent() to be called on an invalid fd. (user: js, size: 4137) [annotate] [blame] [check-ins using]
︙ | ︙ | |||
25 26 27 28 29 30 31 32 33 34 35 36 37 38 | #include <sys/event.h> #include <sys/time.h> #import "OFKernelEventObserver.h" #import "OFKernelEventObserver+Private.h" #import "OFKernelEventObserver_kqueue.h" #import "OFDataArray.h" #import "OFInitializationFailedException.h" #import "OFOutOfMemoryException.h" #import "OFOutOfRangeException.h" #import "socket_helpers.h" | > | 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | #include <sys/event.h> #include <sys/time.h> #import "OFKernelEventObserver.h" #import "OFKernelEventObserver+Private.h" #import "OFKernelEventObserver_kqueue.h" #import "OFDataArray.h" #import "OFArray.h" #import "OFInitializationFailedException.h" #import "OFOutOfMemoryException.h" #import "OFOutOfRangeException.h" #import "socket_helpers.h" |
︙ | ︙ | |||
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 | @try { if ((_kernelQueue = kqueue()) == -1) @throw [OFInitializationFailedException exceptionWithClass: [self class]]; _changeList = [[OFDataArray alloc] initWithItemSize: sizeof(struct kevent)]; [self OF_addFileDescriptorForReading: _cancelFD[0]]; } @catch (id e) { [self release]; @throw e; } return self; } - (void)dealloc { close(_kernelQueue); [_changeList release]; [super dealloc]; } - (void)OF_addFileDescriptorForReading: (int)fd { struct kevent event; | > > > | 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 | @try { if ((_kernelQueue = kqueue()) == -1) @throw [OFInitializationFailedException exceptionWithClass: [self class]]; _changeList = [[OFDataArray alloc] initWithItemSize: sizeof(struct kevent)]; _removedArray = [[OFMutableArray alloc] init]; [self OF_addFileDescriptorForReading: _cancelFD[0]]; } @catch (id e) { [self release]; @throw e; } return self; } - (void)dealloc { close(_kernelQueue); [_changeList release]; [_removedArray release]; [super dealloc]; } - (void)OF_addFileDescriptorForReading: (int)fd { struct kevent event; |
︙ | ︙ | |||
112 113 114 115 116 117 118 | struct timespec timeout; struct kevent eventList[EVENTLIST_SIZE]; int i, events, realEvents = 0; timeout.tv_sec = (time_t)timeInterval; timeout.tv_nsec = lrint((timeInterval - timeout.tv_sec) * 1000000000); | > > > > | > > | 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 | struct timespec timeout; struct kevent eventList[EVENTLIST_SIZE]; int i, events, realEvents = 0; timeout.tv_sec = (time_t)timeInterval; timeout.tv_nsec = lrint((timeInterval - timeout.tv_sec) * 1000000000); /* * Make sure to keep the streams retained and thus the file descriptors * valid until the actual change has been performed. */ [self OF_processQueueAndStoreRemovedIn: _removedArray]; if ([self OF_processCache]) { objc_autoreleasePoolPop(pool); return true; } objc_autoreleasePoolPop(pool); events = kevent(_kernelQueue, [_changeList items], (int)[_changeList count], eventList, EVENTLIST_SIZE, (timeInterval == -1 ? NULL : &timeout)); [_removedArray removeAllObjects]; if (events < 0) return false; [_changeList removeAllItems]; if (events == 0) |
︙ | ︙ | |||
146 147 148 149 150 151 152 | continue; } realEvents++; pool = objc_autoreleasePoolPush(); | < < < < < < < < < < < < < < < < < < < < < < < < | 156 157 158 159 160 161 162 163 164 165 166 167 168 169 | continue; } realEvents++; pool = objc_autoreleasePoolPush(); switch (eventList[i].filter) { case EVFILT_READ: if ([_delegate respondsToSelector: @selector(objectIsReadyForReading:)]) [_delegate objectIsReadyForReading: _FDToObject[eventList[i].ident]]; break; |
︙ | ︙ |