summaryrefslogtreecommitdiff
path: root/server/server_windows.cpp
blob: bbe0b735c16b9c2d5f71ac1cbe17311b5b68f6c9 (plain)
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
#ifdef WIN32
#include <Windows.h>
#pragma comment(lib, "ws2_32.lib")
#else
#include <unistd.h>
#include <sys/types.h> 
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netinet/in.h>
#endif

#include <cstdio>
#include <cstdlib>
#include <string>
#include <fstream>
#include <thread>
#include "server.hpp"

server::c_server g_server;

int main( ) {
	std::thread listen_thread;

	int result = g_server.init( );
	if( !result ) {
		// thread unsafe.
		listen_thread = std::thread( [ ]( ) { while( 1 ) { g_server.listen( ); } } );
		listen_thread.detach( );

		while( 1 ) {
			g_server.client_loop( );
			Sleep( 1 );
		}
	}
	else
		printf( "server init error (%d)\n", result );

	system( "pause" );
	return 0;
}