Odil
A C++11 library for the DICOM standard
Loading...
Searching...
No Matches
Transport.h
Go to the documentation of this file.
1/*************************************************************************
2 * odil - Copyright (C) Universite de Strasbourg
3 * Distributed under the terms of the CeCILL-B license, as published by
4 * the CEA-CNRS-INRIA. Refer to the LICENSE file or to
5 * http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
6 * for details.
7 ************************************************************************/
8
9#ifndef _1619bae8_acba_4bf8_8205_aa8dd0085c66
10#define _1619bae8_acba_4bf8_8205_aa8dd0085c66
11
12#include <memory>
13#include <string>
14
15#include <chrono>
16
17#include <boost/asio.hpp>
18
19// NOTE: the io_service type alias has been removed in boost 1.87.0
20#if BOOST_VERSION >= 108700
21namespace boost
22{
23namespace asio
24{
25using io_service = io_context;
26}
27}
28#endif
29
30#include "odil/odil.h"
31
32namespace odil
33{
34
35namespace dul
36{
37
46{
48 typedef boost::asio::ip::tcp::socket Socket;
49
51 typedef boost::asio::steady_timer::duration duration_type;
52
55
58
60 boost::asio::io_service const & get_service() const;
61
63 boost::asio::io_service & get_service();
64
66 std::shared_ptr<Socket const> get_socket() const;
67
69 std::shared_ptr<Socket> get_socket();
70
73
76
78 bool is_open() const;
79
81 void connect(Socket::endpoint_type const & peer_endpoint);
82
87 void receive(Socket::endpoint_type const & endpoint);
88
90 void close();
91
93 std::string read(std::size_t length);
94
96 void write(std::string const & data);
97
98private:
99 boost::asio::io_service _service;
100 std::shared_ptr<Socket> _socket;
101 duration_type _timeout;
102 boost::asio::steady_timer _deadline;
103
104 std::shared_ptr<boost::asio::ip::tcp::acceptor> _acceptor;
105
106 enum class Source
107 {
108 NONE,
109 TIMER,
110 OPERATION,
111 };
112
113 void _start_deadline(Source & source, boost::system::error_code & error);
114 void _stop_deadline();
115
116 void _run(Source & source, boost::system::error_code & error);
117};
118
119}
120
121}
122
123#endif // _1619bae8_acba_4bf8_8205_aa8dd0085c66
Definition EventData.h:24
Definition Association.h:25
#define ODIL_API
Definition odil.h:28
~Transport()
Destructor.
duration_type get_timeout() const
Return the timeout, default to infinity.
std::shared_ptr< Socket const > get_socket() const
Return the socket.
bool is_open() const
Test whether the transport is open.
void receive(Socket::endpoint_type const &endpoint)
Receive a connection on the specified endpoint, raise an exception upon error.
std::string read(std::size_t length)
Read data, raise an exception on error.
std::shared_ptr< Socket > get_socket()
Return the socket.
void close()
Close the connection.
boost::asio::io_service & get_service()
Return the io_service.
Transport()
Constructor.
boost::asio::steady_timer::duration duration_type
Duration of the timeout.
Definition Transport.h:51
boost::asio::io_service const & get_service() const
Return the io_service.
boost::asio::ip::tcp::socket Socket
Socket type.
Definition Transport.h:48
void connect(Socket::endpoint_type const &peer_endpoint)
Connect to the specified endpoint, raise an exception upon error.
void write(std::string const &data)
Write data, raise an exception on error.
void set_timeout(duration_type timeout)
Set the timeout.