1

I have a program written using Boost.ASIO. I'm looking for a C++ XMPP client library that could be used with it, that is, a library that already uses Boost.ASIO and that either exposes its internal io_service instance, or that I can initialize with my own existing io_service instance and then just call run() on my io_service.

Apparently Swiften (https://swift.im/swiften.html) uses Boost internally, but I can't find any example on how to get the internal io_service.

Any pointer?

sunmat
  • 6,976
  • 3
  • 28
  • 44
  • What do you _need_ the internal io_service instance for? It's _internal_ for a reason - modularity and encapsulation. Nothing stops you from running your own `io_service` for your own tasks – sehe Mar 13 '16 at 22:50
  • 1
    That would mean setting up 2 threads, which I'd like to avoid. – sunmat Mar 14 '16 at 01:48
  • Do you have rational reasons for not wanting the extra thread? I reckon, if it's not doing much, it's not hurting much. – sehe Mar 14 '16 at 01:49
  • I guess it's doable but would involve quite a lot of changes in the original design of my application. – sunmat Mar 14 '16 at 01:56
  • 2
    How so? The fact that IO operations happen on dedicated threads should not in any way influence the users of those operations. If the XMPP library forces your completion handlers on "their" `io_service` thread, then surely you can post directly onto the `io_service` for your program's logic. `io_service` is thread safe – sehe Mar 14 '16 at 02:01

1 Answers1

2

According some fragments of source code, Swiften uses Boost internally, but not ASIO part of it. It uses things like shared_ptr, boost::bind, random generator and so on, but not the boost::asio.

And according to sources, Swift::EventLoop has io_service-like interface, but not use it.

So the answer is: no, you cannot extract io_service from Swiften since it do not use boost::asio.

UPD: But, you can use Swiften in separate thread in async manner and then do io_service::post to your own eventloop, but need to write our own wrapper, completion handlers and so on to manage this.

Galimov Albert
  • 7,269
  • 1
  • 24
  • 50