Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to retrieve boost asio socket file descriptor

Tags:

sockets

boost

I am using boost asio to develop a tcp server process which listens for client connections. The clients are expected to send partial packets. Server process can't process the packet until it receives the entire packet from the client (header,data and footer).

In order to handle partial packets, server process needs to push the packets( or partial packets) from each client connection to a queue. Server would maintain a queue per client connection.

Now my question is how to get a socket file descriptor when using boost asio. I am planning to use the integer value from socket file descriptor and create a std::map container that handles queue per client connection.

std::map< int, std::deque< std::string >

If retrieving socket file descriptor is not feasible what could be the alternatives for optimal performance. Do I need to use

std::map< tcp::socket *,std::deque< std::string> > ?

Thanks in advance.

like image 883
Rak Avatar asked Aug 14 '12 21:08

Rak


1 Answers

There's the basic_socket::native_handle() member function inherited by the socket classes, but you should really consider @David's answer.

like image 168
Nikolai Fetissov Avatar answered Oct 21 '22 06:10

Nikolai Fetissov