ObjFW  Diff

Differences From Artifact [a588145b61]:

To Artifact [f1965656ad]:


20
21
22
23
24
25
26
27

28
29
30
31
32
33
34
20
21
22
23
24
25
26

27
28
29
30
31
32
33
34







-
+







#import "OFSPXStreamSocket.h"
#import "OFRunLoop.h"
#import "OFRunLoop+Private.h"
#import "OFSocket.h"
#import "OFSocket+Private.h"

#import "OFAlreadyConnectedException.h"
#import "OFBindFailedException.h"
#import "OFBindSocketFailedException.h"
#import "OFConnectionFailedException.h"
#import "OFNotOpenException.h"

#ifndef NSPROTO_SPX
# define NSPROTO_SPX 0
#endif

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
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
391







-
+



















+
-
-
-
-
+
+
+
+













+
-
-
-
-
+
+
+
+






+
-
-
-
-
+
+
+
+





	if (_socket != OFInvalidSocketHandle)
		@throw [OFAlreadyConnectedException exceptionWithSocket: self];

	address = OFSocketAddressMakeIPX(0, zeroNode, port);

	if ((_socket = socket(address.sockaddr.ipx.sipx_family,
	    SOCK_STREAM | SOCK_CLOEXEC, NSPROTO_SPX)) == OFInvalidSocketHandle)
		@throw [OFBindFailedException
		@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
		@throw [OFBindFailedException exceptionWithPort: port
						     packetType: SPXPacketType
							 socket: self
							  errNo: errNo];
		    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
		@throw [OFBindFailedException exceptionWithPort: port
						     packetType: SPXPacketType
							 socket: self
							  errNo: errNo];
		    exceptionWithPort: port
			   packetType: SPXPacketType
			       socket: self
				errNo: errNo];
	}

	if (address.sockaddr.ipx.sipx_family != AF_IPX) {
		closesocket(_socket);
		_socket = OFInvalidSocketHandle;

		@throw [OFBindSocketFailedException
		@throw [OFBindFailedException exceptionWithPort: port
						     packetType: SPXPacketType
							 socket: self
							  errNo: EAFNOSUPPORT];
		    exceptionWithPort: port
			   packetType: SPXPacketType
			       socket: self
				errNo: EAFNOSUPPORT];
	}

	return address;
}
@end