ObjFW  Diff

Differences From Artifact [331bf675cd]:

  • File src/OFKernelEventObserver_select.m — part of check-in [220513a3f5] at 2015-05-09 18:13:19 on branch trunk — More OFKernelEventObserver refactoring

    This was necessary because select(), poll() and kevent() on FreeBSD and
    OS X would sometimes return 0 events, even if there are some, and
    sometimes return the correct number of events that were pending, meaning
    the number of events returned is unreliable. To make things worse,
    whether it returns 0 or the number of events that were pending is
    completely non-deterministic on both FreeBSD and OS X (running the same
    tests multiple times in a row would make it sometimes work and sometimes
    fail).

    In order to prevent code from depending on the return value of
    -[observeForTimeInterval:] (which would depend on select(), poll() and
    kevent() returning the correct number), OFKernelObserver no longer
    returns whether there were pending events. It is expected that
    -[observe] or -[observeForTimeInterval:] is just called in a loop as
    long as events should be handled.

    The tests have been changed as well to reflect this. What they do now is
    set a deadline and call -[observeForTimeInterval:] with a small timeout
    in a loop until the deadline is reached or all events have been handled.

    Note: DragonFlyBSD has not been tested, but will most likely behave like
    FreeBSD and OS X. (user: js, size: 4581) [annotate] [blame] [check-ins using]

To Artifact [69ccd8df63]:


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
	return self;
}

- (void)OF_addObjectForReading: (id)object
{
	int fd = [object fileDescriptorForReading];

	if (fd > INT_MAX - 1)
		@throw [OFOutOfRangeException exception];

#ifndef _WIN32
	if (fd >= FD_SETSIZE)
		@throw [OFOutOfRangeException exception];
#endif

	if (fd > _maxFD)
		_maxFD = fd;

	FD_SET(fd, &_readFDs);
}

- (void)OF_addObjectForWriting: (id)object
{
	int fd = [object fileDescriptorForWriting];

	if (fd > INT_MAX - 1)
		@throw [OFOutOfRangeException exception];

#ifndef _WIN32
	if (fd >= FD_SETSIZE)
		@throw [OFOutOfRangeException exception];
#endif

	if (fd > _maxFD)
		_maxFD = fd;

	FD_SET(fd, &_writeFDs);
}

- (void)OF_removeObjectForReading: (id)object
{
	/* TODO: Adjust _maxFD */

	int fd = [object fileDescriptorForReading];

	if (fd >= FD_SETSIZE)
		@throw [OFOutOfRangeException exception];

	FD_CLR(fd, &_readFDs);
}

- (void)OF_removeObjectForWriting: (id)object
{
	/* TODO: Adjust _maxFD */

	int fd = [object fileDescriptorForWriting];

	if (fd >= FD_SETSIZE)
		@throw [OFOutOfRangeException exception];

	FD_CLR(fd, &_writeFDs);
}

- (void)observeForTimeInterval: (of_time_interval_t)timeInterval
{







|

















|



















|











|







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
	return self;
}

- (void)OF_addObjectForReading: (id)object
{
	int fd = [object fileDescriptorForReading];

	if (fd < 0 || fd > INT_MAX - 1)
		@throw [OFOutOfRangeException exception];

#ifndef _WIN32
	if (fd >= FD_SETSIZE)
		@throw [OFOutOfRangeException exception];
#endif

	if (fd > _maxFD)
		_maxFD = fd;

	FD_SET(fd, &_readFDs);
}

- (void)OF_addObjectForWriting: (id)object
{
	int fd = [object fileDescriptorForWriting];

	if (fd < 0 || fd > INT_MAX - 1)
		@throw [OFOutOfRangeException exception];

#ifndef _WIN32
	if (fd >= FD_SETSIZE)
		@throw [OFOutOfRangeException exception];
#endif

	if (fd > _maxFD)
		_maxFD = fd;

	FD_SET(fd, &_writeFDs);
}

- (void)OF_removeObjectForReading: (id)object
{
	/* TODO: Adjust _maxFD */

	int fd = [object fileDescriptorForReading];

	if (fd < 0 || fd >= FD_SETSIZE)
		@throw [OFOutOfRangeException exception];

	FD_CLR(fd, &_readFDs);
}

- (void)OF_removeObjectForWriting: (id)object
{
	/* TODO: Adjust _maxFD */

	int fd = [object fileDescriptorForWriting];

	if (fd < 0 || fd >= FD_SETSIZE)
		@throw [OFOutOfRangeException exception];

	FD_CLR(fd, &_writeFDs);
}

- (void)observeForTimeInterval: (of_time_interval_t)timeInterval
{
173
174
175
176
177
178
179
180
181
182

183
184
185
186
187
188
189
190
191
192
193
194
195
196
197

198
199
200
201
202
203
204
205
206
#endif
	}

	objects = [_readObjects objects];
	count = [_readObjects count];

	for (i = 0; i < count; i++) {
		int fd = [objects[i] fileDescriptorForReading];

		pool = objc_autoreleasePoolPush();


		if (FD_ISSET(fd, &readFDs) && [_delegate respondsToSelector:
		    @selector(objectIsReadyForReading:)])
			[_delegate objectIsReadyForReading: objects[i]];

		objc_autoreleasePoolPop(pool);
	}

	objects = [_writeObjects objects];
	count = [_writeObjects count];

	for (i = 0; i < count; i++) {
		int fd = [objects[i] fileDescriptorForWriting];

		pool = objc_autoreleasePoolPush();


		if (FD_ISSET(fd, &writeFDs) && [_delegate respondsToSelector:
		    @selector(objectIsReadyForWriting:)])
			[_delegate objectIsReadyForWriting: objects[i]];

		objc_autoreleasePoolPop(pool);
	}
}
@end







|


>












|


>









173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
#endif
	}

	objects = [_readObjects objects];
	count = [_readObjects count];

	for (i = 0; i < count; i++) {
		int fd;

		pool = objc_autoreleasePoolPush();
		fd = [objects[i] fileDescriptorForReading];

		if (FD_ISSET(fd, &readFDs) && [_delegate respondsToSelector:
		    @selector(objectIsReadyForReading:)])
			[_delegate objectIsReadyForReading: objects[i]];

		objc_autoreleasePoolPop(pool);
	}

	objects = [_writeObjects objects];
	count = [_writeObjects count];

	for (i = 0; i < count; i++) {
		int fd;

		pool = objc_autoreleasePoolPush();
		fd = [objects[i] fileDescriptorForWriting];

		if (FD_ISSET(fd, &writeFDs) && [_delegate respondsToSelector:
		    @selector(objectIsReadyForWriting:)])
			[_delegate objectIsReadyForWriting: objects[i]];

		objc_autoreleasePoolPop(pool);
	}
}
@end