[nanomsg] Re: [Non-DoD Source] async aio framework exposed to apps in nng

  • From: "Garrett D'Amore" <garrett@xxxxxxxxxx>
  • To: nanomsg@xxxxxxxxxxxxx
  • Date: Thu, 26 Oct 2017 14:41:18 +0000

A given aio has only one outstanding operation on it.  A socket can have
many outstanding aios.  Traffic will “probably” be handled in the order of
submission (generally the implementations use a FIFO to manage multiple
aios), but there is no guarantee of ordered delivery anywhere in nng.

The reason for this is that devices break streams, and if you have a
device, messages may be played on different streams, totally breaking the
order.  Also different TCP flows (associated with a single socket) may have
different flow rates, resulting in misordered delivery.

For a given socket/application flow, you can order your message submissions
by using the same aio — the completion callback is used to queue up the
next message, and so forth.  This does slow things down slightly, since you
introduce some inter-message latency that multiple parallel submissions
would not.  It’s up to the app to decide which strategy works best for it.

(We do guarantee that messages are treated atomically though — a message
either arrives entirely and with all its bytes in order, or not at all.)

 - Garrett

On Thu, Oct 26, 2017 at 6:36 AM Karan, Cem F CIV USARMY RDECOM ARL (US) <
cem.f.karan.civ@xxxxxxxx> wrote:

Nice!  Quick question; are messages always sent in the same order as they
were queued up by the AIO interface?

Thanks,
Cem Karan

---
Other than quoted laws, regulations or officially published policies, the
views expressed herein are not intended to be used as an authoritative
state of the law nor do they reflect official positions of the U.S. Army,
Department of Defense or U.S. Government.


-----Original Message-----
From: nanomsg-bounce@xxxxxxxxxxxxx [mailto:nanomsg-bounce@xxxxxxxxxxxxx]
On Behalf Of Garrett D'Amore
Sent: Wednesday, October 25, 2017 9:44 PM
To: nanomsg@xxxxxxxxxxxxx
Subject: [Non-DoD Source] [nanomsg] async aio framework exposed to apps
in nng

(This is only for nng, not available for legacy nanomsg.)

I just pushed nng bug #45.  This changes the API.  The old event
callback scheme is removed (it was pretty horrible actually), and I’m
exposing an “aio” framework.

The way aio’s work is that you allocate one (it’s like a handle) with a
completion callback and a user supplied argument for the callback.

Then you can submit operations and get notified when they are complete
later.  You can also wait on them to be complete.

E.g:

```
nng_aio *a;
void mycallback(void *);
void *myarg;

nng_aio_alloc(&a, mycallback, myarg);
nng_aio_set_timeout (a, 100);
nng_aio_set_message (a, msg);

nng_send_aio(s, a);

… asynchronously the message is sent, and the mycallback is executed.
… it can read the aio result via nng_aio_result (a);

Operations can also be canceled with nng_aio_cancel().

You can then do nng_aio_wait(a).

The details are for now in the nng.h header file.

Note that this is largely the same stuff I’m using *internally* in nng.
I figured that it was so useful to me that folks building other kinds of
async apps could use it.  For example, this could be used to integrate
into an event loop or drive state machine transitions, etc.

Anyway, not sure how many of you might be poking at nng these days, but
this was the major API change that I wanted to get through
before declaring a broader beta release.  I’d appreciate folks bang away
at this.

I’m still going to try to get websocket and TLS support knocked out
before *formal* beta. Oh, and I need to write a lot more docs. :-)

Enjoy!

 - Garrett


Other related posts: