Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Binding not compatible with latest nanomsg (0.8-beta) #14

Open
stepelu opened this issue Dec 14, 2015 · 4 comments
Open

Binding not compatible with latest nanomsg (0.8-beta) #14

stepelu opened this issue Dec 14, 2015 · 4 comments

Comments

@stepelu
Copy link

stepelu commented Dec 14, 2015

As noted here:
nanomsg/nanomsg#389 (comment)
this binding should be upgraded to the latest version of libnanomsg.
As of now, the binding does not load (the version check in the code fails).

@neomantra
Copy link
Contributor

Hello, I don't use nanomsg anymore, but I just reviewed things and it seems like the public interface only changed in adding a few function (nn_tcpmuxd, nn_poll, and nn_reallocmsg).

So, most of the binding should still work. Try changing this line
to be: if (nn.VERSION_CURRENT - nn.VERSION_AGE) == 4 then

If you have some success, then I can add that change and some of the missing functions.

@stepelu
Copy link
Author

stepelu commented Jan 15, 2016

Yes, I tested it and it seems to be working, I would suggest to incorporate the proposed change.

I also have the following feedback / suggestions:

  1. I would rename send_zc and recv_zc to sendzc and recvzc: all other functions of the module adhere to the Lua convention of no CamelCase and no underscores
  2. I don't understand why only recv_zc does not special-case EAGAIN (all other send/recv functions return -1 for that)
  3. For ease of use, I would add a nanomsg assert and a send/recv pair for standard Lua strings among the following lines:
-- Helper function, behaves like standard assert() for nanomsg
function nn.assert(x, err)
  if not x then
    error(nn.strerror(err))
  end
  return x
end

sendstr = function(s, msg, flags)
    return s:send(msg, #msg, flags)
end,

-- Needs adjustment if recv_zc is changed wrt. EAGAIN.
recvstr = function(s, flags)
  local nnmsg, err = s:recv_zc(flags)
  if not nnmsg then return nil, err end
  local msg = nnmsg:tostring()
  nnmsg:free()
  return msg
end,

Let me know your thoughts.

@stepelu
Copy link
Author

stepelu commented Jan 15, 2016

Thinking about it a bit more, I would probably avoid the EAGAIN special casing completely.

As the "error" code is returned (instead of an error string) it seems to me that this way the library code would be simplified while similar amount of code is required from the user in both scenarios to distinguish between EAGAIN, errors and succesful execution.

@neomantra
Copy link
Contributor

  1. I don't have an opinion, I've seen a variety of ways in the Lua world. If you submit an isolated changeset that makes this change and updates the tests/examples, then I would accept it. But, I would like it to be in a series of changesets that also bumps the nanomsg version bump.
  2. I actually can't exactly remember why I did that. Maybe to differentiate an actual error versus an error because of EAGAIN (which isn't an error, just a busy). But that can be handled at a higher level, I'm OK with that. Pull request would be accepted with the same caveat as above (test/example changes)
  3. Given (2), probably doesn't need to be addressed.

Thanks for your thoughts and an pull requests that come.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants