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