views:

379

answers:

2

Hello,

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

+2  A: 

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.

sverkerw
A: 

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.

Sam Miller