Main.c
1.38 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
#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"
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)
{
// 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;
}