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
|
@try {
if (self.class == [OFDatagramSocket class]) {
[self doesNotRecognizeSelector: _cmd];
abort();
}
_socket = INVALID_SOCKET;
_canBlock = true;
} @catch (id e) {
[self release];
@throw e;
}
return self;
}
- (void)dealloc
{
if (_socket != INVALID_SOCKET)
[self close];
[super dealloc];
}
- (id)copy
{
|
|
|
|
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
|
@try {
if (self.class == [OFDatagramSocket class]) {
[self doesNotRecognizeSelector: _cmd];
abort();
}
_socket = OFInvalidSocketHandle;
_canBlock = true;
} @catch (id e) {
[self release];
@throw e;
}
return self;
}
- (void)dealloc
{
if (_socket != OFInvalidSocketHandle)
[self close];
[super dealloc];
}
- (id)copy
{
|
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
|
- (size_t)receiveIntoBuffer: (void *)buffer
length: (size_t)length
sender: (OFSocketAddress *)sender
{
ssize_t ret;
if (_socket == INVALID_SOCKET)
@throw [OFNotOpenException exceptionWithObject: self];
sender->length = (socklen_t)sizeof(sender->sockaddr);
#ifndef OF_WINDOWS
if ((ret = recvfrom(_socket, buffer, length, 0,
&sender->sockaddr.sockaddr, &sender->length)) < 0)
|
|
|
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
|
- (size_t)receiveIntoBuffer: (void *)buffer
length: (size_t)length
sender: (OFSocketAddress *)sender
{
ssize_t ret;
if (_socket == OFInvalidSocketHandle)
@throw [OFNotOpenException exceptionWithObject: self];
sender->length = (socklen_t)sizeof(sender->sockaddr);
#ifndef OF_WINDOWS
if ((ret = recvfrom(_socket, buffer, length, 0,
&sender->sockaddr.sockaddr, &sender->length)) < 0)
|
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
|
}
#endif
- (void)sendBuffer: (const void *)buffer
length: (size_t)length
receiver: (const OFSocketAddress *)receiver
{
if (_socket == INVALID_SOCKET)
@throw [OFNotOpenException exceptionWithObject: self];
#ifndef OF_WINDOWS
ssize_t bytesWritten;
if (length > SSIZE_MAX)
@throw [OFOutOfRangeException exception];
|
|
|
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
|
}
#endif
- (void)sendBuffer: (const void *)buffer
length: (size_t)length
receiver: (const OFSocketAddress *)receiver
{
if (_socket == OFInvalidSocketHandle)
@throw [OFNotOpenException exceptionWithObject: self];
#ifndef OF_WINDOWS
ssize_t bytesWritten;
if (length > SSIZE_MAX)
@throw [OFOutOfRangeException exception];
|
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
|
}
- (int)fileDescriptorForReading
{
#ifndef OF_WINDOWS
return _socket;
#else
if (_socket == INVALID_SOCKET)
return -1;
if (_socket > INT_MAX)
@throw [OFOutOfRangeException exception];
return (int)_socket;
#endif
}
- (int)fileDescriptorForWriting
{
#ifndef OF_WINDOWS
return _socket;
#else
if (_socket == INVALID_SOCKET)
return -1;
if (_socket > INT_MAX)
@throw [OFOutOfRangeException exception];
return (int)_socket;
#endif
}
- (void)close
{
if (_socket == INVALID_SOCKET)
@throw [OFNotOpenException exceptionWithObject: self];
closesocket(_socket);
_socket = INVALID_SOCKET;
}
@end
|
|
|
|
|
|
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
|
}
- (int)fileDescriptorForReading
{
#ifndef OF_WINDOWS
return _socket;
#else
if (_socket == OFInvalidSocketHandle)
return -1;
if (_socket > INT_MAX)
@throw [OFOutOfRangeException exception];
return (int)_socket;
#endif
}
- (int)fileDescriptorForWriting
{
#ifndef OF_WINDOWS
return _socket;
#else
if (_socket == OFInvalidSocketHandle)
return -1;
if (_socket > INT_MAX)
@throw [OFOutOfRangeException exception];
return (int)_socket;
#endif
}
- (void)close
{
if (_socket == OFInvalidSocketHandle)
@throw [OFNotOpenException exceptionWithObject: self];
closesocket(_socket);
_socket = OFInvalidSocketHandle;
}
@end
|