CapsAdmin / luajitsocket

pure luajit ffi socket bindings for unix and windows
MIT License
36 stars 5 forks source link

Add error numbers to failure responses #1

Closed vwout closed 3 years ago

vwout commented 3 years ago

This pull requests extends the failure responses with the actual error code to be able to handle the error based on the error code rather than on the error message. This makes the socket library locale independent.

The response of lasterror() now returns a tuple with the error string and the error number. The error number is added as second, making this backward compatible with existing code. Functions that used to interpret the error string using the timeout_messages dictionary, now use the error number instead.

CapsAdmin commented 3 years ago

Looks alright. Using error codes is probably better than error messages though. I've ran into issues like this with luasocket and windows with different locales I think.

Feel free to make a new pr replacing error strings with codes. Maybe some sort of ljsocket.assert or ljsocket.translate_error function.

vwout commented 3 years ago

Thanks for merging. All functions now return both the error string and the error code. All occasions where luajitsocket handles an error is now done based on the code, so I don't see a reason for a pr right now :) Only reason would be performance, probably, since there is no real need to always return the error string. That however might break existing usage of the library.