Boost logo

Boost Users :

From: Christopher Kohlhoff (chris_at_[hidden])
Date: 2006-10-18 19:28:35


Hi Christian,

Christian Henning writes:
> Hi there, I have been using ASIO for some weeks, now. I really
> like the lib and have made good progress. Even though the
> learning curve was quite steep for me. I have never really
> programmed networking code. So please excuse my most likely
> dumb questions. The reason why I ask is to get to know the lib
> better and try to avoid adding code on my side for stuff I can
> simply poll from the lib.
>
> 1. [server side] Are errors the only way to get notice when a
> client disconnects.

Yes.

> 2. [server side] How can I poll if a server is connected to a
> client.

Basically, socket state changes (like connection establishment
and termination) occur asynchronously to program code, and in
fact if you're using the asynchronous operations it's possible
for the state change notification to be delivered after the
socket object has been destroyed. In that model, polling for
the connection state doesn't make sense.

If you need the ability to "poll" then I would recommend that
you store the current state (as of the most recent error code)
in a variable, and then check that variable. Calling
remote_endpoint() should also work, but it's not really intended
for that use.

> 3. I have been asking questions regarding asio for some time
> now and never gotten any answer. Is the boost user list the
> right forum? For example yesterday I posted a message for a
> memory leaks reported by MFC and nobody replied, so far.

Yeah, sorry about that. I only have a limited amount of time to
spend on asio, and (until yesterday) virtually all of that time
has been devoted to things that have fixed deadlines (namely TR2
proposal work).

> 4. [server side] When running io_service::run() on a separate
> thread, is io_service::interrupt() the only way to let
> ioservice return from run(). Basically what do I need to do to
> gracefully quite my server app when there are still clients
> connected. Same questions goes for the client apps.

There are basically two options:

- Use io_service::interrupt(). All copies of unfinished handlers
  will be destroyed when the io_service object is destroyed. If
  you bind shared_ptrs and the like into your handlers then they
  will be destroyed and the objects they point to will be
  deleted.

- Track all connection objects and close() the sockets to cancel
  the unfinished operations. Once the handlers for all
  operations have run the io_service will run out of work and
  the io_service::run() call will exit. The HTTP server example
  takes this approach.

> 5. [client side] When I quite the client app (MFC) I get a lot
> of these error message: "The I/O operation has been aborted
> because of either a thread exit or an application request". I
> seems for every message I send to the server I got one of this
> error. I use io_service::post() to initiate a send operation.

I'm guessing that these are messages in the debug output window
-- is that right? On windows, if the thread that initiates an
asynchronous operation terminates before the operation is
complete, then the operation will be aborted with that error. I
suspect that this message is harmless (although annoying), but
it would be good if you could send me a sample program so that I
can confirm that.

Cheers,
Chris


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