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 
143  bool closed_;
144  boost::recursive_mutex close_mutex_;
145 
148 
150  sockaddr_storage server_address_;
151  socklen_t sa_len_;
152  sockaddr_storage local_address_;
153  socklen_t la_len_;
154 
157  AcceptCallback accept_cb_;
158 
159  std::string cached_remote_host_;
160 
162  int flags_;
163 
164  std::string connected_host_;
166 };
167 
168 }
169 
170 #endif // ROSCPP_TRANSPORT_TCP_H
171 
boost::function< void(const TransportTCPPtr &)> AcceptCallback
Definition: transport_tcp.h:84
Abstract base class that allows abstraction of the transport type, eg. TCP, shared memory...
Definition: transport.h:56
socket_fd_t sock_
virtual const char * getType()
Return a string that details the type of transport (Eg. TCPROS)
std::string connected_host_
Manages a set of sockets being polled through the poll() function call.
Definition: poll_set.h:57
std_msgs::Header * header(M &m)
int socket_fd_t
Definition: io.h:136
std::string cached_remote_host_
TCPROS transport.
Definition: transport_tcp.h:56
AcceptCallback accept_cb_
static bool s_use_ipv6_
Definition: transport_tcp.h:60
boost::recursive_mutex close_mutex_
sockaddr_storage server_address_
sockaddr_storage local_address_
int getServerPort()
Returns the port this transport is listening on.
Definition: transport_tcp.h:99
static bool s_use_keepalive_
Definition: transport_tcp.h:59
boost::shared_ptr< TransportTCP > TransportTCPPtr
Definition: forwards.h:58
const std::string & getConnectedHost()


roscpp
Author(s): Morgan Quigley, Josh Faust, Brian Gerkey, Troy Straszheim, Dirk Thomas
autogenerated on Mon Nov 2 2020 03:52:26