blob: 5027d41b5800909524fac31fcc8a580106ab5770 [file] [log] [blame]
Alexander Afanasyeva9034b02014-01-26 18:32:02 -08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (C) 2014 Named Data Networking Project
4 * See COPYING for copyright and distribution information.
5 */
6
7#ifndef NFD_FACE_TCP_CHANNEL_FACTORY_HPP
8#define NFD_FACE_TCP_CHANNEL_FACTORY_HPP
9
10#include "channel-factory.hpp"
11#include "tcp-channel.hpp"
12
Alexander Afanasyev18bbf812014-01-29 01:40:23 -080013namespace nfd {
Alexander Afanasyeva9034b02014-01-26 18:32:02 -080014
15class TcpChannelFactory : public ChannelFactory<tcp::Endpoint, TcpChannel>
16{
17public:
18 /**
19 * \brief Exception of TcpChannelFactory
20 */
21 struct Error : public ChannelFactory::Error
22 {
23 Error(const std::string& what) : ChannelFactory::Error(what) {}
24 };
25
Alexander Afanasyev8ad71ba2014-01-27 00:07:14 -080026 TcpChannelFactory(boost::asio::io_service& ioService);
27
Alexander Afanasyeva9034b02014-01-26 18:32:02 -080028 /**
29 * \brief Create TCP-based channel using tcp::Endpoint
30 *
31 * tcp::Endpoint is really an alias for boost::asio::ip::tcp::endpoint.
32 *
33 * If this method called twice with the same endpoint, only one channel
34 * will be created. The second call will just retrieve the existing
35 * channel.
36 *
37 * \returns always a valid pointer to a TcpChannel object, an exception
38 * is thrown if it cannot be created.
39 *
40 * \throws TcpChannelFactory::Error
41 *
42 * \see http://www.boost.org/doc/libs/1_42_0/doc/html/boost_asio/reference/ip__tcp/endpoint.html
43 * for details on ways to create tcp::Endpoint
44 */
45 shared_ptr<TcpChannel>
46 create(const tcp::Endpoint& localEndpoint);
47
48 /**
49 * \brief Create TCP-based channel using specified host and port number
50 *
51 * This method will attempt to resolve the provided host and port numbers
52 * and will throw TcpChannelFactory::Error when channel cannot be created.
53 *
54 * Note that this call will **BLOCK** until resolution is done or failed.
55 *
56 * \throws TcpChannelFactory::Error
57 */
58 shared_ptr<TcpChannel>
59 create(const std::string& localHost, const std::string& localPort);
60
61 /**
62 * \brief Look up TcpChannel using specified local endpoint
63 *
64 * \returns shared pointer to the existing TcpChannel object
65 * or empty shared pointer when such channel does not exist
66 *
67 * \throws never
68 */
69 shared_ptr<TcpChannel>
70 find(const tcp::Endpoint& localEndpoint);
Alexander Afanasyev8ad71ba2014-01-27 00:07:14 -080071
72private:
73 boost::asio::io_service& m_ioService;
Alexander Afanasyeva9034b02014-01-26 18:32:02 -080074};
75
Alexander Afanasyev18bbf812014-01-29 01:40:23 -080076} // namespace nfd
Alexander Afanasyeva9034b02014-01-26 18:32:02 -080077
78#endif // NFD_FACE_TCP_CHANNEL_FACTORY_HPP