︙ | | | ︙ | |
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
@synthesize listening = _listening, delegate = _delegate;
+ (void)initialize
{
if (self != [OFSequencedPacketSocket class])
return;
if (!of_socket_init())
@throw [OFInitializationFailedException
exceptionWithClass: self];
}
+ (instancetype)socket
{
return [[[self alloc] init] autorelease];
|
|
|
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
@synthesize listening = _listening, delegate = _delegate;
+ (void)initialize
{
if (self != [OFSequencedPacketSocket class])
return;
if (!OFSocketInit())
@throw [OFInitializationFailedException
exceptionWithClass: self];
}
+ (instancetype)socket
{
return [[[self alloc] init] autorelease];
|
︙ | | | ︙ | |
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
|
- (int)of_socketError
{
int errNo;
socklen_t len = sizeof(errNo);
if (getsockopt(_socket, SOL_SOCKET, SO_ERROR, (char *)&errNo,
&len) != 0)
return of_socket_errno();
return errNo;
}
#endif
- (id)copy
{
|
|
|
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
|
- (int)of_socketError
{
int errNo;
socklen_t len = sizeof(errNo);
if (getsockopt(_socket, SOL_SOCKET, SO_ERROR, (char *)&errNo,
&len) != 0)
return OFSocketErrNo();
return errNo;
}
#endif
- (id)copy
{
|
︙ | | | ︙ | |
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
|
_canBlock = canBlock;
#elif defined(OF_WINDOWS)
u_long v = canBlock;
if (ioctlsocket(_socket, FIONBIO, &v) == SOCKET_ERROR)
@throw [OFSetOptionFailedException
exceptionWithObject: self
errNo: of_socket_errno()];
_canBlock = canBlock;
#else
OF_UNRECOGNIZED_SELECTOR
#endif
}
- (size_t)receiveIntoBuffer: (void *)buffer length: (size_t)length
{
ssize_t ret;
if (_socket == INVALID_SOCKET)
@throw [OFNotOpenException exceptionWithObject: self];
#ifndef OF_WINDOWS
if ((ret = recv(_socket, buffer, length, 0)) < 0)
@throw [OFReadFailedException
exceptionWithObject: self
requestedLength: length
errNo: of_socket_errno()];
#else
if (length > INT_MAX)
@throw [OFOutOfRangeException exception];
if ((ret = recv(_socket, buffer, (int)length, 0)) < 0)
@throw [OFReadFailedException
exceptionWithObject: self
requestedLength: length
errNo: of_socket_errno()];
#endif
return ret;
}
- (void)asyncReceiveIntoBuffer: (void *)buffer length: (size_t)length
{
|
|
|
|
|
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
|
_canBlock = canBlock;
#elif defined(OF_WINDOWS)
u_long v = canBlock;
if (ioctlsocket(_socket, FIONBIO, &v) == SOCKET_ERROR)
@throw [OFSetOptionFailedException
exceptionWithObject: self
errNo: OFSocketErrNo()];
_canBlock = canBlock;
#else
OF_UNRECOGNIZED_SELECTOR
#endif
}
- (size_t)receiveIntoBuffer: (void *)buffer length: (size_t)length
{
ssize_t ret;
if (_socket == INVALID_SOCKET)
@throw [OFNotOpenException exceptionWithObject: self];
#ifndef OF_WINDOWS
if ((ret = recv(_socket, buffer, length, 0)) < 0)
@throw [OFReadFailedException
exceptionWithObject: self
requestedLength: length
errNo: OFSocketErrNo()];
#else
if (length > INT_MAX)
@throw [OFOutOfRangeException exception];
if ((ret = recv(_socket, buffer, (int)length, 0)) < 0)
@throw [OFReadFailedException
exceptionWithObject: self
requestedLength: length
errNo: OFSocketErrNo()];
#endif
return ret;
}
- (void)asyncReceiveIntoBuffer: (void *)buffer length: (size_t)length
{
|
︙ | | | ︙ | |
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
|
@throw [OFOutOfRangeException exception];
if ((bytesWritten = send(_socket, (void *)buffer, length, 0)) < 0)
@throw [OFWriteFailedException
exceptionWithObject: self
requestedLength: length
bytesWritten: 0
errNo: of_socket_errno()];
#else
int bytesWritten;
if (length > INT_MAX)
@throw [OFOutOfRangeException exception];
if ((bytesWritten = send(_socket, buffer, (int)length, 0)) < 0)
@throw [OFWriteFailedException
exceptionWithObject: self
requestedLength: length
bytesWritten: 0
errNo: of_socket_errno()];
#endif
if ((size_t)bytesWritten != length)
@throw [OFWriteFailedException exceptionWithObject: self
requestedLength: length
bytesWritten: bytesWritten
errNo: 0];
|
|
|
|
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
|
@throw [OFOutOfRangeException exception];
if ((bytesWritten = send(_socket, (void *)buffer, length, 0)) < 0)
@throw [OFWriteFailedException
exceptionWithObject: self
requestedLength: length
bytesWritten: 0
errNo: OFSocketErrNo()];
#else
int bytesWritten;
if (length > INT_MAX)
@throw [OFOutOfRangeException exception];
if ((bytesWritten = send(_socket, buffer, (int)length, 0)) < 0)
@throw [OFWriteFailedException
exceptionWithObject: self
requestedLength: length
bytesWritten: 0
errNo: OFSocketErrNo()];
#endif
if ((size_t)bytesWritten != length)
@throw [OFWriteFailedException exceptionWithObject: self
requestedLength: length
bytesWritten: bytesWritten
errNo: 0];
|
︙ | | | ︙ | |
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
|
if (_socket == INVALID_SOCKET)
@throw [OFNotOpenException exceptionWithObject: self];
if (listen(_socket, backlog) == -1)
@throw [OFListenFailedException
exceptionWithSocket: self
backlog: backlog
errNo: of_socket_errno()];
_listening = true;
}
- (instancetype)accept
{
OFSequencedPacketSocket *client =
|
|
|
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
|
if (_socket == INVALID_SOCKET)
@throw [OFNotOpenException exceptionWithObject: self];
if (listen(_socket, backlog) == -1)
@throw [OFListenFailedException
exceptionWithSocket: self
backlog: backlog
errNo: OFSocketErrNo()];
_listening = true;
}
- (instancetype)accept
{
OFSequencedPacketSocket *client =
|
︙ | | | ︙ | |
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
|
#if defined(HAVE_PACCEPT) && defined(SOCK_CLOEXEC)
if ((client->_socket = paccept(_socket,
&client->_remoteAddress.sockaddr.sockaddr,
&client->_remoteAddress.length, NULL, SOCK_CLOEXEC)) ==
INVALID_SOCKET)
@throw [OFAcceptFailedException
exceptionWithSocket: self
errNo: of_socket_errno()];
#elif defined(HAVE_ACCEPT4) && defined(SOCK_CLOEXEC)
if ((client->_socket = accept4(_socket,
&client->_remoteAddress.sockaddr.sockaddr,
&client->_remoteAddress.length, SOCK_CLOEXEC)) == INVALID_SOCKET)
@throw [OFAcceptFailedException
exceptionWithSocket: self
errNo: of_socket_errno()];
#else
if ((client->_socket = accept(_socket,
&client->_remoteAddress.sockaddr.sockaddr,
&client->_remoteAddress.length)) == INVALID_SOCKET)
@throw [OFAcceptFailedException
exceptionWithSocket: self
errNo: of_socket_errno()];
# if defined(HAVE_FCNTL) && defined(FD_CLOEXEC)
if ((flags = fcntl(client->_socket, F_GETFD, 0)) != -1)
fcntl(client->_socket, F_SETFD, flags | FD_CLOEXEC);
# endif
#endif
|
|
|
|
|
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
|
#if defined(HAVE_PACCEPT) && defined(SOCK_CLOEXEC)
if ((client->_socket = paccept(_socket,
&client->_remoteAddress.sockaddr.sockaddr,
&client->_remoteAddress.length, NULL, SOCK_CLOEXEC)) ==
INVALID_SOCKET)
@throw [OFAcceptFailedException
exceptionWithSocket: self
errNo: OFSocketErrNo()];
#elif defined(HAVE_ACCEPT4) && defined(SOCK_CLOEXEC)
if ((client->_socket = accept4(_socket,
&client->_remoteAddress.sockaddr.sockaddr,
&client->_remoteAddress.length, SOCK_CLOEXEC)) == INVALID_SOCKET)
@throw [OFAcceptFailedException
exceptionWithSocket: self
errNo: OFSocketErrNo()];
#else
if ((client->_socket = accept(_socket,
&client->_remoteAddress.sockaddr.sockaddr,
&client->_remoteAddress.length)) == INVALID_SOCKET)
@throw [OFAcceptFailedException
exceptionWithSocket: self
errNo: OFSocketErrNo()];
# if defined(HAVE_FCNTL) && defined(FD_CLOEXEC)
if ((flags = fcntl(client->_socket, F_GETFD, 0)) != -1)
fcntl(client->_socket, F_SETFD, flags | FD_CLOEXEC);
# endif
#endif
|
︙ | | | ︙ | |