diff options
author | John Langford <jl@jl-desktop.(none)> | 2010-09-27 19:35:42 +0400 |
---|---|---|
committer | John Langford <jl@jl-desktop.(none)> | 2010-09-27 19:35:42 +0400 |
commit | f806871407bdfd25edd5abc2c1f7f32aa5dfda3c (patch) | |
tree | be4e78e57d3da00b85f368260b5a71e4151158d3 /parser.cc | |
parent | e8b3190a12677787103ce3c0eb0f50f2f190259c (diff) |
added daemon() call
Diffstat (limited to 'parser.cc')
-rw-r--r-- | parser.cc | 17 |
1 files changed, 11 insertions, 6 deletions
@@ -182,14 +182,14 @@ void parse_source_args(po::variables_map& vm, parser* par, bool quiet, size_t pa if (vm.count("daemon") || vm.count("multisource")) { - int daemon = socket(PF_INET, SOCK_STREAM, 0); - if (daemon < 0) { + int sock = socket(PF_INET, SOCK_STREAM, 0); + if (sock < 0) { cerr << "can't open socket!" << endl; exit(1); } int on = 1; - if (setsockopt(daemon, SOL_SOCKET, SO_REUSEADDR, (char*)&on, sizeof(on)) < 0) + if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (char*)&on, sizeof(on)) < 0) perror("setsockopt SO_REUSEADDR"); sockaddr_in address; @@ -200,17 +200,22 @@ void parse_source_args(po::variables_map& vm, parser* par, bool quiet, size_t pa port = vm["port"].as<size_t>(); address.sin_port = htons(port); - if (bind(daemon,(sockaddr*)&address, sizeof(address)) < 0) + if (bind(sock,(sockaddr*)&address, sizeof(address)) < 0) { cerr << "failure to bind!" << endl; exit(1); } + if (daemon(1,1)) + { + cerr << "failure to background!" << endl; + exit(1); + } int source_count = 1; if (vm.count("multisource")) source_count = vm["multisource"].as<size_t>(); - listen(daemon, source_count); + listen(sock, source_count); sockaddr_in client_address; socklen_t size = sizeof(client_address); @@ -220,7 +225,7 @@ void parse_source_args(po::variables_map& vm, parser* par, bool quiet, size_t pa { if (!global.quiet) cerr << "calling accept" << endl; - int f = accept(daemon,(sockaddr*)&client_address,&size); + int f = accept(sock,(sockaddr*)&client_address,&size); if (f < 0) { cerr << "bad client socket!" << endl; |