コード例 #1
0
ファイル: common_socket.cpp プロジェクト: ska-sa/spead2
static void set_socket_buffer_size(SocketType &socket, std::size_t buffer_size)
{
    if (buffer_size == 0)
        return;
    BufferSizeOption option(buffer_size);
    boost::system::error_code ec;
    socket.set_option(option, ec);
    if (ec)
    {
        log_warning("request for socket buffer size %s failed (%s): refer to documentation for details on increasing buffer size",
                    buffer_size, ec.message());
    }
    else
    {
        // Linux silently clips to the maximum allowed size
        BufferSizeOption actual;
        socket.get_option(actual);
        if (std::size_t(actual.value()) < buffer_size)
        {
            log_warning("requested socket buffer size %d but only received %d: refer to documentation for details on increasing buffer size",
                        buffer_size, actual.value());
        }
    }
}
コード例 #2
0
ファイル: Connector.hpp プロジェクト: huangyt/MyProjects
 void Connector::pool_connect(
     SocketType & peer, 
     boost::system::error_code & ec)
 {
     fd_set writefds;
     fd_set exceptfds;
     timeval timeout;
     FD_ZERO(&writefds);
     FD_ZERO(&exceptfds);
     typename SocketType::native_type fd = peer.native();
     FD_SET(fd, &writefds);
     FD_SET(fd, &exceptfds);
     timeval * ptimeout = &timeout;
     if (non_block_) {
         timeout.tv_sec = 0;
         timeout.tv_usec = 0;
     } else if (time_out_) {
         timeout.tv_sec = time_out_ / 1000;
         timeout.tv_usec = (time_out_ % 1000) * 1000;
     } else {
         ptimeout = NULL;
     }
     int ret = boost::asio::detail::socket_ops::select(
         fd + 1, NULL, &writefds, &exceptfds, ptimeout, ec);
     if (ret > 0) {
         boost::asio::socket_base::error err;
         peer.get_option(err);
         ec = boost::asio::error::basic_errors(err.value());
     } else if (ret == 0) {
         if (non_block_) {
             ec = boost::asio::error::would_block;
         } else {
             ec = boost::asio::error::timed_out;
         }
     }
 }