ObjFW  Diff

Differences From Artifact [6084d13774]:

To Artifact [9c1fba606a]:


30
31
32
33
34
35
36

37
38
39
40
41
42
43
44
45





46
47
48

49
50
51
52
53
54


55
56



57
58
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
#include <sys/time.h>

#import "OFKernelEventObserver.h"
#import "OFKernelEventObserver+Private.h"
#import "OFKernelEventObserver_select.h"
#import "OFArray.h"


#import "OFObserveFailedException.h"
#import "OFOutOfRangeException.h"

#import "socket_helpers.h"

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






	FD_ZERO(&_readFDs);
	FD_ZERO(&_writeFDs);


	FD_SET(_cancelFD[0], &_readFDs);

	return self;
}



- (void)OF_addFileDescriptorForReading: (int)fd
{



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




	FD_SET(fd, &_readFDs);
}



- (void)OF_addFileDescriptorForWriting: (int)fd
{



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




	FD_SET(fd, &_writeFDs);
}





- (void)OF_removeFileDescriptorForReading: (int)fd
{
	if (fd >= FD_SETSIZE)
		@throw [OFOutOfRangeException exception];

	FD_CLR(fd, &_readFDs);
}





- (void)OF_removeFileDescriptorForWriting: (int)fd
{
	if (fd >= FD_SETSIZE)
		@throw [OFOutOfRangeException exception];

	FD_CLR(fd, &_writeFDs);
}

- (bool)observeForTimeInterval: (of_time_interval_t)timeInterval







>









>
>
>
>
>



>

|




>
>
|
|
>
>
>




>
>
>




>
>
|
|
>
>
>




>
>
>




>
>
>
>
|
|






>
>
>
>
|
|







30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
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
#include <sys/time.h>

#import "OFKernelEventObserver.h"
#import "OFKernelEventObserver+Private.h"
#import "OFKernelEventObserver_select.h"
#import "OFArray.h"

#import "OFInitializationFailedException.h"
#import "OFObserveFailedException.h"
#import "OFOutOfRangeException.h"

#import "socket_helpers.h"

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

#ifndef _WIN32
	if (_cancelFD[0] >= FD_SETSIZE)
		@throw [OFInitializationFailedException exception];
#endif

	FD_ZERO(&_readFDs);
	FD_ZERO(&_writeFDs);
	FD_SET(_cancelFD[0], &_readFDs);

	_maxFD = _cancelFD[0];

	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);
}

- (bool)observeForTimeInterval: (of_time_interval_t)timeInterval
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
#ifndef _WIN32
	timeout.tv_sec = (time_t)timeInterval;
#else
	timeout.tv_sec = (long)timeInterval;
#endif
	timeout.tv_usec = (int)lrint((timeInterval - timeout.tv_sec) * 1000);

	events = select((int)_maxFD + 1, &readFDs, &writeFDs, NULL,
	    (timeInterval != -1 ? &timeout : NULL));

	if (events < 0)
		@throw [OFObserveFailedException exceptionWithObserver: self
								 errNo: errno];

	if (events == 0)







|







155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
#ifndef _WIN32
	timeout.tv_sec = (time_t)timeInterval;
#else
	timeout.tv_sec = (long)timeInterval;
#endif
	timeout.tv_usec = (int)lrint((timeInterval - timeout.tv_sec) * 1000);

	events = select(_maxFD + 1, &readFDs, &writeFDs, NULL,
	    (timeInterval != -1 ? &timeout : NULL));

	if (events < 0)
		@throw [OFObserveFailedException exceptionWithObserver: self
								 errNo: errno];

	if (events == 0)