Enable TCP_NODELAY for the control socket
It is better to disable Nagle's algorithm to avoid unnecessary latency for control messages. (I'm not sure this has any impact for a local TCP socket though.)
This commit is contained in:
parent
145a9468fd
commit
8453e3ba7d
@ -659,6 +659,14 @@ sc_server_connect_to(struct sc_server *server, struct sc_server_info *info) {
|
||||
}
|
||||
}
|
||||
|
||||
if (control_socket != SC_SOCKET_NONE) {
|
||||
// Disable Nagle's algorithm for the control socket
|
||||
// (it only impacts the sending side, so it is useless to set it
|
||||
// for the other sockets)
|
||||
bool ok = net_set_tcp_nodelay(control_socket, true);
|
||||
(void) ok; // error already logged
|
||||
}
|
||||
|
||||
// we don't need the adb tunnel anymore
|
||||
sc_adb_tunnel_close(tunnel, &server->intr, serial,
|
||||
server->device_socket_name);
|
||||
|
@ -15,6 +15,7 @@
|
||||
# include <sys/types.h>
|
||||
# include <sys/socket.h>
|
||||
# include <netinet/in.h>
|
||||
# include <netinet/tcp.h>
|
||||
# include <arpa/inet.h>
|
||||
# include <unistd.h>
|
||||
# include <fcntl.h>
|
||||
@ -273,6 +274,22 @@ net_close(sc_socket socket) {
|
||||
#endif
|
||||
}
|
||||
|
||||
bool
|
||||
net_set_tcp_nodelay(sc_socket socket, bool tcp_nodelay) {
|
||||
sc_raw_socket raw_sock = unwrap(socket);
|
||||
|
||||
int value = tcp_nodelay ? 1 : 0;
|
||||
int ret = setsockopt(raw_sock, IPPROTO_TCP, TCP_NODELAY,
|
||||
(const void *) &value, sizeof(value));
|
||||
if (ret == -1) {
|
||||
net_perror("setsockopt(TCP_NODELAY)");
|
||||
return false;
|
||||
}
|
||||
|
||||
assert(ret == 0);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
net_parse_ipv4(const char *s, uint32_t *ipv4) {
|
||||
struct in_addr addr;
|
||||
|
@ -67,6 +67,10 @@ net_interrupt(sc_socket socket);
|
||||
bool
|
||||
net_close(sc_socket socket);
|
||||
|
||||
// Disable Nagle's algorithm (if tcp_nodelay is true)
|
||||
bool
|
||||
net_set_tcp_nodelay(sc_socket socket, bool tcp_nodelay);
|
||||
|
||||
/**
|
||||
* Parse `ip` "xxx.xxx.xxx.xxx" to an IPv4 host representation
|
||||
*/
|
||||
|
Loading…
x
Reference in New Issue
Block a user