[nanomsg] mangos has a compatibility shim

  • From: Garrett D'Amore <garrett@xxxxxxxxxx>
  • To: nanomsg@xxxxxxxxxxxxx
  • Date: Sun, 11 May 2014 17:37:43 -0700

I’ve implemented (at user request) bitbucket.org/gdamore/mangos/compat

This implements the most common functionality from op/go-nanomsg in an API 
equivalent way.  This is definitely *not* the preferred way to pick up mangos, 
but it will allow many users to quickly adapt their code to mangos if they 
already have go-nanomsg code.  Basically just import the 
bitbucket.org/gdamore/mangos/compat package (rename it to nanomsg or whatever 
on the import line), and you will probably be good to go.

(This was requested by Jason E. Aten.)

Some functionality is missing:

* PollItem and Poller.  These are really very non-idiomatic interfaces, and 
frankly probably should never be used by native Go code.   Far better to use 
goroutines, select, timeouts (if you need them), and channels.  (Go doesn’t 
support traditional non-blocking I/O, and that is very much a good thing!)   (I 
started to implement these, but realized it was going to be a really crummy and 
non-performant hack.  If you have code following this paradigm, you should 
*really* rewrite it to use channels and select.)

* Quite a few options are missing because they aren’t implemented yet, or have 
no analog.  For example. SendFd() and RecvFd() are non-sensical in this 
context.  In fact, I’d argue that they are largely garbage even for the C code, 
because of the wya nanomsg reschedules I/O.   The things folks are likely to 
miss most are Shutdown() to shut down a specific endpoint, and some of the TCP 
tunables.  (Linger, NoDelay).  Folks that want them, let me know and I’ll 
prioritize accordingly.

The compatibility layer suffers from a nasty performance limitation since it 
has no way to expose message management to applications, so you *have* to pay 
for the garbage collector churn.  This can have big latency implications.  My 
pure Go implementation doesn’t have this problem.  Likewise, I’ve not enabled 
my experimental STAR or the TLS+TCP protocol in the compatibility layer.  If 
you want new stuff, code to the mangos API. :-) 

The compatibility shim is about 500 lines of code, mostly boilerplate and 
stubs, so you can probably easily see how to start writing to the mangos API 
directly. :-)

Btw, while here I fixed one problem, which was that Close() on the socket was 
discarding unsent messages a little too aggressively.  We now wait up to a 
second for data to be delivered to the operating system before doing Close().  
What happens to it after that is up to the OS.  In my testing it generally 
seemed that the default was to deliver it.

Enjoy!

-- 
Garrett D'Amore
Sent with Airmail

Other related posts: