20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
#import "OFSPXSocket.h"
#import "OFRunLoop.h"
#import "OFRunLoop+Private.h"
#import "OFSocket.h"
#import "OFSocket+Private.h"
#import "OFAlreadyConnectedException.h"
#import "OFBindSocketFailedException.h"
#import "OFConnectionFailedException.h"
#import "OFNotOpenException.h"
#ifndef NSPROTO_SPX
# define NSPROTO_SPX 0
#endif
|
|
|
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
#import "OFSPXSocket.h"
#import "OFRunLoop.h"
#import "OFRunLoop+Private.h"
#import "OFSocket.h"
#import "OFSocket+Private.h"
#import "OFAlreadyConnectedException.h"
#import "OFBindIPXSocketFailedException.h"
#import "OFConnectionFailedException.h"
#import "OFNotOpenException.h"
#ifndef NSPROTO_SPX
# define NSPROTO_SPX 0
#endif
|
325
326
327
328
329
330
331
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
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
|
@throw [OFAlreadyConnectedException exceptionWithSocket: self];
address = OFSocketAddressMakeIPX(0, zeroNode, port);
if ((_socket = socket(address.sockaddr.ipx.sipx_family,
SOCK_SEQPACKET | SOCK_CLOEXEC, NSPROTO_SPX)) ==
OFInvalidSocketHandle)
@throw [OFBindSocketFailedException
exceptionWithPort: port
packetType: SPXPacketType
socket: self
errNo: OFSocketErrNo()];
_canBlock = true;
#if SOCK_CLOEXEC == 0 && defined(HAVE_FCNTL_H) && defined(FD_CLOEXEC)
if ((flags = fcntl(_socket, F_GETFD, 0)) != -1)
fcntl(_socket, F_SETFD, flags | FD_CLOEXEC);
#endif
if (bind(_socket, (struct sockaddr *)&address.sockaddr,
address.length) != 0) {
int errNo = OFSocketErrNo();
closesocket(_socket);
_socket = OFInvalidSocketHandle;
@throw [OFBindSocketFailedException
exceptionWithPort: port
packetType: SPXPacketType
socket: self
errNo: errNo];
}
memset(&address, 0, sizeof(address));
address.family = OFSocketAddressFamilyIPX;
address.length = (socklen_t)sizeof(address.sockaddr);
if (OFGetSockName(_socket, (struct sockaddr *)&address.sockaddr,
&address.length) != 0) {
int errNo = OFSocketErrNo();
closesocket(_socket);
_socket = OFInvalidSocketHandle;
@throw [OFBindSocketFailedException
exceptionWithPort: port
packetType: SPXPacketType
socket: self
errNo: errNo];
}
if (address.sockaddr.ipx.sipx_family != AF_IPX) {
closesocket(_socket);
_socket = OFInvalidSocketHandle;
@throw [OFBindSocketFailedException
exceptionWithPort: port
packetType: SPXPacketType
socket: self
errNo: EAFNOSUPPORT];
}
return address;
}
@end
|
|
|
|
|
|
325
326
327
328
329
330
331
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
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
|
@throw [OFAlreadyConnectedException exceptionWithSocket: self];
address = OFSocketAddressMakeIPX(0, zeroNode, port);
if ((_socket = socket(address.sockaddr.ipx.sipx_family,
SOCK_SEQPACKET | SOCK_CLOEXEC, NSPROTO_SPX)) ==
OFInvalidSocketHandle)
@throw [OFBindIPXSocketFailedException
exceptionWithPort: port
packetType: SPXPacketType
socket: self
errNo: OFSocketErrNo()];
_canBlock = true;
#if SOCK_CLOEXEC == 0 && defined(HAVE_FCNTL_H) && defined(FD_CLOEXEC)
if ((flags = fcntl(_socket, F_GETFD, 0)) != -1)
fcntl(_socket, F_SETFD, flags | FD_CLOEXEC);
#endif
if (bind(_socket, (struct sockaddr *)&address.sockaddr,
address.length) != 0) {
int errNo = OFSocketErrNo();
closesocket(_socket);
_socket = OFInvalidSocketHandle;
@throw [OFBindIPXSocketFailedException
exceptionWithPort: port
packetType: SPXPacketType
socket: self
errNo: errNo];
}
memset(&address, 0, sizeof(address));
address.family = OFSocketAddressFamilyIPX;
address.length = (socklen_t)sizeof(address.sockaddr);
if (OFGetSockName(_socket, (struct sockaddr *)&address.sockaddr,
&address.length) != 0) {
int errNo = OFSocketErrNo();
closesocket(_socket);
_socket = OFInvalidSocketHandle;
@throw [OFBindIPXSocketFailedException
exceptionWithPort: port
packetType: SPXPacketType
socket: self
errNo: errNo];
}
if (address.sockaddr.ipx.sipx_family != AF_IPX) {
closesocket(_socket);
_socket = OFInvalidSocketHandle;
@throw [OFBindIPXSocketFailedException
exceptionWithPort: port
packetType: SPXPacketType
socket: self
errNo: EAFNOSUPPORT];
}
return address;
}
@end
|