Boost logo

Boost Users :

Subject: Re: [Boost-users] ASIO - Using IO service from main program in a .so loaded with dlopen, dlsym, etc.
From: J.W.F. Thirion (derik_at_[hidden])
Date: 2009-08-29 13:55:22


Hi there,

Thanks. Let me expand a little here:

I have a communication library, called libcomm. It has a session class
that sends and receives messages on the socket (reads into a queue and
writes from a queue). Users of the class simply call readMessage and
writeMessage to access the queues and the library takes care of
everything else. It also provides a connect function to connect to a
remote server. In this class, I have all of the handleResolve,
handleConnect, handleRead, handleWrite, etc. handlers. The session class
inherits from enable_shared_from_this and makes use of shared_ptrs to
make sure the object doesn't go out of scope with handlers outstanding.
I also have a server class in this library that implements all of the
functionality such as accepting connections, handleAccept, etc. A newly
accepted connection results in a session object (which holds the
underlying tcp socket). This appears to work correctly. The libcomm
library is a libtool convenience library.

I have linked the communication library statically into my main server
program (that makes use of a server class in libcomm). I've also linked
the library statically into my shared object, lets call it
application.so.

I am able to open (with dlopen) and load the main function in
application.so with dlsym, I can even execute the main function in
the .so. So in other words, I am able to resolve the symbol name in the
shared object correctly. My main server program passes the session
object from the server's accepted "session"/connection to the main
function in the shared object application.so.

Now I am able to continue reading /writing messages and have the
handleRead and handleWrite on the session called through calls to
async_read, etc. in libcomm from the shared object. It is just that new
sessions created inside the shared object fails to have the
handleConnect called.

Hope this makes sense.

Thanks for the help!
Derik

On Sat, 2009-08-29 at 13:53 +0100, Bruce Simpson wrote:
> J.W.F. Thirion wrote:
> > Interesting thing is that I can actually pass a session object (from the
> > socket server accept operation) from my main program to the .so function
> > and have messages read and written on the socket. But when I try and
> > create a new connection using the session's IO service (e.g. from a
> > sock.get_io_service() call), then I never get the handle_connect.
> >
>
> Does your main program export dynamic symbols (--export-dynamic in GNU
> ld) ? see here:
> http://www.nondot.org/~sabre/Mirrored/libtool-2.1a/libtool_9.html
>
> If for whatever reason the dynamically loaded code needs to resolve a
> symbol at runtime, and this has not been exported by your main program,
> I would expect the code to either be terminated with a runtime linker
> exception, or fail silently.
> _______________________________________________
> Boost-users mailing list
> Boost-users_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users


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