forked from moai/moai-dev
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathServerHost.cpp
More file actions
78 lines (61 loc) · 1.58 KB
/
Copy pathServerHost.cpp
File metadata and controls
78 lines (61 loc) · 1.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
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
#include <moai-core/host.h>
#include <host-modules/aku_modules.h>
#include <host-sdl/SDLHost.h>
#ifdef _WIN32
#include <windows.h>
#define sleep(x) Sleep((x) * 1000)
#else
#include <unistd.h>
#endif
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include <string.h>
#include <errno.h>
#include <limits.h>
#include <stddef.h>
#include <stdarg.h>
#include <ctype.h>
static int sExitFlag = 0;
//----------------------------------------------------------------//
static void signal_handler ( int sig_num ) {
sExitFlag = sig_num;
}
//----------------------------------------------------------------//
static void die ( const char *fmt, ... ) {
va_list ap;
char msg [ 200 ];
va_start ( ap, fmt );
vsnprintf ( msg, sizeof ( msg ), fmt, ap );
va_end ( ap );
exit ( EXIT_FAILURE );
}
//----------------------------------------------------------------//
int main ( int argc, char *argv []) {
AKUAppInitialize ();
AKUModulesAppInitialize ();
AKUCreateContext ();
AKUModulesContextInitialize ();
// Setup signal handler: quit on Ctrl-C
signal ( SIGTERM, signal_handler );
signal ( SIGINT, signal_handler );
AKUSetArgv ( argv );
for ( int i = 1; i < argc; ++i ) {
char* arg = argv [ i ];
if ( strcmp( arg, "-s" ) == 0 && ++i < argc ) {
AKURunString ( argv [ i ]);
}
else {
AKURunScript ( arg );
}
}
while ( sExitFlag == 0 ) {
sleep ( 1 );
}
printf ( "Exiting on signal %d, waiting for all threads to finish...", sExitFlag );
fflush ( stdout );
AKUModulesAppFinalize ();
AKUAppFinalize ();
printf ( "%s", " done.\n" );
return EXIT_SUCCESS;
}