67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
|
#endif
#if !defined(OF_AMIGAOS) || defined(OF_MORPHOS) || !defined(OF_HAVE_THREADS)
static bool initSuccessful = false;
#endif
#ifdef OF_AMIGAOS
# if defined(OF_HAVE_THREADS) && !defined(OF_MORPHOS)
OFTLSKey of_socket_base_key;
# ifdef OF_AMIGAOS4
OFTLSKey of_socket_interface_key;
# endif
# else
struct Library *SocketBase;
# ifdef OF_AMIGAOS4
struct SocketIFace *ISocket = NULL;
# endif
# endif
#endif
#if defined(OF_HAVE_THREADS) && defined(OF_AMIGAOS) && !defined(OF_MORPHOS)
OF_CONSTRUCTOR()
{
if (OFTLSKeyNew(&of_socket_base_key) != 0)
@throw [OFInitializationFailedException exception];
# ifdef OF_AMIGAOS4
if (OFTLSKeyNew(&of_socket_interface_key) != 0)
@throw [OFInitializationFailedException exception];
# endif
}
#endif
#if !defined(OF_AMIGAOS) || defined(OF_MORPHOS) || !defined(OF_HAVE_THREADS)
static void
|
|
|
|
|
|
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
|
#endif
#if !defined(OF_AMIGAOS) || defined(OF_MORPHOS) || !defined(OF_HAVE_THREADS)
static bool initSuccessful = false;
#endif
#ifdef OF_AMIGAOS
# if defined(OF_HAVE_THREADS) && !defined(OF_MORPHOS)
OFTLSKey OFSocketBaseKey;
# ifdef OF_AMIGAOS4
OFTLSKey OFSocketInterfaceKey;
# endif
# else
struct Library *SocketBase;
# ifdef OF_AMIGAOS4
struct SocketIFace *ISocket = NULL;
# endif
# endif
#endif
#if defined(OF_HAVE_THREADS) && defined(OF_AMIGAOS) && !defined(OF_MORPHOS)
OF_CONSTRUCTOR()
{
if (OFTLSKeyNew(&OFSocketBaseKey) != 0)
@throw [OFInitializationFailedException exception];
# ifdef OF_AMIGAOS4
if (OFTLSKeyNew(&OFSocketInterfaceKey) != 0)
@throw [OFInitializationFailedException exception];
# endif
}
#endif
#if !defined(OF_AMIGAOS) || defined(OF_MORPHOS) || !defined(OF_HAVE_THREADS)
static void
|
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
|
if (SocketBase != NULL)
CloseLibrary(SocketBase);
# endif
}
#endif
bool
of_socket_init(void)
{
#if !defined(OF_AMIGAOS) || defined(OF_MORPHOS) || !defined(OF_HAVE_THREADS)
static OFOnceControl onceControl = OFOnceControlInitValue;
OFOnce(&onceControl, init);
return initSuccessful;
#else
struct Library *socketBase;
# ifdef OF_AMIGAOS4
struct SocketIFace *socketInterface;
# endif
# ifdef OF_AMIGAOS4
if ((socketInterface = OFTLSKeyGet(of_socket_interface_key)) != NULL)
# else
if ((socketBase = OFTLSKeyGet(of_socket_base_key)) != NULL)
# endif
return true;
if ((socketBase = OpenLibrary("bsdsocket.library", 4)) == NULL)
return false;
# ifdef OF_AMIGAOS4
if ((socketInterface = (struct SocketIFace *)
GetInterface(socketBase, "main", 1, NULL)) == NULL) {
CloseLibrary(socketBase);
return false;
}
# endif
if (OFTLSKeySet(of_socket_base_key, socketBase) != 0) {
CloseLibrary(socketBase);
# ifdef OF_AMIGAOS4
DropInterface((struct Interface *)socketInterface);
# endif
return false;
}
# ifdef OF_AMIGAOS4
if (OFTLSKeySet(of_socket_interface_key, socketInterface) != 0) {
CloseLibrary(socketBase);
DropInterface((struct Interface *)socketInterface);
return false;
}
# endif
return true;
#endif
}
#if defined(OF_HAVE_THREADS) && defined(OF_AMIGAOS) && !defined(OF_MORPHOS)
void
of_socket_deinit(void)
{
struct Library *socketBase = OFTLSKeyGet(of_socket_base_key);
# ifdef OF_AMIGAOS4
struct SocketIFace *socketInterface =
OFTLSKeyGet(of_socket_interface_key);
if (socketInterface != NULL)
DropInterface((struct Interface *)socketInterface);
# endif
if (socketBase != NULL)
CloseLibrary(socketBase);
}
#endif
int
of_socket_errno()
{
#if defined(OF_WINDOWS)
switch (WSAGetLastError()) {
case WSAEACCES:
return EACCES;
case WSAEADDRINUSE:
return EADDRINUSE;
|
|
|
|
|
|
|
|
|
<
|
|
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
|
if (SocketBase != NULL)
CloseLibrary(SocketBase);
# endif
}
#endif
bool
OFSocketInit(void)
{
#if !defined(OF_AMIGAOS) || defined(OF_MORPHOS) || !defined(OF_HAVE_THREADS)
static OFOnceControl onceControl = OFOnceControlInitValue;
OFOnce(&onceControl, init);
return initSuccessful;
#else
struct Library *socketBase;
# ifdef OF_AMIGAOS4
struct SocketIFace *socketInterface;
# endif
# ifdef OF_AMIGAOS4
if ((socketInterface = OFTLSKeyGet(OFSocketInterfaceKey)) != NULL)
# else
if ((socketBase = OFTLSKeyGet(OFSocketBaseKey)) != NULL)
# endif
return true;
if ((socketBase = OpenLibrary("bsdsocket.library", 4)) == NULL)
return false;
# ifdef OF_AMIGAOS4
if ((socketInterface = (struct SocketIFace *)
GetInterface(socketBase, "main", 1, NULL)) == NULL) {
CloseLibrary(socketBase);
return false;
}
# endif
if (OFTLSKeySet(OFSocketBaseKey, socketBase) != 0) {
CloseLibrary(socketBase);
# ifdef OF_AMIGAOS4
DropInterface((struct Interface *)socketInterface);
# endif
return false;
}
# ifdef OF_AMIGAOS4
if (OFTLSKeySet(OFSocketInterfaceKey, socketInterface) != 0) {
CloseLibrary(socketBase);
DropInterface((struct Interface *)socketInterface);
return false;
}
# endif
return true;
#endif
}
#if defined(OF_HAVE_THREADS) && defined(OF_AMIGAOS) && !defined(OF_MORPHOS)
void
OFSocketDeinit(void)
{
struct Library *socketBase = OFTLSKeyGet(OFSocketBaseKey);
# ifdef OF_AMIGAOS4
struct SocketIFace *socketInterface = OFTLSKeyGet(OFSocketInterfaceKey);
if (socketInterface != NULL)
DropInterface((struct Interface *)socketInterface);
# endif
if (socketBase != NULL)
CloseLibrary(socketBase);
}
#endif
int
OFSocketErrNo()
{
#if defined(OF_WINDOWS)
switch (WSAGetLastError()) {
case WSAEACCES:
return EACCES;
case WSAEADDRINUSE:
return EADDRINUSE;
|
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
|
#else
return errno;
#endif
}
#ifndef OF_WII
int
of_getsockname(OFSocketHandle sock, struct sockaddr *restrict addr,
socklen_t *restrict addrLen)
{
int ret;
# if defined(OF_HAVE_THREADS) && (!defined(OF_AMIGAOS) || defined(OF_MORPHOS))
[mutex lock];
# endif
|
|
|
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
|
#else
return errno;
#endif
}
#ifndef OF_WII
int
OFGetSockName(OFSocketHandle sock, struct sockaddr *restrict addr,
socklen_t *restrict addrLen)
{
int ret;
# if defined(OF_HAVE_THREADS) && (!defined(OF_AMIGAOS) || defined(OF_MORPHOS))
[mutex lock];
# endif
|