︙ | | | ︙ | |
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
#ifndef NSPROTO_SPX
# define NSPROTO_SPX 0
#endif
#define SPX_PACKET_TYPE 5
@interface OFSPXSocket ()
- (int)of_createSocketForAddress: (const of_socket_address_t *)address
errNo: (int *)errNo;
- (bool)of_connectSocketToAddress: (const of_socket_address_t *)address
errNo: (int *)errNo;
- (void)of_closeSocket;
@end
OF_DIRECT_MEMBERS
@interface OFSPXSocketAsyncConnectDelegate: OFObject <OFRunLoopConnectDelegate>
{
|
|
|
|
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
#ifndef NSPROTO_SPX
# define NSPROTO_SPX 0
#endif
#define SPX_PACKET_TYPE 5
@interface OFSPXSocket ()
- (int)of_createSocketForAddress: (const OFSocketAddress *)address
errNo: (int *)errNo;
- (bool)of_connectSocketToAddress: (const OFSocketAddress *)address
errNo: (int *)errNo;
- (void)of_closeSocket;
@end
OF_DIRECT_MEMBERS
@interface OFSPXSocketAsyncConnectDelegate: OFObject <OFRunLoopConnectDelegate>
{
|
︙ | | | ︙ | |
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
|
#endif
[super dealloc];
}
- (void)startWithRunLoopMode: (OFRunLoopMode)runLoopMode
{
of_socket_address_t address =
of_socket_address_ipx(_node, _network, _port);
id exception = nil;
int errNo;
if (![_socket of_createSocketForAddress: &address errNo: &errNo]) {
exception = [self of_connectionFailedExceptionForErrNo: errNo];
goto inform_delegate;
}
|
|
|
|
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
|
#endif
[super dealloc];
}
- (void)startWithRunLoopMode: (OFRunLoopMode)runLoopMode
{
OFSocketAddress address =
OFSocketAddressMakeIPX(_node, _network, _port);
id exception = nil;
int errNo;
if (![_socket of_createSocketForAddress: &address errNo: &errNo]) {
exception = [self of_connectionFailedExceptionForErrNo: errNo];
goto inform_delegate;
}
|
︙ | | | ︙ | |
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
|
errNo: errNo];
}
@end
@implementation OFSPXSocket
@dynamic delegate;
- (int)of_createSocketForAddress: (const of_socket_address_t *)address
errNo: (int *)errNo
{
#if SOCK_CLOEXEC == 0 && defined(HAVE_FCNTL) && defined(FD_CLOEXEC)
int flags;
#endif
if (_socket != INVALID_SOCKET)
|
|
|
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
|
errNo: errNo];
}
@end
@implementation OFSPXSocket
@dynamic delegate;
- (int)of_createSocketForAddress: (const OFSocketAddress *)address
errNo: (int *)errNo
{
#if SOCK_CLOEXEC == 0 && defined(HAVE_FCNTL) && defined(FD_CLOEXEC)
int flags;
#endif
if (_socket != INVALID_SOCKET)
|
︙ | | | ︙ | |
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
|
if ((flags = fcntl(_socket, F_GETFD, 0)) != -1)
fcntl(_socket, F_SETFD, flags | FD_CLOEXEC);
#endif
return true;
}
- (bool)of_connectSocketToAddress: (const of_socket_address_t *)address
errNo: (int *)errNo
{
if (_socket == INVALID_SOCKET)
@throw [OFNotOpenException exceptionWithObject: self];
if (connect(_socket, &address->sockaddr.sockaddr,
address->length) != 0) {
|
|
|
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
|
if ((flags = fcntl(_socket, F_GETFD, 0)) != -1)
fcntl(_socket, F_SETFD, flags | FD_CLOEXEC);
#endif
return true;
}
- (bool)of_connectSocketToAddress: (const OFSocketAddress *)address
errNo: (int *)errNo
{
if (_socket == INVALID_SOCKET)
@throw [OFNotOpenException exceptionWithObject: self];
if (connect(_socket, &address->sockaddr.sockaddr,
address->length) != 0) {
|
︙ | | | ︙ | |
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
|
_socket = INVALID_SOCKET;
}
- (void)connectToNode: (unsigned char [_Nonnull IPX_NODE_LEN])node
network: (uint32_t)network
port: (uint16_t)port
{
of_socket_address_t address =
of_socket_address_ipx(node, network, port);
int errNo;
if (![self of_createSocketForAddress: &address errNo: &errNo])
@throw [OFConnectionFailedException
exceptionWithNode: node
network: network
port: port
|
<
|
|
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
|
_socket = INVALID_SOCKET;
}
- (void)connectToNode: (unsigned char [_Nonnull IPX_NODE_LEN])node
network: (uint32_t)network
port: (uint16_t)port
{
OFSocketAddress address = OFSocketAddressMakeIPX(node, network, port);
int errNo;
if (![self of_createSocketForAddress: &address errNo: &errNo])
@throw [OFConnectionFailedException
exceptionWithNode: node
network: network
port: port
|
︙ | | | ︙ | |
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
|
block: block
] autorelease] startWithRunLoopMode: runLoopMode];
objc_autoreleasePoolPop(pool);
}
#endif
- (of_socket_address_t)bindToPort: (uint16_t)port
{
const unsigned char zeroNode[IPX_NODE_LEN] = { 0 };
of_socket_address_t address;
#if SOCK_CLOEXEC == 0 && defined(HAVE_FCNTL_H) && defined(FD_CLOEXEC)
int flags;
#endif
if (_socket != INVALID_SOCKET)
@throw [OFAlreadyConnectedException exceptionWithSocket: self];
address = of_socket_address_ipx(zeroNode, 0, port);
if ((_socket = socket(address.sockaddr.sockaddr.sa_family,
SOCK_SEQPACKET | SOCK_CLOEXEC, NSPROTO_SPX)) == INVALID_SOCKET)
@throw [OFBindFailedException
exceptionWithPort: port
packetType: SPX_PACKET_TYPE
socket: self
|
|
|
|
|
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
|
block: block
] autorelease] startWithRunLoopMode: runLoopMode];
objc_autoreleasePoolPop(pool);
}
#endif
- (OFSocketAddress)bindToPort: (uint16_t)port
{
const unsigned char zeroNode[IPX_NODE_LEN] = { 0 };
OFSocketAddress address;
#if SOCK_CLOEXEC == 0 && defined(HAVE_FCNTL_H) && defined(FD_CLOEXEC)
int flags;
#endif
if (_socket != INVALID_SOCKET)
@throw [OFAlreadyConnectedException exceptionWithSocket: self];
address = OFSocketAddressMakeIPX(zeroNode, 0, port);
if ((_socket = socket(address.sockaddr.sockaddr.sa_family,
SOCK_SEQPACKET | SOCK_CLOEXEC, NSPROTO_SPX)) == INVALID_SOCKET)
@throw [OFBindFailedException
exceptionWithPort: port
packetType: SPX_PACKET_TYPE
socket: self
|
︙ | | | ︙ | |
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
|
@throw [OFBindFailedException exceptionWithPort: port
packetType: SPX_PACKET_TYPE
socket: self
errNo: errNo];
}
memset(&address, 0, sizeof(address));
address.family = OF_SOCKET_ADDRESS_FAMILY_IPX;
address.length = (socklen_t)sizeof(address.sockaddr);
if (of_getsockname(_socket, &address.sockaddr.sockaddr,
&address.length) != 0) {
int errNo = of_socket_errno();
closesocket(_socket);
|
|
|
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
|
@throw [OFBindFailedException exceptionWithPort: port
packetType: SPX_PACKET_TYPE
socket: self
errNo: errNo];
}
memset(&address, 0, sizeof(address));
address.family = OFSocketAddressFamilyIPX;
address.length = (socklen_t)sizeof(address.sockaddr);
if (of_getsockname(_socket, &address.sockaddr.sockaddr,
&address.length) != 0) {
int errNo = of_socket_errno();
closesocket(_socket);
|
︙ | | | ︙ | |