transport_tcp.h
Go to the documentation of this file.
00001 /*
00002  * Software License Agreement (BSD License)
00003  *
00004  *  Copyright (c) 2008, Willow Garage, Inc.
00005  *  All rights reserved.
00006  *
00007  *  Redistribution and use in source and binary forms, with or without
00008  *  modification, are permitted provided that the following conditions
00009  *  are met:
00010  *
00011  *   * Redistributions of source code must retain the above copyright
00012  *     notice, this list of conditions and the following disclaimer.
00013  *   * Redistributions in binary form must reproduce the above
00014  *     copyright notice, this list of conditions and the following
00015  *     disclaimer in the documentation and/or other materials provided
00016  *     with the distribution.
00017  *   * Neither the name of Willow Garage, Inc. nor the names of its
00018  *     contributors may be used to endorse or promote products derived
00019  *     from this software without specific prior written permission.
00020  *
00021  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00022  *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00023  *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00024  *  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00025  *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00026  *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00027  *  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00028  *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00029  *  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00030  *  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00031  *  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00032  *  POSSIBILITY OF SUCH DAMAGE.
00033  */
00034 
00035 #ifndef ROSCPP_TRANSPORT_TCP_H
00036 #define ROSCPP_TRANSPORT_TCP_H
00037 
00038 #include <ros/types.h>
00039 #include <ros/transport/transport.h>
00040 
00041 #include <boost/thread/recursive_mutex.hpp>
00042 #include "ros/io.h"
00043 #include <ros/common.h>
00044 
00045 namespace ros
00046 {
00047 
00048 class TransportTCP;
00049 typedef boost::shared_ptr<TransportTCP> TransportTCPPtr;
00050 
00051 class PollSet;
00052 
00056 class ROSCPP_DECL TransportTCP : public Transport
00057 {
00058 public:
00059   static bool s_use_keepalive_;
00060   static bool s_use_ipv6_;
00061 
00062 public:
00063   enum Flags
00064   {
00065     SYNCHRONOUS = 1<<0,
00066   };
00067 
00068   TransportTCP(PollSet* poll_set, int flags = 0);
00069   virtual ~TransportTCP();
00070 
00077   bool connect(const std::string& host, int port);
00078 
00082   std::string getClientURI();
00083 
00084   typedef boost::function<void(const TransportTCPPtr&)> AcceptCallback;
00091   bool listen(int port, int backlog, const AcceptCallback& accept_cb);
00095   TransportTCPPtr accept();
00099   int getServerPort() { return server_port_; }
00100 
00101   void setNoDelay(bool nodelay);
00102   void setKeepAlive(bool use, uint32_t idle, uint32_t interval, uint32_t count);
00103 
00104   const std::string& getConnectedHost() { return connected_host_; }
00105   int getConnectedPort() { return connected_port_; }
00106 
00107   // overrides from Transport
00108   virtual int32_t read(uint8_t* buffer, uint32_t size);
00109   virtual int32_t write(uint8_t* buffer, uint32_t size);
00110 
00111   virtual void enableWrite();
00112   virtual void disableWrite();
00113   virtual void enableRead();
00114   virtual void disableRead();
00115 
00116   virtual void close();
00117 
00118   virtual std::string getTransportInfo();
00119 
00120   virtual void parseHeader(const Header& header);
00121 
00122   virtual const char* getType() { return "TCPROS"; }
00123 
00124 private:
00128   bool initializeSocket();
00129 
00130   bool setNonBlocking();
00131 
00137   bool setSocket(int sock);
00138 
00139   void socketUpdate(int events);
00140 
00141   socket_fd_t sock_;
00142   bool closed_;
00143   boost::recursive_mutex close_mutex_;
00144 
00145   bool expecting_read_;
00146   bool expecting_write_;
00147 
00148   bool is_server_;
00149   sockaddr_storage server_address_;
00150   socklen_t sa_len_;
00151 
00152   int server_port_;
00153   AcceptCallback accept_cb_;
00154 
00155   std::string cached_remote_host_;
00156 
00157   PollSet* poll_set_;
00158   int flags_;
00159 
00160   std::string connected_host_;
00161   int connected_port_;
00162 };
00163 
00164 }
00165 
00166 #endif // ROSCPP_TRANSPORT_TCP_H
00167 


roscpp
Author(s): Morgan Quigley, Josh Faust, Brian Gerkey, Troy Straszheim
autogenerated on Mon Oct 6 2014 11:46:44