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

Feature request to expose errno #27

Closed
hertzg opened this issue Apr 12, 2024 · 2 comments
Closed

Feature request to expose errno #27

hertzg opened this issue Apr 12, 2024 · 2 comments
Labels
enhancement New feature or request

Comments

@hertzg
Copy link

hertzg commented Apr 12, 2024

Hello following our short conversation in #22 I'm creating a separate issue to expose errno.

Summary

Some syscall functions like setsockopt and simiar return -1 but set the errno to actual error.
Currently there's no way to access this errno value. ffi-napi exposes this via FFI.errno() function call.

Motivation

Since node v20.12.x broke ffi-napi and it seems like ffi-napi is not supported, I'm trying to migrate net-keepalive to ffi-rs one of the blockers is the lack of errno. Without it we can't provide clear enough error message on why setsockopt failed.

References:

@zhangyuang
Copy link
Owner

zhangyuang commented Apr 14, 2024

Support errno in [email protected]

By default, ffi-rs will not output errno info, developers can get it by pass errno: true when call load method like

 const foo = load({
    library: 'libnative',
    funcName: 'setsockopt',
    retType: DataType.I32,
    paramsType: [DataType.I32, DataType.I32, DataType.I32, DataType.External, DataType.I32],
    paramsValue: [socket._handle.fd, level, option, pointer[0], 4],
    errno: true // set errno as true
  })
// The above code will return a object include three fields include errnoCode, errnoMessage, and the foreign function return value
  // { errnoCode: 22, errnoMessage: 'Invalid argument (os error 22)', value: -1 }

@hertzg
Copy link
Author

hertzg commented Apr 15, 2024

Seems to be working like a charm 👍. Resolved. Thank you!

@hertzg hertzg closed this as completed Apr 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants