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 <boost/asio.hpp>
16#include <boost/date_time.hpp>
17
18// NOTE: the io_service type alias has been removed in boost 1.87.0
19#if BOOST_VERSION >= 108700
20namespace boost
21{
22namespace asio
23{
24using io_service = io_context;
25}
26}
27#endif
28
29#include "odil/odil.h"
30
31namespace odil
32{
33
34namespace dul
35{
36
45{
47 typedef boost::asio::ip::tcp::socket Socket;
48
50 typedef boost::asio::deadline_timer::duration_type duration_type;
51
54
57
59 boost::asio::io_service const & get_service() const;
60
62 boost::asio::io_service & get_service();
63
65 std::shared_ptr<Socket const> get_socket() const;
66
68 std::shared_ptr<Socket> get_socket();
69
72
75
77 bool is_open() const;
78
80 void connect(Socket::endpoint_type const & peer_endpoint);
81
86 void receive(Socket::endpoint_type const & endpoint);
87
89 void close();
90
92 std::string read(std::size_t length);
93
95 void write(std::string const & data);
96
97private:
98 boost::asio::io_service _service;
99 std::shared_ptr<Socket> _socket;
100 duration_type _timeout;
101 boost::asio::deadline_timer _deadline;
102
103 std::shared_ptr<boost::asio::ip::tcp::acceptor> _acceptor;
104
105 enum class Source
106 {
107 NONE,
108 TIMER,
109 OPERATION,
110 };
111
112 void _start_deadline(Source & source, boost::system::error_code & error);
113 void _stop_deadline();
114
115 void _run(Source & source, boost::system::error_code & error);
116};
117
118}
119
120}
121
122#endif // _1619bae8_acba_4bf8_8205_aa8dd0085c66
Definition EventData.h:24
Definition Association.h:25
#define ODIL_API
Definition odil.h:28
boost::asio::deadline_timer::duration_type duration_type
Duration of the timeout.
Definition Transport.h:50
~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::io_service const & get_service() const
Return the io_service.
boost::asio::ip::tcp::socket Socket
Socket type.
Definition Transport.h:47
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.