ObjFW  Diff

Differences From Artifact [05982c597a]:

To Artifact [10e23bfd72]:

  • File src/OFStreamSocket.m — part of check-in [ffb91daffe] at 2013-06-11 23:33:16 on branch trunk — Initial sockets support for the Wii.

    Not functional yet due to bugs in the SDK.
    Bugs found so far:

    * Binding to port 0 fails instead of choosing a free port.
    * gethostbyname() does not work for IPs.
    * getsockname() is missing.
    * struct sockaddr_storage is missing.

    I have not decided yet whether I fix those bugs in the SDK (I already
    implemented getsockname() and added struct sockaddr_stroage and it seems
    to work) or if I work around them in ObjFW. This will mainly depend on
    how cooperative the developers of the Wii SDK are. (user: js, size: 3874) [annotate] [blame] [check-ins using]


32
33
34
35
36
37
38








39
40
41
42
43
44
45
46
47
48
49
50
51

52

53
54
55
56

57
58
59
60




61

62
63
64
65
66
67
68
#import "OFStreamSocket.h"

#import "OFInitializationFailedException.h"
#import "OFNotConnectedException.h"
#import "OFReadFailedException.h"
#import "OFSetOptionFailedException.h"
#import "OFWriteFailedException.h"









#ifndef INVALID_SOCKET
# define INVALID_SOCKET -1
#endif

#ifdef _WIN32
# define close(sock) closesocket(sock)
#endif

@implementation OFStreamSocket
#ifdef _WIN32
+ (void)initialize
{

	WSADATA wsa;


	if (self != [OFStreamSocket class])
		return;


	if (WSAStartup(MAKEWORD(2, 0), &wsa))
		@throw [OFInitializationFailedException
		    exceptionWithClass: self];
}




#endif


+ (instancetype)socket
{
	return [[[self alloc] init] autorelease];
}

- (bool)lowlevelIsAtEndOfStream







>
>
>
>
>
>
>
>










<


>

>




>



<
>
>
>
>

>







32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56

57
58
59
60
61
62
63
64
65
66
67
68
69

70
71
72
73
74
75
76
77
78
79
80
81
82
#import "OFStreamSocket.h"

#import "OFInitializationFailedException.h"
#import "OFNotConnectedException.h"
#import "OFReadFailedException.h"
#import "OFSetOptionFailedException.h"
#import "OFWriteFailedException.h"

#ifdef __wii__
# define BOOL OGC_BOOL
# include <network.h>
# undef BOOL
# define recv(sock, buf, len, flags) net_recv(sock, buf, len, flags)
# define send(sock, buf, len, flags) net_send(sock, buf, len, flags)
#endif

#ifndef INVALID_SOCKET
# define INVALID_SOCKET -1
#endif

#ifdef _WIN32
# define close(sock) closesocket(sock)
#endif

@implementation OFStreamSocket

+ (void)initialize
{
#ifdef _WIN32
	WSADATA wsa;
#endif

	if (self != [OFStreamSocket class])
		return;

#if defined(_WIN32)
	if (WSAStartup(MAKEWORD(2, 0), &wsa))
		@throw [OFInitializationFailedException
		    exceptionWithClass: self];

#elif defined(__wii__)
	if (net_init() < 0)
		@throw [OFInitializationFailedException
		    exceptionWithClass: self];
#endif
}

+ (instancetype)socket
{
	return [[[self alloc] init] autorelease];
}

- (bool)lowlevelIsAtEndOfStream