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


sick_scan_xd
Author(s): Michael Lehning , Jochen Sprickerhof , Martin Günther
autogenerated on Fri Oct 25 2024 02:47:12