5648
|
1 |
/* $Id$ */
|
|
2 |
|
|
3 |
#ifdef ENABLE_NETWORK
|
|
4 |
|
|
5 |
#include "../../stdafx.h"
|
|
6 |
#include "../../debug.h"
|
|
7 |
#include "os_abstraction.h"
|
|
8 |
|
|
9 |
#ifdef __MORPHOS__
|
|
10 |
/* the library base is required here */
|
|
11 |
struct Library *SocketBase = NULL;
|
|
12 |
#endif
|
|
13 |
|
|
14 |
/**
|
|
15 |
* Initializes the network core (as that is needed for some platforms
|
|
16 |
*/
|
|
17 |
bool NetworkCoreInitialize(void)
|
|
18 |
{
|
|
19 |
#if defined(__MORPHOS__) || defined(__AMIGA__)
|
|
20 |
/*
|
|
21 |
* IMPORTANT NOTE: SocketBase needs to be initialized before we use _any_
|
|
22 |
* network related function, else: crash.
|
|
23 |
*/
|
|
24 |
DEBUG(net, 3, "[core] loading bsd socket library");
|
|
25 |
SocketBase = OpenLibrary("bsdsocket.library", 4);
|
|
26 |
if (SocketBase == NULL) {
|
|
27 |
DEBUG(net, 0, "[core] can't open bsdsocket.library version 4, network unavailable");
|
|
28 |
return false;
|
|
29 |
}
|
|
30 |
|
|
31 |
#if defined(__AMIGA__)
|
|
32 |
/* for usleep() implementation (only required for legacy AmigaOS builds) */
|
|
33 |
TimerPort = CreateMsgPort();
|
|
34 |
if (TimerPort != NULL) {
|
|
35 |
TimerRequest = (struct timerequest*)CreateIORequest(TimerPort, sizeof(struct timerequest);
|
|
36 |
if (TimerRequest != NULL) {
|
|
37 |
if (OpenDevice("timer.device", UNIT_MICROHZ, (struct IORequest*)TimerRequest, 0) == 0) {
|
|
38 |
TimerBase = TimerRequest->tr_node.io_Device;
|
|
39 |
if (TimerBase == NULL) {
|
|
40 |
/* free ressources... */
|
|
41 |
DEBUG(net, 0, "[core] can't initialize timer, network unavailable");
|
|
42 |
return false;
|
|
43 |
}
|
|
44 |
}
|
|
45 |
}
|
|
46 |
}
|
|
47 |
#endif // __AMIGA__
|
|
48 |
#endif // __MORPHOS__ / __AMIGA__
|
|
49 |
|
|
50 |
/* Let's load the network in windows */
|
|
51 |
#ifdef WIN32
|
|
52 |
{
|
|
53 |
WSADATA wsa;
|
|
54 |
DEBUG(net, 3, "[core] loading windows socket library");
|
|
55 |
if (WSAStartup(MAKEWORD(2, 0), &wsa) != 0) {
|
|
56 |
DEBUG(net, 0, "[core] WSAStartup failed, network unavailable");
|
|
57 |
return false;
|
|
58 |
}
|
|
59 |
}
|
|
60 |
#endif /* WIN32 */
|
|
61 |
|
|
62 |
return true;
|
|
63 |
}
|
|
64 |
|
|
65 |
/**
|
|
66 |
* Shuts down the network core (as that is needed for some platforms
|
|
67 |
*/
|
|
68 |
void NetworkCoreShutdown(void)
|
|
69 |
{
|
|
70 |
#if defined(__MORPHOS__) || defined(__AMIGA__)
|
|
71 |
/* free allocated resources */
|
|
72 |
#if defined(__AMIGA__)
|
|
73 |
if (TimerBase != NULL) CloseDevice((struct IORequest*)TimerRequest); // XXX This smells wrong
|
|
74 |
if (TimerRequest != NULL) DeleteIORequest(TimerRequest);
|
|
75 |
if (TimerPort != NULL) DeleteMsgPort(TimerPort);
|
|
76 |
#endif
|
|
77 |
|
|
78 |
if (SocketBase != NULL) CloseLibrary(SocketBase);
|
|
79 |
#endif
|
|
80 |
|
|
81 |
#if defined(WIN32)
|
|
82 |
WSACleanup();
|
|
83 |
#endif
|
|
84 |
}
|
|
85 |
|
|
86 |
#endif /* ENABLE_NETWORK */
|