Differences From Artifact [2f5d16033d]:
- File
src/socket.m
— part of check-in
[5358e9ea6a]
at
2019-08-01 20:14:35
on branch trunk
— Split threading.[hm] into multiple files
This allows the runtime to only link against the parts it needs, without
pulling in unnecessary parts like thread spawning, TLS and conditions. (user: js, size: 14637) [annotate] [blame] [check-ins using]
To Artifact [54314146cb]:
- File src/socket.m — part of check-in [3dec8ecf2e] at 2019-08-09 23:44:51 on branch trunk — Support sockets on AmigaOS 3 (user: js, size: 15355) [annotate] [blame] [check-ins using]
| ︙ | ︙ | |||
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 "socket.h"
#import "socket_helpers.h"
#ifdef OF_HAVE_THREADS
# include "mutex.h"
#endif
#include "once.h"
#ifdef OF_NINTENDO_3DS
# include <3ds/types.h>
# include <3ds/services/soc.h>
#endif
#ifdef OF_HAVE_THREADS
static of_mutex_t mutex;
#endif
static bool initSuccessful = false;
static void
init(void)
{
#if defined(OF_WINDOWS)
WSADATA wsa;
if (WSAStartup(MAKEWORD(2, 0), &wsa))
return;
#elif defined(OF_WII)
if (net_init() < 0)
return;
#elif defined(OF_NINTENDO_3DS)
void *ctx;
if ((ctx = memalign(0x1000, 0x100000)) == NULL)
| > > > > > > > > > > > > > > > > > > > > > > | 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 83 84 85 86 87 88 89 90 |
#import "socket.h"
#import "socket_helpers.h"
#ifdef OF_HAVE_THREADS
# include "mutex.h"
#endif
#include "once.h"
#ifdef OF_AMIGAOS
# include <proto/exec.h>
#endif
#ifdef OF_NINTENDO_3DS
# include <3ds/types.h>
# include <3ds/services/soc.h>
#endif
#ifdef OF_HAVE_THREADS
static of_mutex_t mutex;
#endif
#ifdef OF_AMIGAOS
/* TODO: Support multiple threads */
struct Library *SocketBase;
# ifdef OF_AMIGAOS4
struct SocketIFace *ISocket = NULL;
# endif
#endif
static bool initSuccessful = false;
static void
init(void)
{
#if defined(OF_WINDOWS)
WSADATA wsa;
if (WSAStartup(MAKEWORD(2, 0), &wsa))
return;
#elif defined(OF_AMIGAOS)
if ((SocketBase = OpenLibrary("bsdsocket.library", 4)) == NULL)
return;
# ifdef OF_AMIGAOS4
if ((ISocket = (struct SocketIFace *)
GetInterface(SocketBase, "main", 1, NULL)) == NULL) {
CloseLibrary(SocketBase);
return;
}
# endif
#elif defined(OF_WII)
if (net_init() < 0)
return;
#elif defined(OF_NINTENDO_3DS)
void *ctx;
if ((ctx = memalign(0x1000, 0x100000)) == NULL)
|
| ︙ | ︙ | |||
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
return;
# endif
#endif
initSuccessful = true;
}
bool
of_socket_init()
{
static of_once_t onceControl = OF_ONCE_INIT;
of_once(&onceControl, init);
return initSuccessful;
}
int
of_socket_errno()
{
| > > > > > > > > > > > > > | < < | 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 |
return;
# endif
#endif
initSuccessful = true;
}
#ifdef OF_AMIGAOS
OF_DESTRUCTOR()
{
# ifdef OF_AMIGAOS4
if (ISocket != NULL)
DropInterface((struct Interface *)ISocket);
# endif
if (SocketBase != NULL)
CloseLibrary(SocketBase);
}
#endif
bool
of_socket_init()
{
static of_once_t onceControl = OF_ONCE_INIT;
of_once(&onceControl, init);
return initSuccessful;
}
int
of_socket_errno()
{
#if defined(OF_WINDOWS)
switch (WSAGetLastError()) {
case WSAEACCES:
return EACCES;
case WSAEADDRINUSE:
return EADDRINUSE;
case WSAEADDRNOTAVAIL:
return EADDRNOTAVAIL;
|
| ︙ | ︙ | |||
188 189 190 191 192 193 194 195 196 197 198 199 200 201 |
case WSAEUSERS:
return EUSERS;
case WSAEWOULDBLOCK:
return EWOULDBLOCK;
}
return 0;
#endif
}
#ifndef OF_WII
int
of_getsockname(of_socket_t sock, struct sockaddr *restrict addr,
socklen_t *restrict addrLen)
| > > > > | 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 |
case WSAEUSERS:
return EUSERS;
case WSAEWOULDBLOCK:
return EWOULDBLOCK;
}
return 0;
#elif defined(OF_AMIGAOS)
return Errno();
#else
return errno;
#endif
}
#ifndef OF_WII
int
of_getsockname(of_socket_t sock, struct sockaddr *restrict addr,
socklen_t *restrict addrLen)
|
| ︙ | ︙ |