]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/libs/asio/example/cpp03/iostreams/daytime_server.cpp
update sources to v12.2.3
[ceph.git] / ceph / src / boost / libs / asio / example / cpp03 / iostreams / daytime_server.cpp
CommitLineData
7c673cae
FG
1//
2// daytime_server.cpp
3// ~~~~~~~~~~~~~~~~~~
4//
b32b8144 5// Copyright (c) 2003-2017 Christopher M. Kohlhoff (chris at kohlhoff dot com)
7c673cae
FG
6//
7// Distributed under the Boost Software License, Version 1.0. (See accompanying
8// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
9//
10
11#include <ctime>
12#include <iostream>
13#include <string>
14#include <boost/asio.hpp>
15
16using boost::asio::ip::tcp;
17
18std::string make_daytime_string()
19{
20 using namespace std; // For time_t, time and ctime;
21 time_t now = time(0);
22 return ctime(&now);
23}
24
25int main()
26{
27 try
28 {
b32b8144 29 boost::asio::io_context io_context;
7c673cae
FG
30
31 tcp::endpoint endpoint(tcp::v4(), 13);
b32b8144 32 tcp::acceptor acceptor(io_context, endpoint);
7c673cae
FG
33
34 for (;;)
35 {
36 tcp::iostream stream;
37 boost::system::error_code ec;
b32b8144 38 acceptor.accept(stream.socket(), ec);
7c673cae
FG
39 if (!ec)
40 {
41 stream << make_daytime_string();
42 }
43 }
44 }
45 catch (std::exception& e)
46 {
47 std::cerr << e.what() << std::endl;
48 }
49
50 return 0;
51}