/usr/include/ros/transport/transport_tcp.h is in libroscpp-dev 1.11.16-3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 | /*
* Software License Agreement (BSD License)
*
* Copyright (c) 2008, Willow Garage, Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of Willow Garage, Inc. nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef ROSCPP_TRANSPORT_TCP_H
#define ROSCPP_TRANSPORT_TCP_H
#include <ros/types.h>
#include <ros/transport/transport.h>
#include <boost/thread/recursive_mutex.hpp>
#include "ros/io.h"
#include <ros/common.h>
namespace ros
{
class TransportTCP;
typedef boost::shared_ptr<TransportTCP> TransportTCPPtr;
class PollSet;
/**
* \brief TCPROS transport
*/
class ROSCPP_DECL TransportTCP : public Transport
{
public:
static bool s_use_keepalive_;
static bool s_use_ipv6_;
public:
enum Flags
{
SYNCHRONOUS = 1<<0,
};
TransportTCP(PollSet* poll_set, int flags = 0);
virtual ~TransportTCP();
/**
* \brief Connect to a remote host.
* \param host The hostname/IP to connect to
* \param port The port to connect to
* \return Whether or not the connection was successful
*/
bool connect(const std::string& host, int port);
/**
* \brief Returns the URI of the remote host
*/
std::string getClientURI();
typedef boost::function<void(const TransportTCPPtr&)> AcceptCallback;
/**
* \brief Start a server socket and listen on a port
* \param port The port to listen on
* \param backlog defines the maximum length for the queue of pending connections. Identical to the backlog parameter to the ::listen function
* \param accept_cb The function to call when a client socket has connected
*/
bool listen(int port, int backlog, const AcceptCallback& accept_cb);
/**
* \brief Accept a connection on a server socket. Blocks until a connection is available
*/
TransportTCPPtr accept();
/**
* \brief Returns the port this transport is listening on
*/
int getServerPort() { return server_port_; }
int getLocalPort() { return local_port_; }
void setNoDelay(bool nodelay);
void setKeepAlive(bool use, uint32_t idle, uint32_t interval, uint32_t count);
const std::string& getConnectedHost() { return connected_host_; }
int getConnectedPort() { return connected_port_; }
// overrides from Transport
virtual int32_t read(uint8_t* buffer, uint32_t size);
virtual int32_t write(uint8_t* buffer, uint32_t size);
virtual void enableWrite();
virtual void disableWrite();
virtual void enableRead();
virtual void disableRead();
virtual void close();
virtual std::string getTransportInfo();
virtual void parseHeader(const Header& header);
virtual const char* getType() { return "TCPROS"; }
private:
/**
* \brief Initializes the assigned socket -- sets it to non-blocking and enables reading
*/
bool initializeSocket();
bool setNonBlocking();
/**
* \brief Set the socket to be used by this transport
* \param sock A valid TCP socket
* \return Whether setting the socket was successful
*/
bool setSocket(int sock);
void socketUpdate(int events);
socket_fd_t sock_;
bool closed_;
boost::recursive_mutex close_mutex_;
bool expecting_read_;
bool expecting_write_;
bool is_server_;
sockaddr_storage server_address_;
socklen_t sa_len_;
sockaddr_storage local_address_;
socklen_t la_len_;
int server_port_;
int local_port_;
AcceptCallback accept_cb_;
std::string cached_remote_host_;
PollSet* poll_set_;
int flags_;
std::string connected_host_;
int connected_port_;
};
}
#endif // ROSCPP_TRANSPORT_TCP_H
|