What is the problem this feature will solve?
-
My scenario is that the TCP client read speed is slow, so I need to set SO_RCVBUF through setsockopt().
According to this post, I have implemented setsockopt().
But can Node.js directly expose the corresponding interface?
-
The normal TCP client implementation code is:
var conn = new net.Socket(); // conn._handle will be null
conn.connect(5555, '127.0.0.1'); // conn._handle will be not null
Only after the socket is connected, its handle is not null.
But because the setting of SO_RCVBUF needs to be before socket connect (client) or socket listen (server), so I do it with the following code:
const TCPWrap = process.binding('tcp_wrap');
const { TCP } = TCPWrap;
const handle = new TCP(TCPWrap.constants.SOCKET);
var conn = new net.Socket({handle});
console.log(conn._handle) => print null
setSocketOption(conn._handle, SOL_SOCKET, SO_RCVBUF, 1024);
conn.connect(5555, '127.0.0.1');
I expected to get a socket with a non-null handle at line 4, but in fact, conn._handle is still null.
Is there any way to allocate the socket handle before the connect operation?
What is the feature you are proposing to solve the problem?
- Provide
setsockeopt() interface;
- Provides a method to initialize its handle when instantiating
net.Socket()
What alternatives have you considered?
No response
What is the problem this feature will solve?
My scenario is that the TCP client read speed is slow, so I need to set
SO_RCVBUFthroughsetsockopt().According to this post, I have implemented
setsockopt().But can Node.js directly expose the corresponding interface?
The normal TCP client implementation code is:
Only after the socket is connected, its handle is not null.
But because the setting of
SO_RCVBUFneeds to be before socket connect (client) or socket listen (server), so I do it with the following code:I expected to get a socket with a non-null handle at line 4, but in fact,
conn._handleis still null.Is there any way to allocate the socket handle before the connect operation?
What is the feature you are proposing to solve the problem?
setsockeopt()interface;net.Socket()What alternatives have you considered?
No response