Differences From Artifact [f6b8ae522e]:
- File
src/OFPollKernelEventObserver.m
— part of check-in
[627511b032]
at
2020-11-14 12:23:55
on branch trunk
— Rename of_malloc and of_calloc
The new names should be more accurate. (user: js, size: 5124) [annotate] [blame] [check-ins using] [more...]
To Artifact [f68dab1660]:
- File src/OFPollKernelEventObserver.m — part of check-in [1b82d3bf4f] at 2021-03-07 20:25:21 on branch trunk — *.m: Fold methods into one line where it fits (user: js, size: 4927) [annotate] [blame] [check-ins using] [more...]
1 | /* | < < | | 1 2 3 4 5 6 7 8 9 | /* * Copyright (c) 2008-2021 Jonathan Schleifer <js@nil.im> * * 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. * |
︙ | ︙ | |||
65 66 67 68 69 70 71 | { [_FDs release]; free(_FDToObject); [super dealloc]; } | | < | | | | | | | | | | < | | | | < | < < | < < | < < | < | 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 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 | { [_FDs release]; free(_FDToObject); [super dealloc]; } static void addObject(OFPollKernelEventObserver *self, id object, int fd, short events) { struct pollfd *FDs; size_t count; bool found; if (fd < 0) @throw [OFObserveFailedException exceptionWithObserver: self errNo: EBADF]; FDs = self->_FDs.mutableItems; count = self->_FDs.count; found = false; for (size_t i = 0; i < count; i++) { if (FDs[i].fd == fd) { FDs[i].events |= events; found = true; break; } } if (!found) { struct pollfd p = { fd, events, 0 }; if (fd > self->_maxFD) { self->_maxFD = fd; self->_FDToObject = of_realloc(self->_FDToObject, (size_t)self->_maxFD + 1, sizeof(id)); } self->_FDToObject[fd] = object; [self->_FDs addItem: &p]; } } static void removeObject(OFPollKernelEventObserver *self, id object, int fd, short events) { struct pollfd *FDs; size_t nFDs; if (fd < 0) @throw [OFObserveFailedException exceptionWithObserver: self errNo: EBADF]; FDs = self->_FDs.mutableItems; nFDs = self->_FDs.count; for (size_t i = 0; i < nFDs; i++) { if (FDs[i].fd == fd) { FDs[i].events &= ~events; if (FDs[i].events == 0) { /* * TODO: Remove from and resize _FDToObject, * adjust _maxFD. */ [self->_FDs removeItemAtIndex: i]; } break; } } } - (void)addObjectForReading: (id <OFReadyForReadingObserving>)object { addObject(self, object, object.fileDescriptorForReading, POLLIN); [super addObjectForReading: object]; } - (void)addObjectForWriting: (id <OFReadyForWritingObserving>)object { addObject(self, object, object.fileDescriptorForWriting, POLLOUT); [super addObjectForWriting: object]; } - (void)removeObjectForReading: (id <OFReadyForReadingObserving>)object { removeObject(self, object, object.fileDescriptorForReading, POLLIN); [super removeObjectForReading: object]; } - (void)removeObjectForWriting: (id <OFReadyForWritingObserving>)object { removeObject(self, object, object.fileDescriptorForWriting, POLLOUT); [super removeObjectForWriting: object]; } - (void)observeForTimeInterval: (of_time_interval_t)timeInterval { void *pool; |
︙ | ︙ |