1
2
3
4
5
6
7
8
9
10
11
|
/*
* Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017,
* 2018, 2019
* Jonathan Schleifer <js@heap.zone>
*
* 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.
*
|
|
|
|
1
2
3
4
5
6
7
8
9
10
11
|
/*
* Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017,
* 2018, 2019, 2020
* 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.
*
|
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
#ifdef HAVE_POLL_H
# include <poll.h>
#endif
#import "OFPollKernelEventObserver.h"
#import "OFData.h"
#import "OFKernelEventObserver+Private.h"
#import "OFKernelEventObserver.h"
#import "OFObserveFailedException.h"
#import "OFOutOfRangeException.h"
#import "socket_helpers.h"
#ifdef OF_WII
|
<
<
|
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
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
168
169
170
171
|
}
break;
}
}
}
- (void)of_addObjectForReading: (id <OFReadyForReadingObserving>)object
{
[self of_addObject: object
fileDescriptor: object.fileDescriptorForReading
events: POLLIN];
}
- (void)of_addObjectForWriting: (id <OFReadyForWritingObserving>)object
{
[self of_addObject: object
fileDescriptor: object.fileDescriptorForWriting
events: POLLOUT];
}
- (void)of_removeObjectForReading: (id <OFReadyForReadingObserving>)object
{
[self of_removeObject: object
fileDescriptor: object.fileDescriptorForReading
events: POLLIN];
}
- (void)of_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;
[self of_processQueue];
if ([self of_processReadBuffers])
return;
FDs = _FDs.mutableItems;
nFDs = _FDs.count;
#ifdef OPEN_MAX
|
|
|
>
|
>
|
|
>
|
>
|
|
>
|
>
|
>
>
<
<
|
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
168
169
170
171
172
173
174
175
|
}
break;
}
}
}
- (void)addObjectForReading: (id <OFReadyForReadingObserving>)object
{
[self of_addObject: object
fileDescriptor: object.fileDescriptorForReading
events: POLLIN];
[super addObjectForReading: object];
}
- (void)addObjectForWriting: (id <OFReadyForWritingObserving>)object
{
[self of_addObject: object
fileDescriptor: object.fileDescriptorForWriting
events: POLLOUT];
[super addObjectForWriting: object];
}
- (void)removeObjectForReading: (id <OFReadyForReadingObserving>)object
{
[self of_removeObject: object
fileDescriptor: object.fileDescriptorForReading
events: POLLIN];
[super removeObjectForReading: object];
}
- (void)removeObjectForWriting: (id <OFReadyForWritingObserving>)object
{
[self of_removeObject: object
fileDescriptor: object.fileDescriptorForWriting
events: POLLOUT];
[super removeObjectForWriting: object];
}
- (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
|
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
|
@selector(objectIsReadyForReading:)])
[_delegate objectIsReadyForReading:
_FDToObject[FDs[i].fd]];
objc_autoreleasePoolPop(pool);
}
if (FDs[i].revents & POLLOUT) {
void *pool = objc_autoreleasePoolPush();
if ([_delegate respondsToSelector:
@selector(objectIsReadyForWriting:)])
[_delegate objectIsReadyForWriting:
_FDToObject[FDs[i].fd]];
|
|
|
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
|
@selector(objectIsReadyForReading:)])
[_delegate objectIsReadyForReading:
_FDToObject[FDs[i].fd]];
objc_autoreleasePoolPop(pool);
}
if (FDs[i].revents & (POLLOUT | POLLHUP)) {
void *pool = objc_autoreleasePoolPush();
if ([_delegate respondsToSelector:
@selector(objectIsReadyForWriting:)])
[_delegate objectIsReadyForWriting:
_FDToObject[FDs[i].fd]];
|