Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detaching a native socket from Boost.ASIO's socket class

Is it possible to detach a native socket from Boost.ASIO's socket class? If so, how can it be done? I can't seem to find anything obvious in the documentation.

As a quick overview of what I'm trying to accomplish: I have a class that makes a connection and does some negotiation using Boost.ASIO, then passes back a native Windows SOCKET on success or 0 on failure.

Unless I'm mistaken, the native socket will be closed and deallocated when my boost::asio::basic_socket is destructed.

like image 911
Collin Dauphinee Avatar asked Jan 11 '10 18:01

Collin Dauphinee


1 Answers

Answering my own question.

Windows has a WSADuplicateSocket function, which can be used to duplicate the native socket. The underlying socket will remain open until all descriptors for this socket are deallocated.

http://msdn.microsoft.com/en-us/library/ms741565(VS.85).aspx

like image 130
Collin Dauphinee Avatar answered Oct 14 '22 03:10

Collin Dauphinee