-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On 18/11/13 20:55, Paul Colomiets wrote: > You have same error here. You almost certainly never want to get > the value on the stack in asynchronous loop, since return from this > code causes pointer to be invalidated. Your code makes sense only > when you do a single/multiple requests without falling back to the > main loop. And in this case you almost certainly want the cancel > callback, so you can cancel request before ``return``ing this > function (e.g. in case of some error between nn_send and nn_recv) It was just a quick and dirty example, don't take it too seriously :) >>> 2. How to know that request is timed out? >>> >>> rc = nn_req_recv(s, &context, buf, sizeof(buf), 0); if(rc < 0 >>> && errno == ETIMEDOUT) { printf("request %d timed out\n", >>> *context); } >>> >>> Is it ok that context is filled even if error code received? >>> Probably only certain errors will have request id filled in? >> >> Looks ugly, but it's technically viable. >> > > kinda, yes > >> The other option, of course, is not to have timeouts and let the >> use cancel the requests: >> >> nn_req_cancel (s, &context1); >> > > That would: > > 1. require every user to implement timeout management > > 2. will leak memory since many users will forget about that > > The #1 is likely be easy when using some async main loop. But is > ugly when you have a blocking code which just run multiple > requests simultaneously. > > I.e. I'm almost certain that both timeout and cancel are needed. Yes, I think you are right. Martin -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.11 (GNU/Linux) Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/ iQEcBAEBAgAGBQJSinGrAAoJENTpVjxCNN9Ynw4H/0Ng5PxCTqneM6x5tAXvfAaX Eu/95NQbw8Ge7ZZY+93JXzNaWlLCbNKrFTCjA2m7HnJVil7F6uXQOfZvaSaEu4dP mRzYKuQekkqzQF9b63lDl0rgoPX23YoO7ieSfpJ/DpJ8XhbdrA1aqwcXvmMTJY8u gs+QtsU5p37p873DUCV6zkyufVq0hDqqcjl+BaUa2h3z21zIXXg7KPQbGBor12zt loSxP5lMik7pf7nmoKYLsCT/F4Sy+vYHJbrm4JA5OAbv46PYDA1lqFacQwvBZnsf sIuEdDRmktU55Mxh+jDBoFZ7Ghh+r8F7VfUz1Kv034i2wUu4BO6+6sV0cnl6irw= =94ay -----END PGP SIGNATURE-----