Blame view

test/CSlimTestServer/Main.c 1.43 KB
fbe3c2bb   Benjamin Renard   First commit
1
2
3
4
5
6
7
8
9
10
11
12
#include <stdlib.h>
#include <stdio.h> /* defines FILENAME_MAX */
#include <string.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>

#include "CSlim/Slim.h"
#include "Com/SocketServer.h"
#include "CSlim/SlimConnectionHandler.h"
#include "Com/TcpComLink.h"

47539b45   Benjamin Renard   Remove some warni...
13
14
#define UNUSED(x) (void)(x)

fbe3c2bb   Benjamin Renard   First commit
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
Slim * slim;

int connection_handler(int socket)
{
	int result = 0;
	TcpComLink * comLink = TcpComLink_Create(socket);

  result = Slim_HandleConnection(slim, (void*)comLink, &TcpComLink_send, &TcpComLink_recv);

	TcpComLink_Destroy(comLink);

	return result;
}

int main(int ac, char** av)
{
47539b45   Benjamin Renard   Remove some warni...
31
32
	UNUSED(ac);
	UNUSED(av);
fbe3c2bb   Benjamin Renard   First commit
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
	// Put env
	char* lExecutablePath = "build/Debug/bin/";
	if ( !access("Release.flag", R_OK)) {
		lExecutablePath = "build/Release/bin/";
		setenv("BUILD_TYPE","Release",1);
	} else {
		setenv( "BUILD_TYPE","Debug",1);
	}
	const char* path = getenv("PATH");
	char _currentPath[FILENAME_MAX];
	getcwd(_currentPath,sizeof(_currentPath));
	printf("%s:%s\n%s",lExecutablePath,path,_currentPath);
	char* lNewPath = (char*) malloc(strlen(_currentPath)+strlen(path)+strlen(lExecutablePath)+3);
	sprintf(lNewPath,"%s/%s:%s",_currentPath,lExecutablePath,path);
	setenv( "PATH",lNewPath,1);

	// Server
	slim = Slim_Create();
	SocketServer* server = SocketServer_Create();
	SocketServer_register_handler(server, &connection_handler);

	int result = SocketServer_Run(server, av[1]);

	SocketServer_Destroy(server);
  Slim_Destroy(slim);
	return result;
}