Example #1
0
    void Listener<SocketType>::BeginAccept()
    {
        NetworkThread<SocketType> *worker = SelectWorker();
        SocketType *socket = worker->CreateSocket();

        m_acceptor.async_accept(socket->GetAsioSocket(), [this,worker,socket](const boost::system::error_code &ec) { this->OnAccept(worker, socket, ec); });
    }
Example #2
0
void Node::copy_value(const SocketType& socket, const Node& other, const SocketType& other_socket)
{
	assert(socket.type == other_socket.type);

	if(socket.is_array()) {
		switch(socket.type) {
			case SocketType::BOOLEAN_ARRAY: copy_array<bool>(this, socket, &other, other_socket); break;
			case SocketType::FLOAT_ARRAY: copy_array<float>(this, socket, &other, other_socket); break;
			case SocketType::INT_ARRAY: copy_array<int>(this, socket, &other, other_socket); break;
			case SocketType::COLOR_ARRAY: copy_array<float3>(this, socket, &other, other_socket); break;
			case SocketType::VECTOR_ARRAY: copy_array<float3>(this, socket, &other, other_socket); break;
			case SocketType::POINT_ARRAY: copy_array<float3>(this, socket, &other, other_socket); break;
			case SocketType::NORMAL_ARRAY: copy_array<float3>(this, socket, &other, other_socket); break;
			case SocketType::POINT2_ARRAY: copy_array<float2>(this, socket, &other, other_socket); break;
			case SocketType::STRING_ARRAY: copy_array<ustring>(this, socket, &other, other_socket); break;
			case SocketType::TRANSFORM_ARRAY: copy_array<Transform>(this, socket, &other, other_socket); break;
			case SocketType::NODE_ARRAY: copy_array<void*>(this, socket, &other, other_socket); break;
			default: assert(0); break;
		}
	}
	else {
		const void *src = ((char*)&other) + other_socket.struct_offset;
		void *dst = ((char*)this) + socket.struct_offset;
		memcpy(dst, src, socket.size());
	}
}
Example #3
0
 void accept( AcceptorType& acc, SocketType& sock ) {
     promise<boost::system::error_code>::ptr p( new promise<boost::system::error_code>("fc::asio::tcp::accept") );
     acc.async_accept( sock, boost::bind( fc::asio::detail::error_handler, p, _1 ) );
     auto ec = p->wait();
     if( !ec ) sock.non_blocking(true);
     if( ec ) BOOST_THROW_EXCEPTION( boost::system::system_error(ec) );
 }
Example #4
0
 void Connector::start_connect(
     SocketType & peer, 
     Endpoint const & ep, 
     boost::system::error_code & ec)
 {
     if (!non_block_ && time_out_) {
         boost::asio::socket_base::non_blocking_io cmd(true);
         peer.io_control(cmd, ec);
         if (ec)
             return;
     }
     if (!connect_started_) {
         connect_started_ = true;
         peer.connect(ep, ec);
     }
     if ((ec == boost::asio::error::in_progress || 
         ec == boost::asio::error::already_started)) {
             ec = boost::asio::error::would_block;
     }
 }
Example #5
0
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());
        }
    }
}
Example #6
0
 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;
         }
     }
 }
Example #7
0
 void Connector::post_connect(
     SocketType & peer, 
     boost::system::error_code & ec)
 {
     if (!non_block_ && time_out_) {
         boost::asio::socket_base::non_blocking_io cmd(false);
         boost::system::error_code ec1;
         peer.io_control(cmd, ec1);
     }
     // support non-blocking mode
     if (ec == boost::asio::error::in_progress || 
         ec == boost::asio::error::already_started || 
         ec == boost::asio::error::would_block) {
             ec = boost::asio::error::would_block;
     } else if (ec == boost::asio::error::already_connected) {
         ec = boost::system::error_code();
     } else {
         connect_started_ = false;
     }
 }
Example #8
0
static void value_hash(const Node *node, const SocketType& socket, MD5Hash& md5)
{
	md5.append(((uint8_t*)node) + socket.struct_offset, socket.size());
}
Example #9
0
void Node::set_default_value(const SocketType& socket)
{
	const void *src = socket.default_value;
	void *dst = ((char*)this) + socket.struct_offset;
	memcpy(dst, src, socket.size());
}
Example #10
0
bool Node::has_default_value(const SocketType& input) const
{
	const void *src = input.default_value;
	void *dst = &get_socket_value<char>(this, input);
	return memcmp(dst, src, input.size()) == 0;
}