bool TransportTCP::initializeSocket() { ROS_ASSERT(sock_ != ROS_INVALID_SOCKET); if (!setNonBlocking()) { return false; } setKeepAlive(s_use_keepalive_, 60, 10, 9); // connect() will set cached_remote_host_ because it already has the host/port available if (cached_remote_host_.empty()) { if (is_server_) { cached_remote_host_ = "TCPServer Socket"; } else { std::stringstream ss; ss << getClientURI() << " on socket " << sock_; cached_remote_host_ = ss.str(); } } if (local_port_ < 0) { la_len_ = s_use_ipv6_ ? sizeof(sockaddr_in6) : sizeof(sockaddr_in); getsockname(sock_, (sockaddr *)&local_address_, &la_len_); switch (local_address_.ss_family) { case AF_INET: local_port_ = ntohs(((sockaddr_in *)&local_address_)->sin_port); break; case AF_INET6: local_port_ = ntohs(((sockaddr_in6 *)&local_address_)->sin6_port); break; } } #ifdef ROSCPP_USE_TCP_NODELAY setNoDelay(true); #endif ROS_ASSERT(poll_set_ || (flags_ & SYNCHRONOUS)); if (poll_set_) { ROS_DEBUG("Adding tcp socket [%d] to pollset", sock_); poll_set_->addSocket(sock_, boost::bind(&TransportTCP::socketUpdate, this, _1), shared_from_this()); } if (!(flags_ & SYNCHRONOUS)) { //enableRead(); } return true; }
bool TransportTCP::initializeSocket() { ROS_ASSERT(sock_ != ROS_INVALID_SOCKET); if (!setNonBlocking()) { return false; } setKeepAlive(s_use_keepalive_, 60, 10, 9); // connect() will set cached_remote_host_ because it already has the host/port available if (cached_remote_host_.empty()) { if (is_server_) { cached_remote_host_ = "TCPServer Socket"; } else { std::stringstream ss; ss << getClientURI() << " on socket " << sock_; cached_remote_host_ = ss.str(); } } #ifdef ROSCPP_USE_TCP_NODELAY setNoDelay(true); #endif ROS_ASSERT(poll_set_ || (flags_ & SYNCHRONOUS)); if (poll_set_) { ROS_DEBUG("Adding tcp socket [%d] to pollset", sock_); poll_set_->addSocket(sock_, boost::bind(&TransportTCP::socketUpdate, this, _1), shared_from_this()); } if (!(flags_ & SYNCHRONOUS)) { //enableRead(); } return true; }