transport_udp.cpp
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 
36 #include "ros/poll_set.h"
37 #include "ros/file_log.h"
38 
39 #include <ros/assert.h>
40 #include <boost/bind.hpp>
41 #ifndef _WIN32
42  #include <sys/socket.h> // explicit include required for FreeBSD
43 #endif
44 
45 #include <fcntl.h>
46 #if defined(__APPLE__)
47  // For readv() and writev()
48  #include <sys/types.h>
49  #include <sys/uio.h>
50  #include <unistd.h>
51 #elif defined(__ANDROID__)
52  // For readv() and writev() on ANDROID
53  #include <sys/uio.h>
54 #elif defined(_POSIX_VERSION)
55  // For readv() and writev()
56  #include <sys/uio.h>
57 #endif
58 
59 namespace ros
60 {
61 
62 TransportUDP::TransportUDP(PollSet* poll_set, int flags, int max_datagram_size)
63 : sock_(-1)
64 , closed_(false)
65 , expecting_read_(false)
66 , expecting_write_(false)
67 , is_server_(false)
68 , server_address_{}
69 , local_address_{}
70 , server_port_(-1)
71 , local_port_(-1)
72 , poll_set_(poll_set)
73 , flags_(flags)
74 , connection_id_(0)
75 , current_message_id_(0)
76 , total_blocks_(0)
77 , last_block_(0)
78 , max_datagram_size_(max_datagram_size)
79 , data_filled_(0)
80 , reorder_buffer_(0)
81 , reorder_bytes_(0)
82 {
83  // This may eventually be machine dependent
84  if (max_datagram_size_ == 0)
85  max_datagram_size_ = 1500;
86  reorder_buffer_ = new uint8_t[max_datagram_size_];
87  reorder_start_ = reorder_buffer_;
88  data_buffer_ = new uint8_t[max_datagram_size_];
89  data_start_ = data_buffer_;
90 }
91 
93 {
94  ROS_ASSERT_MSG(sock_ == ROS_INVALID_SOCKET, "TransportUDP socket [%d] was never closed", sock_);
95  delete [] reorder_buffer_;
96  delete [] data_buffer_;
97 }
98 
100 {
101  sock_ = sock;
102  return initializeSocket();
103 }
104 
106 {
107  {
108  boost::mutex::scoped_lock lock(close_mutex_);
109 
110  if (closed_)
111  {
112  return;
113  }
114  }
115 
116  if((events & POLLERR) ||
117  (events & POLLHUP) ||
118  (events & POLLNVAL))
119  {
120  ROSCPP_LOG_DEBUG("Socket %d closed with (ERR|HUP|NVAL) events %d", sock_, events);
121  close();
122  }
123  else
124  {
125  if ((events & POLLIN) && expecting_read_)
126  {
127  if (read_cb_)
128  {
129  read_cb_(shared_from_this());
130  }
131  }
132 
133  if ((events & POLLOUT) && expecting_write_)
134  {
135  if (write_cb_)
136  {
137  write_cb_(shared_from_this());
138  }
139  }
140  }
141 
142 }
143 
145 {
146  std::stringstream str;
147  str << "UDPROS connection on port " << local_port_ << " to [" << cached_remote_host_ << "]";
148  return str.str();
149 }
150 
151 bool TransportUDP::connect(const std::string& host, int port, int connection_id)
152 {
153  if (!isHostAllowed(host))
154  return false; // adios amigo
155 
156  sock_ = socket(AF_INET, SOCK_DGRAM, 0);
157  connection_id_ = connection_id;
158 
159  if (sock_ == ROS_INVALID_SOCKET)
160  {
161  ROS_ERROR("socket() failed with error [%s]", last_socket_error_string());
162  return false;
163  }
164 
165  sockaddr_in sin = {};
166  sin.sin_family = AF_INET;
167  if (inet_addr(host.c_str()) == INADDR_NONE)
168  {
169  struct addrinfo* addr;
170  struct addrinfo hints;
171  memset(&hints, 0, sizeof(hints));
172  hints.ai_family = AF_UNSPEC;
173 
174  if (getaddrinfo(host.c_str(), NULL, &hints, &addr) != 0)
175  {
176  close();
177  ROS_ERROR("couldn't resolve host [%s]", host.c_str());
178  return false;
179  }
180 
181  bool found = false;
182  struct addrinfo* it = addr;
183  for (; it; it = it->ai_next)
184  {
185  if (it->ai_family == AF_INET)
186  {
187  memcpy(&sin, it->ai_addr, it->ai_addrlen);
188  sin.sin_family = it->ai_family;
189  sin.sin_port = htons(port);
190 
191  found = true;
192  break;
193  }
194  }
195 
196  freeaddrinfo(addr);
197 
198  if (!found)
199  {
200  ROS_ERROR("Couldn't find an AF_INET address for [%s]\n", host.c_str());
201  return false;
202  }
203 
204  ROSCPP_LOG_DEBUG("Resolved host [%s] to [%s]", host.c_str(), inet_ntoa(sin.sin_addr));
205  }
206  else
207  {
208  sin.sin_addr.s_addr = inet_addr(host.c_str()); // already an IP addr
209  }
210 
211  sin.sin_port = htons(port);
212 
213  if (::connect(sock_, (sockaddr *)&sin, sizeof(sin)))
214  {
215  ROSCPP_LOG_DEBUG("Connect to udpros host [%s:%d] failed with error [%s]", host.c_str(), port, last_socket_error_string());
216  close();
217 
218  return false;
219  }
220 
221  // from daniel stonier:
222 #ifdef WIN32
223  // This is hackish, but windows fails at recv() if its slow to connect (e.g. happens with wireless)
224  // recv() needs to check if its connected or not when its asynchronous?
225  Sleep(100);
226 #endif
227 
228  std::stringstream ss;
229  ss << host << ":" << port << " on socket " << sock_;
230  cached_remote_host_ = ss.str();
231 
232  if (!initializeSocket())
233  {
234  return false;
235  }
236 
237  ROSCPP_LOG_DEBUG("Connect succeeded to [%s:%d] on socket [%d]", host.c_str(), port, sock_);
238 
239  return true;
240 }
241 
242 bool TransportUDP::createIncoming(int port, bool is_server)
243 {
244  is_server_ = is_server;
245 
246  sock_ = socket(AF_INET, SOCK_DGRAM, 0);
247 
248  if (sock_ == ROS_INVALID_SOCKET)
249  {
250  ROS_ERROR("socket() failed with error [%s]", last_socket_error_string());
251  return false;
252  }
253 
254  server_address_.sin_family = AF_INET;
255  server_address_.sin_port = htons(port);
256  server_address_.sin_addr.s_addr = isOnlyLocalhostAllowed() ?
257  htonl(INADDR_LOOPBACK) :
258  INADDR_ANY;
259  if (bind(sock_, (sockaddr *)&server_address_, sizeof(server_address_)) < 0)
260  {
261  ROS_ERROR("bind() failed with error [%s]", last_socket_error_string());
262  return false;
263  }
264 
265  socklen_t len = sizeof(server_address_);
266  getsockname(sock_, (sockaddr *)&server_address_, &len);
267  server_port_ = ntohs(server_address_.sin_port);
268  ROSCPP_LOG_DEBUG("UDPROS server listening on port [%d]", server_port_);
269 
270  if (!initializeSocket())
271  {
272  return false;
273  }
274 
275  enableRead();
276 
277  return true;
278 }
279 
281 {
283 
284  if (!(flags_ & SYNCHRONOUS))
285  {
286  int result = set_non_blocking(sock_);
287  if ( result != 0 ) {
288  ROS_ERROR("setting socket [%d] as non_blocking failed with error [%d]", sock_, result);
289  close();
290  return false;
291  }
292  }
293 
294  socklen_t len = sizeof(local_address_);
295  getsockname(sock_, (sockaddr *)&local_address_, &len);
296  local_port_ = ntohs(local_address_.sin_port);
297 
299  if (poll_set_)
300  {
301  poll_set_->addSocket(sock_, boost::bind(&TransportUDP::socketUpdate, this, boost::placeholders::_1), shared_from_this());
302  }
303 
304  return true;
305 }
306 
308 {
309  Callback disconnect_cb;
310 
311  if (!closed_)
312  {
313  {
314  boost::mutex::scoped_lock lock(close_mutex_);
315 
316  if (!closed_)
317  {
318  closed_ = true;
319 
320  ROSCPP_LOG_DEBUG("UDP socket [%d] closed", sock_);
321 
323 
324  if (poll_set_)
325  {
327  }
328 
329  if ( close_socket(sock_) != 0 )
330  {
331  ROS_ERROR("Error closing socket [%d]: [%s]", sock_, last_socket_error_string());
332  }
333 
335 
336  disconnect_cb = disconnect_cb_;
337 
339  read_cb_ = Callback();
340  write_cb_ = Callback();
341  }
342  }
343  }
344 
345  if (disconnect_cb)
346  {
347  disconnect_cb(shared_from_this());
348  }
349 }
350 
351 int32_t TransportUDP::read(uint8_t* buffer, uint32_t size)
352 {
353  {
354  boost::mutex::scoped_lock lock(close_mutex_);
355  if (closed_)
356  {
357  ROSCPP_LOG_DEBUG("Tried to read on a closed socket [%d]", sock_);
358  return -1;
359  }
360  }
361 
362  ROS_ASSERT((int32_t)size > 0);
363 
364  uint32_t bytes_read = 0;
365 
366  while (bytes_read < size)
367  {
369 
370  // Get the data either from the reorder buffer or the socket
371  // copy_bytes will contain the read size.
372  // from_previous is true if the data belongs to the previous UDP datagram.
373  uint32_t copy_bytes = 0;
374  bool from_previous = false;
375  if (reorder_bytes_)
376  {
378  {
379  from_previous = true;
380  }
381 
382  copy_bytes = std::min(size - bytes_read, reorder_bytes_);
384  memcpy(buffer + bytes_read, reorder_start_, copy_bytes);
385  reorder_bytes_ -= copy_bytes;
386  reorder_start_ += copy_bytes;
387  }
388  else
389  {
390  if (data_filled_ == 0)
391  {
392 #if defined(WIN32)
393  SSIZE_T num_bytes = 0;
394  DWORD received_bytes = 0;
395  DWORD flags = 0;
396  WSABUF iov[2];
397  iov[0].buf = reinterpret_cast<char*>(&header);
398  iov[0].len = sizeof(header);
399  iov[1].buf = reinterpret_cast<char*>(data_buffer_);
400  iov[1].len = max_datagram_size_ - sizeof(header);
401  int rc = WSARecv(sock_, iov, 2, &received_bytes, &flags, NULL, NULL);
402  if ( rc == SOCKET_ERROR) {
403  num_bytes = -1;
404  } else {
405  num_bytes = received_bytes;
406  }
407 #else
408  ssize_t num_bytes;
409  struct iovec iov[2];
410  iov[0].iov_base = &header;
411  iov[0].iov_len = sizeof(header);
412  iov[1].iov_base = data_buffer_;
413  iov[1].iov_len = max_datagram_size_ - sizeof(header);
414  // Read a datagram with header
415  num_bytes = readv(sock_, iov, 2);
416 #endif
417  if (num_bytes < 0)
418  {
420  {
421  num_bytes = 0;
422  break;
423  }
424  else
425  {
426  ROSCPP_LOG_DEBUG("readv() failed with error [%s]", last_socket_error_string());
427  close();
428  break;
429  }
430  }
431  else if (num_bytes == 0)
432  {
433  ROSCPP_LOG_DEBUG("Socket [%d] received 0/%d bytes, closing", sock_, size);
434  close();
435  return -1;
436  }
437  else if (num_bytes < (unsigned) sizeof(header))
438  {
439  ROS_ERROR("Socket [%d] received short header (%d bytes): %s", sock_, int(num_bytes), last_socket_error_string());
440  close();
441  return -1;
442  }
443 
444  num_bytes -= sizeof(header);
445  data_filled_ = num_bytes;
447  }
448  else
449  {
450  from_previous = true;
451  }
452 
453  copy_bytes = std::min(size - bytes_read, data_filled_);
454  // Copy from the data buffer, whether it has data left in it from a previous datagram or
455  // was just filled by readv()
456  memcpy(buffer + bytes_read, data_start_, copy_bytes);
457  data_filled_ -= copy_bytes;
458  data_start_ += copy_bytes;
459  }
460 
461 
462  if (from_previous)
463  {
464  // We are simply reading data from the last UDP datagram, nothing to
465  // parse
466  bytes_read += copy_bytes;
467  }
468  else
469  {
470  // This datagram is new, process header
471  switch (header.op_)
472  {
473  case ROS_UDP_DATA0:
475  {
476  ROS_DEBUG("Received new message [%d:%d], while still working on [%d] (block %d of %d)", header.message_id_, header.block_, current_message_id_, last_block_ + 1, total_blocks_);
478 
479  // Copy the entire data buffer to the reorder buffer, as we will
480  // need to replay this UDP datagram in the next call.
485  total_blocks_ = 0;
486  last_block_ = 0;
487 
488  data_filled_ = 0;
490  return -1;
491  }
492  total_blocks_ = header.block_;
493  last_block_ = 0;
494  current_message_id_ = header.message_id_;
495  break;
496  case ROS_UDP_DATAN:
497  if (header.message_id_ != current_message_id_)
498  {
499  ROS_DEBUG("Message Id mismatch: %d != %d", header.message_id_, current_message_id_);
500  data_filled_ = 0; // discard datagram
501  return 0;
502  }
503  if (header.block_ != last_block_ + 1)
504  {
505  ROS_DEBUG("Expected block %d, received %d", last_block_ + 1, header.block_);
506  data_filled_ = 0; // discard datagram
507  return 0;
508  }
509  last_block_ = header.block_;
510 
511  break;
512  default:
513  ROS_ERROR("Unexpected UDP header OP [%d]", header.op_);
514  return -1;
515  }
516 
517  bytes_read += copy_bytes;
518 
519  if (last_block_ == (total_blocks_ - 1))
520  {
522  break;
523  }
524  }
525  }
526 
527  return bytes_read;
528 }
529 
530 int32_t TransportUDP::write(uint8_t* buffer, uint32_t size)
531 {
532  {
533  boost::mutex::scoped_lock lock(close_mutex_);
534 
535  if (closed_)
536  {
537  ROSCPP_LOG_DEBUG("Tried to write on a closed socket [%d]", sock_);
538  return -1;
539  }
540  }
541 
542  ROS_ASSERT((int32_t)size > 0);
543 
544  const uint32_t max_payload_size = max_datagram_size_ - sizeof(TransportUDPHeader);
545 
546  uint32_t bytes_sent = 0;
547  uint32_t this_block = 0;
548  if (++current_message_id_ == 0)
550  while (bytes_sent < size)
551  {
553  header.connection_id_ = connection_id_;
554  header.message_id_ = current_message_id_;
555  if (this_block == 0)
556  {
557  header.op_ = ROS_UDP_DATA0;
558  header.block_ = (size + max_payload_size - 1) / max_payload_size;
559  }
560  else
561  {
562  header.op_ = ROS_UDP_DATAN;
563  header.block_ = this_block;
564  }
565  ++this_block;
566 #if defined(WIN32)
567  WSABUF iov[2];
568  DWORD sent_bytes;
569  SSIZE_T num_bytes = 0;
570  DWORD flags = 0;
571  int rc;
572  iov[0].buf = reinterpret_cast<char*>(&header);
573  iov[0].len = sizeof(header);
574  iov[1].buf = reinterpret_cast<char*>(buffer + bytes_sent);
575  iov[1].len = std::min(max_payload_size, size - bytes_sent);
576  rc = WSASend(sock_, iov, 2, &sent_bytes, flags, NULL, NULL);
577  num_bytes = sent_bytes;
578  if (rc == SOCKET_ERROR) {
579  num_bytes = -1;
580  }
581 #else
582  struct iovec iov[2];
583  iov[0].iov_base = &header;
584  iov[0].iov_len = sizeof(header);
585  iov[1].iov_base = buffer + bytes_sent;
586  iov[1].iov_len = std::min(max_payload_size, size - bytes_sent);
587  ssize_t num_bytes = writev(sock_, iov, 2);
588 #endif
589  //usleep(100);
590  if (num_bytes < 0)
591  {
592  if( !last_socket_error_is_would_block() ) // Actually EAGAIN or EWOULDBLOCK on posix
593  {
594  ROSCPP_LOG_DEBUG("writev() failed with error [%s]", last_socket_error_string());
595  close();
596  break;
597  }
598  else
599  {
600  num_bytes = 0;
601  --this_block;
602  }
603  }
604  else if (num_bytes < (unsigned) sizeof(header))
605  {
606  ROSCPP_LOG_DEBUG("Socket [%d] short write (%d bytes), closing", sock_, int(num_bytes));
607  close();
608  break;
609  }
610  else
611  {
612  num_bytes -= sizeof(header);
613  }
614  bytes_sent += num_bytes;
615  }
616 
617  return bytes_sent;
618 }
619 
621 {
622  {
623  boost::mutex::scoped_lock lock(close_mutex_);
624 
625  if (closed_)
626  {
627  return;
628  }
629  }
630 
631  if (!expecting_read_)
632  {
633  poll_set_->addEvents(sock_, POLLIN);
634  expecting_read_ = true;
635  }
636 }
637 
639 {
641 
642  {
643  boost::mutex::scoped_lock lock(close_mutex_);
644 
645  if (closed_)
646  {
647  return;
648  }
649  }
650 
651  if (expecting_read_)
652  {
653  poll_set_->delEvents(sock_, POLLIN);
654  expecting_read_ = false;
655  }
656 }
657 
659 {
660  {
661  boost::mutex::scoped_lock lock(close_mutex_);
662 
663  if (closed_)
664  {
665  return;
666  }
667  }
668 
669  if (!expecting_write_)
670  {
671  poll_set_->addEvents(sock_, POLLOUT);
672  expecting_write_ = true;
673  }
674 }
675 
677 {
678  {
679  boost::mutex::scoped_lock lock(close_mutex_);
680 
681  if (closed_)
682  {
683  return;
684  }
685  }
686 
687  if (expecting_write_)
688  {
689  poll_set_->delEvents(sock_, POLLOUT);
690  expecting_write_ = false;
691  }
692 }
693 
694 TransportUDPPtr TransportUDP::createOutgoing(std::string host, int port, int connection_id, int max_datagram_size)
695 {
697 
698  TransportUDPPtr transport(boost::make_shared<TransportUDP>(poll_set_, flags_, max_datagram_size));
699  if (!transport->connect(host, port, connection_id))
700  {
701  ROS_ERROR("Failed to create outgoing connection");
702  return TransportUDPPtr();
703  }
704  return transport;
705 
706 }
707 
709 {
711 
712  sockaddr_storage sas;
713  socklen_t sas_len = sizeof(sas);
714  getpeername(sock_, (sockaddr *)&sas, &sas_len);
715 
716  sockaddr_in *sin = (sockaddr_in *)&sas;
717 
718  char namebuf[128] = {};
719  int port = ntohs(sin->sin_port);
720  strncpy(namebuf, inet_ntoa(sin->sin_addr), sizeof(namebuf)-1);
721 
722  std::string ip = namebuf;
723  std::stringstream uri;
724  uri << ip << ":" << port;
725 
726  return uri.str();
727 }
728 
729 }
ros::TransportUDP::getTransportInfo
virtual std::string getTransportInfo()
Returns a string description of both the type of transport and who the transport is connected to.
Definition: transport_udp.cpp:144
ros::TransportUDP::flags_
int flags_
Definition: transport_udp.h:155
ros::PollSet::delSocket
bool delSocket(int sock)
Delete a socket.
Definition: poll_set.cpp:94
ros::TransportUDP::data_start_
uint8_t * data_start_
Definition: transport_udp.h:165
boost::shared_ptr< TransportUDP >
ros::TransportUDP::enableRead
virtual void enableRead()
Enable reading on this transport. Allows derived classes to, for example, enable read polling for asy...
Definition: transport_udp.cpp:620
ros::TransportUDP::read
virtual int32_t read(uint8_t *buffer, uint32_t size)
Read a number of bytes into the supplied buffer. Not guaranteed to actually read that number of bytes...
Definition: transport_udp.cpp:351
ros
ros::TransportUDPHeader
Definition: transport_udp.h:57
ros::TransportUDP::server_port_
int server_port_
Definition: transport_udp.h:149
ros::TransportUDPPtr
boost::shared_ptr< TransportUDP > TransportUDPPtr
Definition: forwards.h:60
ros::TransportUDP::local_port_
int local_port_
Definition: transport_udp.h:150
ros::Transport::write_cb_
Callback write_cb_
Definition: transport.h:137
ros::TransportUDP::reorder_header_
TransportUDPHeader reorder_header_
Definition: transport_udp.h:170
ros::TransportUDP::setSocket
bool setSocket(int sock)
Set the socket to be used by this transport.
Definition: transport_udp.cpp:99
ros::PollSet::addEvents
bool addEvents(int sock, int events)
Add events to be polled on a socket.
Definition: poll_set.cpp:126
ROS_UDP_DATAN
#define ROS_UDP_DATAN
Definition: transport_udp.h:54
ros::TransportUDP::expecting_read_
bool expecting_read_
Definition: transport_udp.h:143
poll_set.h
ros::TransportUDP::~TransportUDP
virtual ~TransportUDP()
Definition: transport_udp.cpp:92
ros::TransportUDP::max_datagram_size_
uint32_t max_datagram_size_
Definition: transport_udp.h:162
ros::PollSet::addSocket
bool addSocket(int sock, const SocketUpdateFunc &update_func, const TransportPtr &transport=TransportPtr())
Add a socket.
Definition: poll_set.cpp:66
ros::TransportUDP::reorder_start_
uint8_t * reorder_start_
Definition: transport_udp.h:169
ros::TransportUDP::SYNCHRONOUS
@ SYNCHRONOUS
Definition: transport_udp.h:72
ros::Transport::Callback
boost::function< void(const TransportPtr &)> Callback
Definition: transport.h:105
ros::TransportUDP::createIncoming
bool createIncoming(int port, bool is_server)
Start a server socket and listen on a port.
Definition: transport_udp.cpp:242
ros::TransportUDP::reorder_bytes_
uint32_t reorder_bytes_
Definition: transport_udp.h:171
ros::TransportUDP::initializeSocket
bool initializeSocket()
Initializes the assigned socket – sets it to non-blocking and enables reading.
Definition: transport_udp.cpp:280
ROS_DEBUG
#define ROS_DEBUG(...)
ros::TransportUDP::last_block_
uint16_t last_block_
Definition: transport_udp.h:160
ros::TransportUDP::close_mutex_
boost::mutex close_mutex_
Definition: transport_udp.h:141
transport_udp.h
ros::TransportUDP::getClientURI
std::string getClientURI()
Returns the URI of the remote host.
Definition: transport_udp.cpp:708
ros::TransportUDP::disableRead
virtual void disableRead()
Disable reading on this transport. Allows derived classes to, for example, disable read polling for a...
Definition: transport_udp.cpp:638
ros::TransportUDP::createOutgoing
TransportUDPPtr createOutgoing(std::string host, int port, int conn_id, int max_datagram_size)
Create a connection to a server socket.
Definition: transport_udp.cpp:694
ROS_UDP_DATA0
#define ROS_UDP_DATA0
Definition: transport_udp.h:53
ros::TransportUDP::connection_id_
uint32_t connection_id_
Definition: transport_udp.h:157
ros::TransportUDP::socketUpdate
void socketUpdate(int events)
Definition: transport_udp.cpp:105
ROS_ASSERT_MSG
#define ROS_ASSERT_MSG(cond,...)
ros::TransportUDP::sock_
socket_fd_t sock_
Definition: transport_udp.h:139
ros::Transport::isOnlyLocalhostAllowed
bool isOnlyLocalhostAllowed() const
returns true if this transport is only allowed to talk to localhost
Definition: transport.h:147
ros::TransportUDP::connect
bool connect(const std::string &host, int port, int conn_id)
Connect to a remote host.
Definition: transport_udp.cpp:151
ros::TransportUDP::local_address_
sockaddr_in local_address_
Definition: transport_udp.h:148
ros::TransportUDP::poll_set_
PollSet * poll_set_
Definition: transport_udp.h:154
ros::PollSet::delEvents
bool delEvents(int sock, int events)
Delete events to be polled on a socket.
Definition: poll_set.cpp:148
ros::TransportUDP::data_buffer_
uint8_t * data_buffer_
Definition: transport_udp.h:164
ros::TransportUDP::enableWrite
virtual void enableWrite()
Enable writing on this transport. Allows derived classes to, for example, enable write polling for as...
Definition: transport_udp.cpp:658
ros::last_socket_error_is_would_block
ROSCPP_DECL bool last_socket_error_is_would_block()
Definition: io.cpp:98
ros::TransportUDP::reorder_buffer_
uint8_t * reorder_buffer_
Definition: transport_udp.h:168
ros::TransportUDP::cached_remote_host_
std::string cached_remote_host_
Definition: transport_udp.h:152
ros::close_socket
ROSCPP_DECL int close_socket(socket_fd_t &socket)
Close the socket.
Definition: io.cpp:524
ros::TransportUDP::is_server_
bool is_server_
Definition: transport_udp.h:146
ros::Transport::isHostAllowed
bool isHostAllowed(const std::string &host) const
returns true if the transport is allowed to connect to the host passed to it.
Definition: transport.cpp:111
ros::TransportUDP::TransportUDP
TransportUDP(PollSet *poll_set, int flags=0, int max_datagram_size=0)
Definition: transport_udp.cpp:62
ROS_ERROR
#define ROS_ERROR(...)
ros::TransportUDP::closed_
bool closed_
Definition: transport_udp.h:140
ros::TransportUDP::expecting_write_
bool expecting_write_
Definition: transport_udp.h:144
ROS_INVALID_SOCKET
#define ROS_INVALID_SOCKET
Definition: io.h:107
ros::Transport::disconnect_cb_
Callback disconnect_cb_
Definition: transport.h:135
ros::TransportUDP::close
virtual void close()
Close this transport. Once this call has returned, writing on this transport should always return an ...
Definition: transport_udp.cpp:307
ros::TransportUDP::disableWrite
virtual void disableWrite()
Disable writing on this transport. Allows derived classes to, for example, disable write polling for ...
Definition: transport_udp.cpp:676
header
const std::string header
assert.h
ros::TransportUDP::write
virtual int32_t write(uint8_t *buffer, uint32_t size)
Write a number of bytes from the supplied buffer. Not guaranteed to actually write that number of byt...
Definition: transport_udp.cpp:530
ROS_ASSERT
#define ROS_ASSERT(cond)
ros::Transport::read_cb_
Callback read_cb_
Definition: transport.h:136
ros::set_non_blocking
ROSCPP_DECL int set_non_blocking(socket_fd_t &socket)
Definition: io.cpp:503
ROSCPP_LOG_DEBUG
#define ROSCPP_LOG_DEBUG(...)
Definition: file_log.h:35
ros::TransportUDPHeader
struct ros::TransportUDPHeader TransportUDPHeader
ros::last_socket_error_string
const ROSCPP_DECL char * last_socket_error_string()
Definition: io.cpp:90
ros::TransportUDP::server_address_
sockaddr_in server_address_
Definition: transport_udp.h:147
ros::PollSet
Manages a set of sockets being polled through the poll() function call.
Definition: poll_set.h:57
ros::TransportUDP::current_message_id_
uint8_t current_message_id_
Definition: transport_udp.h:158
file_log.h
ros::TransportUDP::data_filled_
uint32_t data_filled_
Definition: transport_udp.h:166
ros::TransportUDP::total_blocks_
uint16_t total_blocks_
Definition: transport_udp.h:159


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