ObjFW  Diff

Differences From Artifact [ac3c9446ae]:

To Artifact [0df0a2e4f0]:


12
13
14
15
16
17
18

19
20
21
22
23
24
25
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26







+







 * Public License, either version 2 or 3, which can be found in the file
 * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this
 * file.
 */

#include "config.h"

#include <math.h>
#include <unistd.h>
#include <errno.h>

#include <assert.h>

#include <sys/types.h>
#include <sys/event.h>
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
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







-
+


-
+



-
-
+
+












-
+







{
	struct kevent event;

	EV_SET(&event, fd, EVFILT_WRITE, EV_DELETE, 0, 0, 0);
	[_changeList addItem: &event];
}

- (bool)observeWithTimeout: (double)timeout
- (bool)observeForTimeInterval: (double)timeInterval
{
	void *pool = objc_autoreleasePoolPush();
	struct timespec timespec;
	struct timespec timeout;
	struct kevent eventList[EVENTLIST_SIZE];
	int i, events, realEvents = 0;

	timespec.tv_sec = (time_t)timeout;
	timespec.tv_nsec = (long)((timeout - timespec.tv_sec) * 1000000000);
	timeout.tv_sec = (time_t)timeInterval;
	timeout.tv_nsec = lrint((timeInterval - timeout.tv_sec) * 1000000000);

	[self OF_processQueue];

	if ([self OF_processCache]) {
		objc_autoreleasePoolPop(pool);
		return true;
	}

	objc_autoreleasePoolPop(pool);

	events = kevent(_kernelQueue, [_changeList items],
	    (int)[_changeList count], eventList, EVENTLIST_SIZE,
	    (timeout == -1 ? NULL : &timespec));
	    (timeInterval == -1 ? NULL : &timeout));

	if (events < 0)
		return false;

	[_changeList removeAllItems];

	if (events == 0)