File: server.cc

package info (click to toggle)
workflow 0.11.10-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,744 kB
  • sloc: cpp: 33,792; ansic: 9,393; makefile: 9; sh: 6
file content (46 lines) | stat: -rw-r--r-- 867 bytes parent folder | download
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
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <signal.h>
#include "workflow/WFFacilities.h"
#include "workflow/WFHttpServer.h"

static WFFacilities::WaitGroup wait_group(1);

void sig_handler(int signo)
{
	wait_group.done();
}

int main(int argc, const char *argv[])
{
	if (argc != 3)
	{
		fprintf(stderr, "USAGE: %s listen_fd pipe_fd\n", argv[0]);
		exit(1);
	}

	int listen_fd = atoi(argv[1]);
	int pipe_fd = atoi(argv[2]);

	signal(SIGUSR1, sig_handler);

	WFHttpServer server([](WFHttpTask *task) {
     	task->get_resp()->append_output_body("<html>Hello World!</html>");
	});

	if (server.serve(listen_fd) == 0)
	{
		wait_group.wait();
		server.shutdown();
		write(pipe_fd, "success", strlen("success"));
		server.wait_finish();
	}
	else
		write(pipe_fd, "failed ", strlen("failed "));

	close(pipe_fd);
	close(listen_fd);
    return 0;
}