Differences From Artifact [8b9acbd834]:
- File src/OFStreamObserver_poll.m — part of check-in [c279948fb8] at 2011-09-19 12:44:09 on branch trunk — Nicer OFStreamObserver API. (user: js, size: 3597) [annotate] [blame] [check-ins using]
To Artifact [10244167cd]:
- File
src/OFStreamObserver_poll.m
— part of check-in
[47caef4f8a]
at
2011-09-20 18:40:54
on branch trunk
— OFStreamObserver improvements.
* Make it possible to close a stream before the add/remove queue has
been processed.
* The actual implementations don't need to handle OFStreams now, but
get the file descriptor instead.
* Use an OFMutex instead of @synchronized. (user: js, size: 3513) [annotate] [blame] [check-ins using]
︙ | ︙ | |||
56 57 58 59 60 61 62 | - (void)dealloc { [FDs release]; [super dealloc]; } | | | < | | < | | | | | | | | | | | | | | 56 57 58 59 60 61 62 63 64 65 66 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 | - (void)dealloc { [FDs release]; [super dealloc]; } - (void)_addFileDescriptor: (int)fd withEvents: (short)events { struct pollfd *FDsCArray = [FDs cArray]; size_t i, count = [FDs count]; BOOL found = NO; for (i = 0; i < count; i++) { if (FDsCArray[i].fd == fd) { FDsCArray[i].events |= events; found = YES; break; } } if (!found) { struct pollfd p = { fd, events | POLLERR, 0 }; [FDs addItem: &p]; } } - (void)_removeFileDescriptor: (int)fd withEvents: (short)events { struct pollfd *FDsCArray = [FDs cArray]; size_t i, nFDs = [FDs count]; for (i = 0; i < nFDs; i++) { if (FDsCArray[i].fd == fd) { FDsCArray[i].events &= ~events; if ((FDsCArray[i].events & ~POLLERR) == 0) [FDs removeItemAtIndex: i]; break; } } } - (void)_addFileDescriptorForReading: (int)fd { [self _addFileDescriptor: fd withEvents: POLLIN]; } - (void)_addFileDescriptorForWriting: (int)fd { [self _addFileDescriptor: fd withEvents: POLLOUT]; } - (void)_removeFileDescriptorForReading: (int)fd { [self _removeFileDescriptor: fd withEvents: POLLIN]; } - (void)_removeFileDescriptorForWriting: (int)fd { [self _removeFileDescriptor: fd withEvents: POLLOUT]; } - (BOOL)observeWithTimeout: (int)timeout { OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; struct pollfd *FDsCArray; size_t i, nFDs; |
︙ | ︙ |