-
-
Notifications
You must be signed in to change notification settings - Fork 31.9k
How to read from unix socket file descriptor? #8328
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
Comments
Where is the socket fd created? Is the socket a stream or datagram socket? |
Inside the Bluez source code. bluez/btio/btio.c, look for the create_io function: My bluetooth connection type is RFCOMM, so if we look at the source code we see this:
So I'm pretty sure it is a stream socket. Also, you can see from the source code, Bluez is using the gio channel lib, Thanks for any help you may provide :) |
Libuv, the I/O library that node.js uses, restricts its support to AF_INET/AF_INET6 and AF_UNIX for reasons of portability. What you could do perhaps is to turn off non-blocking mode on the file descriptor with (for example) the ffi module and then wrap it with |
Thank you for your help + advice, thought this was the case. Im not sure i want to have blocking io, going to try and create a gyp binding to gio-channel instead. Cheers! |
this is the code:
this is the output:
socket:[12357]
{ Error: EAGAIN: resource temporarily unavailable, read
at Error (native) errno: -11, code: 'EAGAIN', syscall: 'read' }
I have also tried this:
the error i get is:
TypeError: Unsupported fd type: UNKNOWN
Now, I can write to the fd using createWriteStream (and receive data on the other end), but I am unable to read.
If i were to read this socket using this c function it will work:
ssize_t recvmsg(int sockfd, struct msghdr *msg, int flags);
documentation here: http://linux.die.net/man/2/recvmsg
But i want to know how to read from unix socket descriptor using nodejs.
Keep in mind this code:
console.log( fs.readlinkSync('/proc/self/fd/' + fd) );
produces:
socket:[12357]
So I am just trying to read a simple unix socket, I would be shocked if this is not supported in node.
that is why I am asking the question, how do i read from a unix socket descritpor in nodejs?
Thank you for any help.
The text was updated successfully, but these errors were encountered: