mirror of
https://github.com/boostorg/asio.git
synced 2026-01-28 18:52:09 +00:00
........ r43377 | chris_kohlhoff | 2008-02-23 09:43:54 +1100 (Sat, 23 Feb 2008) | 2 lines Use the correct vector of timer queues when dispatching timers. ........ r43437 | chris_kohlhoff | 2008-02-29 23:57:57 +1100 (Fri, 29 Feb 2008) | 2 lines Add missing tie(). ........ r43469 | chris_kohlhoff | 2008-03-04 00:21:05 +1100 (Tue, 04 Mar 2008) | 4 lines Disable use of CancelIo by default, due to the possibility of silent failure on some system configurations. Swallow error returned by CancelIoEx if there are no operations to be cancelled. ........ r43470 | chris_kohlhoff | 2008-03-04 00:27:06 +1100 (Tue, 04 Mar 2008) | 2 lines Add missing 'boost_' prefix to helper namespace. ........ r43471 | chris_kohlhoff | 2008-03-04 00:36:35 +1100 (Tue, 04 Mar 2008) | 2 lines Regenerate documentation. ........ r43472 | chris_kohlhoff | 2008-03-04 01:05:35 +1100 (Tue, 04 Mar 2008) | 1 line Update copyright notices. ........ r43473 | chris_kohlhoff | 2008-03-04 01:13:01 +1100 (Tue, 04 Mar 2008) | 2 lines Update copyright notices. ........ r43569 | chris_kohlhoff | 2008-03-13 00:25:49 +1100 (Thu, 13 Mar 2008) | 4 lines Revert to having the windows-bug workaround (short timeout on GetQueuedCompletionStatus) on all threads as there are still scenarios where threads can get stuck indefinitely. ........ [SVN r43571]
76 lines
1.9 KiB
C++
76 lines
1.9 KiB
C++
//
|
|
// posix_main.cpp
|
|
// ~~~~~~~~~~~~~~
|
|
//
|
|
// Copyright (c) 2003-2008 Christopher M. Kohlhoff (chris at kohlhoff dot com)
|
|
//
|
|
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
|
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
|
//
|
|
|
|
#include <iostream>
|
|
#include <string>
|
|
#include <boost/asio.hpp>
|
|
#include <boost/thread.hpp>
|
|
#include <boost/bind.hpp>
|
|
#include <boost/lexical_cast.hpp>
|
|
#include "server.hpp"
|
|
|
|
#if !defined(_WIN32)
|
|
|
|
#include <pthread.h>
|
|
#include <signal.h>
|
|
|
|
int main(int argc, char* argv[])
|
|
{
|
|
try
|
|
{
|
|
// Check command line arguments.
|
|
if (argc != 5)
|
|
{
|
|
std::cerr << "Usage: http_server <address> <port> <threads> <doc_root>\n";
|
|
std::cerr << " For IPv4, try:\n";
|
|
std::cerr << " receiver 0.0.0.0 80 1 .\n";
|
|
std::cerr << " For IPv6, try:\n";
|
|
std::cerr << " receiver 0::0 80 1 .\n";
|
|
return 1;
|
|
}
|
|
|
|
// Block all signals for background thread.
|
|
sigset_t new_mask;
|
|
sigfillset(&new_mask);
|
|
sigset_t old_mask;
|
|
pthread_sigmask(SIG_BLOCK, &new_mask, &old_mask);
|
|
|
|
// Run server in background thread.
|
|
std::size_t num_threads = boost::lexical_cast<std::size_t>(argv[3]);
|
|
http::server2::server s(argv[1], argv[2], argv[4], num_threads);
|
|
boost::thread t(boost::bind(&http::server2::server::run, &s));
|
|
|
|
// Restore previous signals.
|
|
pthread_sigmask(SIG_SETMASK, &old_mask, 0);
|
|
|
|
// Wait for signal indicating time to shut down.
|
|
sigset_t wait_mask;
|
|
sigemptyset(&wait_mask);
|
|
sigaddset(&wait_mask, SIGINT);
|
|
sigaddset(&wait_mask, SIGQUIT);
|
|
sigaddset(&wait_mask, SIGTERM);
|
|
pthread_sigmask(SIG_BLOCK, &wait_mask, 0);
|
|
int sig = 0;
|
|
sigwait(&wait_mask, &sig);
|
|
|
|
// Stop the server.
|
|
s.stop();
|
|
t.join();
|
|
}
|
|
catch (std::exception& e)
|
|
{
|
|
std::cerr << "exception: " << e.what() << "\n";
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
#endif // !defined(_WIN32)
|