ObjFW  Diff

Differences From Artifact [3c38516b1b]:

  • File src/OFUDPSocket.m — part of check-in [62e2de30b9] at 2015-02-16 08:39:17 on branch trunk — Explicitly pass errno to exceptions

    The old behaviour where the exception would access errno directly on
    creation of the exception was very fragile. The two main problems with
    it were that sometimes it would pick up an errno even though none had
    been set and in other cases that when the exception was created errno
    had already been overridden.

    This also greatly increases errno handling on Win32, especially in
    conjunction with sockets. It can still be improved further, though. (user: js, size: 12842) [annotate] [blame] [check-ins using]

To Artifact [455c967f24]:


31
32
33
34
35
36
37
38
39

40
41
42
43
44
45
46
#import "OFInitializationFailedException.h"
#import "OFInvalidArgumentException.h"
#import "OFNotConnectedException.h"
#import "OFOutOfRangeException.h"
#import "OFReadFailedException.h"
#import "OFWriteFailedException.h"

#import "resolver.h"
#import "socket_helpers.h"


#ifdef __wii__
static uint16_t freePort = 65532;
#endif

#ifdef OF_HAVE_THREADS
@interface OFUDPSocket_ResolveThread: OFThread







|

>







31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#import "OFInitializationFailedException.h"
#import "OFInvalidArgumentException.h"
#import "OFNotConnectedException.h"
#import "OFOutOfRangeException.h"
#import "OFReadFailedException.h"
#import "OFWriteFailedException.h"

#import "socket.h"
#import "socket_helpers.h"
#import "resolver.h"

#ifdef __wii__
static uint16_t freePort = 65532;
#endif

#ifdef OF_HAVE_THREADS
@interface OFUDPSocket_ResolveThread: OFThread
430
431
432
433
434
435
436
437

438
439
440
441
442
443
444
	}

	if (port > 0)
		return port;

#ifndef __wii__
	addrLen = (socklen_t)sizeof(addr.storage);
	if (getsockname(_socket, (struct sockaddr*)&addr.storage, &addrLen)) {

		int errNo = of_socket_errno();

		close(_socket);
		_socket = INVALID_SOCKET;

		@throw [OFBindFailedException exceptionWithHost: host
							   port: port







|
>







431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
	}

	if (port > 0)
		return port;

#ifndef __wii__
	addrLen = (socklen_t)sizeof(addr.storage);
	if (of_getsockname(_socket, (struct sockaddr*)&addr.storage,
	    &addrLen) != 0) {
		int errNo = of_socket_errno();

		close(_socket);
		_socket = INVALID_SOCKET;

		@throw [OFBindFailedException exceptionWithHost: host
							   port: port