Boost logo

Boost Users :

From: Matthias Vallentin (vallentin_at_[hidden])
Date: 2008-04-23 04:40:22


Hello,

I would like to incorporate asio into my current project. However, I
am restricted by a library that uses C-style socket descriptors to
identify sockets, e.g. it contains functions similar to

     void foo(int fd, ...)

Right now, I picture write an asio server that merely performs an
asynchronous accept. Thereafter, the start() function in
handle_accept() (see below) would invoke calls to the library such as
foo(fd, ...) and spawn a dedicated thread per client that would gather
data from the socket.

     void Server::handle_accept(const boost::system::error_code& e) {
         if (! e) {
             new_connection_->start();
             new_connection_.reset(new Connection(...)
             //...

In this example, asio would only be used to to handle the accept() and
provide an outside interface to the rest of the application while the
actual read()/write() calls are capsulated in the library.

Is there a way to obtain a native socket descriptor from an
ip::tcp::socket object? I am aware that mixing asio with C-style
networking code totally breaks platform independence and it is
generally a very ugly approach. On the other side, the C-style library
would be capsulated behind one asio Server object, without interacting
with the remaining application code.

I appreciate any input on this issue,

     Matthias

-- 
Matthias Vallentin
vallentin_at_[hidden]
pgp/gpg: 0x37F34C16

Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net