ObjFW  Diff

Differences From Artifact [17f5ac1ccb]:

To Artifact [a6a3da0735]:


19
20
21
22
23
24
25
26
27
28
29

30
31
32
33
34
35
36
19
20
21
22
23
24
25

26
27
28
29
30
31
32
33
34
35
36







-



+







#define __NO_EXT_QNX

#include <unistd.h>
#include <poll.h>

#import "OFStreamObserver_poll.h"
#import "OFDataArray.h"
#import "OFAutoreleasePool.h"

#import "OFOutOfRangeException.h"

#import "autorelease.h"
#import "macros.h"

@implementation OFStreamObserver_poll
- init
{
	self = [super init];

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
168
169
170
171
172
173
174
175
176
177
178
179



180
181
182
183
184
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
168
169

170
171
172
173
174

175
176
177


178
179
180

181
182
183
184







-
+






-
+


+
+









-
+
-

-
+
-

+
+







+





-





-





-



-
-
+
+
+
-




{
	[self _removeFileDescriptor: fd
			 withEvents: POLLOUT];
}

- (BOOL)observeWithTimeout: (int)timeout
{
	OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init];
	void *pool = objc_autoreleasePoolPush();
	struct pollfd *FDsCArray;
	size_t i, nFDs;

	[self _processQueue];

	if ([self _processCache]) {
		[pool release];
		objc_autoreleasePoolPop(pool);
		return YES;
	}

	objc_autoreleasePoolPop(pool);

	FDsCArray = [FDs cArray];
	nFDs = [FDs count];

#ifdef OPEN_MAX
	if (nFDs > OPEN_MAX)
		@throw [OFOutOfRangeException exceptionWithClass: [self class]];
#endif

	if (poll(FDsCArray, (nfds_t)nFDs, timeout) < 1) {
	if (poll(FDsCArray, (nfds_t)nFDs, timeout) < 1)
		[pool release];
		return NO;
	}


	for (i = 0; i < nFDs; i++) {
		pool = objc_autoreleasePoolPush();

		if (FDsCArray[i].revents & POLLIN) {
			if (FDsCArray[i].fd == cancelFD[0]) {
				char buffer;

				OF_ENSURE(read(cancelFD[0], &buffer, 1) > 0);
				FDsCArray[i].revents = 0;

				objc_autoreleasePoolPop(pool);
				continue;
			}

			[delegate streamIsReadyForReading:
			    FDToStream[FDsCArray[i].fd]];
			[pool releaseObjects];
		}

		if (FDsCArray[i].revents & POLLOUT) {
			[delegate streamIsReadyForWriting:
			    FDToStream[FDsCArray[i].fd]];
			[pool releaseObjects];
		}

		if (FDsCArray[i].revents & POLLERR) {
			[delegate streamDidReceiveException:
			    FDToStream[FDsCArray[i].fd]];
			[pool releaseObjects];
		}

		FDsCArray[i].revents = 0;
	}


		objc_autoreleasePoolPop(pool);
	}
	[pool release];

	return YES;
}
@end