Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Release a socket in Boost.Asio (opposite of assign), or don't transfer ownership

There is a function assign in Boost.Asio sockets, however I'm looking for something like

  • release/unassign that would transfer the ownership on socket back to user.

or

  • some type of assign that would not transfer ownership to socket class, so it would not close it when destroyed.

I'm aware of this solution but it involves duplicating socket (i.e. creating new descriptor rather then releasing one).

Does anybody knows how can this be done?

Edit: There is no such feature, opened ticket for Boost.Asio https://svn.boost.org/trac/boost/ticket/3900

like image 903
Artyom Avatar asked Jan 31 '10 10:01

Artyom


2 Answers

I couldn't find any such way in the .hpp files (Boost 1.35), so I think you'll have to patch ASIO yourself and add a release() method. When done, you could keep the patch for yourself, post it on your website (or here), or submit it back to Boost.

Do try the Boost mailing lists. The people there might tell you whether such a method is a good or bad idea, and why. If you find anything interesting there, please post a summary here.

BTW: Boost 1.42 was released yesterday.

like image 195
sverkerw Avatar answered Nov 05 '22 13:11

sverkerw


I've accomplished this in the past by using the dup system call to create another file descriptor.

int fd = dup( old_fd )

socket.assign( ... fd )

It obviously does not have the same semantics as releasing the descriptor, but it works well when you need to layer Boost.Asio above or below an existing layer that assumes descriptor ownership.

like image 1
Sam Miller Avatar answered Nov 05 '22 15:11

Sam Miller