transport_tcp.h
Go to the documentation of this file.
1 /*
2  * Software License Agreement (BSD License)
3  *
4  * Copyright (c) 2008, Willow Garage, Inc.
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  *
11  * * Redistributions of source code must retain the above copyright
12  * notice, this list of conditions and the following disclaimer.
13  * * Redistributions in binary form must reproduce the above
14  * copyright notice, this list of conditions and the following
15  * disclaimer in the documentation and/or other materials provided
16  * with the distribution.
17  * * Neither the name of Willow Garage, Inc. nor the names of its
18  * contributors may be used to endorse or promote products derived
19  * from this software without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32  * POSSIBILITY OF SUCH DAMAGE.
33  */
34 
35 #ifndef ROSCPP_TRANSPORT_TCP_H
36 #define ROSCPP_TRANSPORT_TCP_H
37 
38 #include <ros/types.h>
40 
41 #include <boost/thread/recursive_mutex.hpp>
42 #include "ros/io.h"
43 #include <ros/common.h>
44 
45 namespace ros
46 {
47 
48 class TransportTCP;
50 
51 class PollSet;
52 
56 class ROSCPP_DECL TransportTCP : public Transport
57 {
58 public:
59  static bool s_use_keepalive_;
60  static bool s_use_ipv6_;
61 
62 public:
63  enum Flags
64  {
65  SYNCHRONOUS = 1<<0,
66  };
67 
68  TransportTCP(PollSet* poll_set, int flags = 0);
69  virtual ~TransportTCP();
70 
77  bool connect(const std::string& host, int port);
78 
82  std::string getClientURI();
83 
84  typedef boost::function<void(const TransportTCPPtr&)> AcceptCallback;
91  bool listen(int port, int backlog, const AcceptCallback& accept_cb);
95  TransportTCPPtr accept();
99  int getServerPort() { return server_port_; }
100  int getLocalPort() { return local_port_; }
101 
102  void setNoDelay(bool nodelay);
103  void setKeepAlive(bool use, uint32_t idle, uint32_t interval, uint32_t count);
104 
105  const std::string& getConnectedHost() { return connected_host_; }
106  int getConnectedPort() { return connected_port_; }
107 
108  // overrides from Transport
109  virtual int32_t read(uint8_t* buffer, uint32_t size);
110  virtual int32_t write(uint8_t* buffer, uint32_t size);
111 
112  virtual void enableWrite();
113  virtual void disableWrite();
114  virtual void enableRead();
115  virtual void disableRead();
116 
117  virtual void close();
118 
119  virtual std::string getTransportInfo();
120 
121  virtual void parseHeader(const Header& header);
122 
123  virtual const char* getType() { return "TCPROS"; }
124 
125 private:
129  bool initializeSocket();
130 
131  bool setNonBlocking();
132 
138  bool setSocket(int sock);
139 
140  void socketUpdate(int events);
141 
144  bool closed_;
145  boost::recursive_mutex close_mutex_;
146 
149 
151  sockaddr_storage server_address_;
152  socklen_t sa_len_;
153  sockaddr_storage local_address_;
154  socklen_t la_len_;
155 
159 
160  std::string cached_remote_host_;
161 
163  int flags_;
164 
165  std::string connected_host_;
167 };
168 
169 }
170 
171 #endif // ROSCPP_TRANSPORT_TCP_H
172 
boost::shared_ptr< TransportTCP >
ros::TransportTCP::expecting_write_
bool expecting_write_
Definition: transport_tcp.h:148
ros
ros::TransportTCP::sock_
socket_fd_t sock_
Definition: transport_tcp.h:142
ros::TransportTCP::local_address_
sockaddr_storage local_address_
Definition: transport_tcp.h:153
ros::TransportTCP::Flags
Flags
Definition: transport_tcp.h:63
ros::Header
ros::TransportTCP::expecting_read_
bool expecting_read_
Definition: transport_tcp.h:147
ros::TransportTCP::s_use_keepalive_
static bool s_use_keepalive_
Definition: transport_tcp.h:59
ros::TransportTCP::cached_remote_host_
std::string cached_remote_host_
Definition: transport_tcp.h:160
ros::Transport
Abstract base class that allows abstraction of the transport type, eg. TCP, shared memory,...
Definition: transport.h:55
ros::TransportTCP::connected_host_
std::string connected_host_
Definition: transport_tcp.h:165
ros::TransportTCP::close_mutex_
boost::recursive_mutex close_mutex_
Definition: transport_tcp.h:145
ros::TransportTCP::server_address_
sockaddr_storage server_address_
Definition: transport_tcp.h:151
ros::TransportTCP::is_server_
bool is_server_
Definition: transport_tcp.h:150
ros::TransportTCP::la_len_
socklen_t la_len_
Definition: transport_tcp.h:154
ros::TransportTCP::getServerPort
int getServerPort()
Returns the port this transport is listening on.
Definition: transport_tcp.h:99
ros::TransportTCP::closed_
bool closed_
Definition: transport_tcp.h:144
ros::TransportTCP::sa_len_
socklen_t sa_len_
Definition: transport_tcp.h:152
ros::TransportTCP::getType
virtual const char * getType()
Return a string that details the type of transport (Eg. TCPROS)
Definition: transport_tcp.h:123
ros::TransportTCP::local_port_
int local_port_
Definition: transport_tcp.h:157
ros::TransportTCP
TCPROS transport.
Definition: transport_tcp.h:56
ros::socket_fd_t
int socket_fd_t
Definition: io.h:138
ros::TransportTCPPtr
boost::shared_ptr< TransportTCP > TransportTCPPtr
Definition: forwards.h:58
ros::TransportTCP::accept_cb_
AcceptCallback accept_cb_
Definition: transport_tcp.h:158
io.h
ros::TransportTCP::flags_
int flags_
Definition: transport_tcp.h:163
ros::TransportTCP::getConnectedPort
int getConnectedPort()
Definition: transport_tcp.h:106
ros::TransportTCP::s_use_ipv6_
static bool s_use_ipv6_
Definition: transport_tcp.h:60
transport.h
ros::TransportTCP::getLocalPort
int getLocalPort()
Definition: transport_tcp.h:100
ros::TransportTCP::server_port_
int server_port_
Definition: transport_tcp.h:156
ros::TransportTCP::async_connected_
bool async_connected_
Definition: transport_tcp.h:143
ros::TransportTCP::getConnectedHost
const std::string & getConnectedHost()
Definition: transport_tcp.h:105
types.h
ros::TransportTCP::poll_set_
PollSet * poll_set_
Definition: transport_tcp.h:162
ros::TransportTCP::AcceptCallback
boost::function< void(const TransportTCPPtr &)> AcceptCallback
Definition: transport_tcp.h:84
ros::TransportTCP::connected_port_
int connected_port_
Definition: transport_tcp.h:166
ros::PollSet
Manages a set of sockets being polled through the poll() function call.
Definition: poll_set.h:57


roscpp
Author(s): Morgan Quigley, Josh Faust, Brian Gerkey, Troy Straszheim, Dirk Thomas
autogenerated on Sat Oct 17 2020 19:28:47