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

Request: Return errno from native send() #130

Open
poppfd opened this issue Dec 11, 2023 · 4 comments
Open

Request: Return errno from native send() #130

poppfd opened this issue Dec 11, 2023 · 4 comments

Comments

@poppfd
Copy link

poppfd commented Dec 11, 2023

The RawChannel.send() method returns -1 if the send cannot be completed. Could the method somehow return an object including the errno set by the socket.h -> send() method? Or better yet, return the string parsed by strerror() to translate the errno to the system specific error.

I understand returning an object is less clear than number of bytes or -1. I'm hoping you might have an idea for how to cleanly provide this info.

I was debugging a CAN interface issue and found the send() returned -1. But I didn't realize I had a txqueuelen issue until I recompiled the socketcan C code to provide this errno context (105 ENOBUFS No buffer space available). It'd be nice if node-can could provide that error information.

@sebi2k1
Copy link
Owner

sebi2k1 commented Feb 17, 2024

We would have to introduce a new set of function otherwise we would break compatibility with existing code. Did you tried reading ERRNO directly from the script? The send-call itself is synchronous and this should be the only syscall in the call chain (except if nodejs is doing some hidden syscall).

@poppfd
Copy link
Author

poppfd commented Feb 19, 2024

Yea I understand backwards compatibility is a concern. I'm not super familiar with natively compiled C libraries for node so I thought you might have a more elegant solution.
Not sure what you mean by "the script". If you mean the node script, I did not think the C errno variable was available in that scope. If I could get access to the errno variable, it looks like node will parse it with util.getSystemErrorName(errno)
Like I said, I recompiled the can.cc file to return the errno string instead of number of bytes sent. I found this to be a crude, but workable solution.

@sebi2k1
Copy link
Owner

sebi2k1 commented Feb 26, 2024

We can add an additional function to read the errno. Would that work?

@poppfd
Copy link
Author

poppfd commented Feb 27, 2024

Yea I think that would work. So if we detect a failed send, we can read the errno and log from node.

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

No branches or pull requests

2 participants