-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtestsvr.cpp
More file actions
executable file
·83 lines (73 loc) · 1.62 KB
/
testsvr.cpp
File metadata and controls
executable file
·83 lines (73 loc) · 1.62 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
79
80
81
82
#if defined(USE_SOCKET)
#include "socket_ipc_svr.h"
#elif defined(USE_BOOST)
#include "boost_ipc_svr.h"
#elif defined(USE_SHMEM)
#include "shmem_ipc_svr.h"
#elif defined(USE_PTY)
#include "pty_ipc_svr.h"
#else
#include "stdio_ipc_svr.h"
#endif
#include <stdio.h>
#include <string>
#include "stringutils.h"
#include "vectorutils.h"
#include "util/HiresTimer.h"
int g_ctrlcpressed= 0;
void handlectrlc(int sig)
{
fprintf(stderr, "ctrl-c pressed\n");
if (g_ctrlcpressed++ > 2)
signal(sig, SIG_DFL);
}
void do_server(int argc, char**argv)
{
#if defined(USE_SOCKET)
socket_ipc_server _ipc;
#elif defined(USE_BOOST)
boost_ipc_server _ipc;
#elif defined(USE_SHMEM)
shmem_ipc_server _ipc;
#elif defined(USE_PTY)
if (argc!=2) {
fprintf(stderr, "Usage: testptysvr [ptydevname]\n");
return;
}
pty_ipc_server _ipc(argv[1]);
#else
stdio_ipc_server _ipc(STDOUT_FILENO,STDIN_FILENO);
#endif
while (!g_ctrlcpressed)
{
DWORD s[2];
if (!_ipc.read(s, sizeof(s)))
break;
ByteVector req(s[0]-8);
if (s[0]>0x100000) {
fprintf(stderr, "svr: %08x %08x\n", s[0], s[1]);
break;
}
if (g_ctrlcpressed)
break;
if (!_ipc.read(&req[0], req.size()))
break;
ByteVector res(s[1]);
if (g_ctrlcpressed)
break;
if (!_ipc.write(&res[0], res.size()))
break;
}
}
int main(int argc,char**argv)
{
signal(SIGINT, handlectrlc);
try {
do_server(argc, argv);
}
catch(...)
{
fprintf(stderr, "EXCEPTION\n");
}
return 0;
}