[nanomsg] Re: two questions about nanomsg

  • From: Martin Sustrik <sustrik@xxxxxxxxxx>
  • To: Niek <nieka@xxxxxx>
  • Date: Wed, 18 Dec 2013 07:27:06 +0100

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi Niek,

> I'm working on a small long polling webserver that uses
> libmicrohttpd and nanomsg to commicate with workers. The webserver
> uses a thread pool to handle requests and sends them to an internal
> socket that has workers connected and passes content back and
> forward. Workers connect to the REQ socket and can scale up. Please
> look at the attached image.
> 
> I have two questions, I'm using a nn_device to connect the internal
> socket to the listening socket for the workers.
> 
> - I see in the sourcecode of nanomsg that the sockets for a
> nn_device need to be of the same protocol. Is this really
> necessary? I'd like to connect an inproc socket to a tcp socket and
> use that as a device.

You are confusing transports and protocols. "tcp" and "inproc" are
transports. "Request/reply" or "publish/subscribe" are scalability
protocols. The device requires both sockets to belong to the same
scalability protocol. It makes no assumptions about underlying
transports. Thus, everything should work OK in your use case.

> - The client threads are a pool that handle incoming requests. When
> waiting for an answer from one of the workers I can tell microhttpd
> to suspend the request handler from the event loop so it can handle
> other requests. I'd like to be able to re-enable this handler when
> an answer from a worker arrives. So a callback for the nn_device
> when a message is transmitted would be nice. something like:
> 
> nn_device(sock1, sock2, callback);
> 
> void callback(from, to, msg) { ... };
> 
> where callback is called everytime something happens.

What does "transmitted" mean? Does it mean that nanomsg takes
resposibility for the message and guarantee that an reply will arrive
in the future. That happens directly in the nn_send() is executed. No
need for asynchronous callback.

Martin
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/

iQEcBAEBAgAGBQJSsUA6AAoJENTpVjxCNN9YQawH/2mkaGG7iITdZBv4CfcPZF5K
CQ+ZPgEQCyqkTD13trnA+9Kj3OhvCpNvbQjiLzu1hriqGD8Cno4evhedS19A45/m
QCbrCxcMJMmQOQg9knsFnf5R+FqMag8mxaYtyyn0+8p5p1N0Ok8e6ceFYDdw9Tce
1ubsu7bi4o1QxkFv9Lqn3dIqa1zWq9XzIXe0IjPu60drhuEMhsGoXmw9+ZSjm65t
+HRDKZvNS/ngl4ZgYDle+832bYOTuOzwYwL6GbuhGBDMF9sITBjxEvty9cZ+hGhK
vFmsGa0FcOLW235GVep/aI3YsRLG8wgOI10YbF2QHMEvQwDmw+GsBMBqXaFescs=
=XRhE
-----END PGP SIGNATURE-----

Other related posts:

  • » [nanomsg] Re: two questions about nanomsg - Martin Sustrik