︙ | | | ︙ | |
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
#include <assert.h>
#import "OFStreamObserver.h"
#import "OFArray.h"
#import "OFDictionary.h"
#import "OFStream.h"
#import "OFDataArray.h"
#ifdef _WIN32
# import "OFTCPSocket.h"
#endif
#ifdef OF_HAVE_THREADS
# import "OFMutex.h"
#endif
#import "OFDate.h"
#ifdef HAVE_KQUEUE
|
|
|
|
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
#include <assert.h>
#import "OFStreamObserver.h"
#import "OFArray.h"
#import "OFDictionary.h"
#import "OFStream.h"
#import "OFDataArray.h"
#ifndef OF_HAVE_PIPE
# import "OFStreamSocket.h"
#endif
#ifdef OF_HAVE_THREADS
# import "OFMutex.h"
#endif
#import "OFDate.h"
#ifdef HAVE_KQUEUE
|
︙ | | | ︙ | |
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
124
125
126
|
#endif
- init
{
self = [super init];
@try {
#ifdef _WIN32
struct sockaddr_in cancelAddr2;
socklen_t cancelAddrLen;
#endif
_readStreams = [[OFMutableArray alloc] init];
_writeStreams = [[OFMutableArray alloc] init];
_queue = [[OFMutableArray alloc] init];
_queueInfo = [[OFDataArray alloc]
initWithItemSize: sizeof(int)];
_queueFDs = [[OFDataArray alloc] initWithItemSize: sizeof(int)];
#ifndef _WIN32
if (pipe(_cancelFD))
@throw [OFInitializationFailedException
exceptionWithClass: [self class]];
#else
/* Make sure WSAStartup has been called */
[OFTCPSocket class];
_cancelFD[0] = socket(AF_INET, SOCK_DGRAM, 0);
_cancelFD[1] = socket(AF_INET, SOCK_DGRAM, 0);
if (_cancelFD[0] == INVALID_SOCKET ||
_cancelFD[1] == INVALID_SOCKET)
@throw [OFInitializationFailedException
|
|
|
|
|
|
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
124
125
126
|
#endif
- init
{
self = [super init];
@try {
#ifndef OF_HAVE_PIPE
struct sockaddr_in cancelAddr2;
socklen_t cancelAddrLen;
#endif
_readStreams = [[OFMutableArray alloc] init];
_writeStreams = [[OFMutableArray alloc] init];
_queue = [[OFMutableArray alloc] init];
_queueInfo = [[OFDataArray alloc]
initWithItemSize: sizeof(int)];
_queueFDs = [[OFDataArray alloc] initWithItemSize: sizeof(int)];
#ifdef OF_HAVE_PIPE
if (pipe(_cancelFD))
@throw [OFInitializationFailedException
exceptionWithClass: [self class]];
#else
/* Make sure network has been initialized */
[OFStreamSocket class];
_cancelFD[0] = socket(AF_INET, SOCK_DGRAM, 0);
_cancelFD[1] = socket(AF_INET, SOCK_DGRAM, 0);
if (_cancelFD[0] == INVALID_SOCKET ||
_cancelFD[1] == INVALID_SOCKET)
@throw [OFInitializationFailedException
|
︙ | | | ︙ | |
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
|
if (bind(_cancelFD[0], (struct sockaddr*)&_cancelAddr,
sizeof(_cancelAddr)) || bind(_cancelFD[1],
(struct sockaddr*)&cancelAddr2, sizeof(cancelAddr2)))
@throw [OFInitializationFailedException
exceptionWithClass: [self class]];
cancelAddrLen = sizeof(_cancelAddr);
if (getsockname(_cancelFD[0], (struct sockaddr*)&_cancelAddr,
&cancelAddrLen))
@throw [OFInitializationFailedException
exceptionWithClass: [self class]];
#endif
_maxFD = _cancelFD[0];
|
<
|
134
135
136
137
138
139
140
141
142
143
144
145
146
147
|
if (bind(_cancelFD[0], (struct sockaddr*)&_cancelAddr,
sizeof(_cancelAddr)) || bind(_cancelFD[1],
(struct sockaddr*)&cancelAddr2, sizeof(cancelAddr2)))
@throw [OFInitializationFailedException
exceptionWithClass: [self class]];
cancelAddrLen = sizeof(_cancelAddr);
if (getsockname(_cancelFD[0], (struct sockaddr*)&_cancelAddr,
&cancelAddrLen))
@throw [OFInitializationFailedException
exceptionWithClass: [self class]];
#endif
_maxFD = _cancelFD[0];
|
︙ | | | ︙ | |
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
|
- (bool)observeUntilDate: (OFDate*)date
{
return [self observeForTimeInterval: [date timeIntervalSinceNow]];
}
- (void)cancel
{
#ifndef _WIN32
OF_ENSURE(write(_cancelFD[1], "", 1) > 0);
#else
OF_ENSURE(sendto(_cancelFD[1], "", 1, 0, (struct sockaddr*)&_cancelAddr,
sizeof(_cancelAddr)) > 0);
#endif
}
|
|
|
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
|
- (bool)observeUntilDate: (OFDate*)date
{
return [self observeForTimeInterval: [date timeIntervalSinceNow]];
}
- (void)cancel
{
#ifdef OF_HAVE_PIPE
OF_ENSURE(write(_cancelFD[1], "", 1) > 0);
#else
OF_ENSURE(sendto(_cancelFD[1], "", 1, 0, (struct sockaddr*)&_cancelAddr,
sizeof(_cancelAddr)) > 0);
#endif
}
|
︙ | | | ︙ | |