Add nodelay option for TCP character devices.

git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@2362 c046a42c-6fe2-441c-8c8c-71466251a162
This commit is contained in:
pbrook 2007-01-28 00:10:01 +00:00
parent e5b0bc445e
commit f749998939
2 changed files with 17 additions and 3 deletions

View File

@ -576,13 +576,14 @@ localhost 5555
@end table @end table
@item tcp:[host]:port[,server][,nowait] @item tcp:[host]:port[,server][,nowait][,nodelay]
The TCP Net Console has two modes of operation. It can send the serial The TCP Net Console has two modes of operation. It can send the serial
I/O to a location or wait for a connection from a location. By default I/O to a location or wait for a connection from a location. By default
the TCP Net Console is sent to @var{host} at the @var{port}. If you use the TCP Net Console is sent to @var{host} at the @var{port}. If you use
the @var{server} option QEMU will wait for a client socket application the @var{server} option QEMU will wait for a client socket application
to connect to the port before continuing, unless the @code{nowait} to connect to the port before continuing, unless the @code{nowait}
option was specified. If @var{host} is omitted, 0.0.0.0 is assumed. Only option was specified. The @code{nodelay} option disables the Nagle buffering
algoritm. If @var{host} is omitted, 0.0.0.0 is assumed. Only
one TCP connection at a time is accepted. You can use @code{telnet} to one TCP connection at a time is accepted. You can use @code{telnet} to
connect to the corresponding character device. connect to the corresponding character device.
@table @code @table @code
@ -594,7 +595,7 @@ connect to the corresponding character device.
-serial tcp:192.168.0.100:4444,server,nowait -serial tcp:192.168.0.100:4444,server,nowait
@end table @end table
@item telnet:host:port[,server][,nowait] @item telnet:host:port[,server][,nowait][,nodelay]
The telnet protocol is used instead of raw tcp sockets. The options The telnet protocol is used instead of raw tcp sockets. The options
work the same as if you had specified @code{-serial tcp}. The work the same as if you had specified @code{-serial tcp}. The
difference is that the port acts like a telnet server or client using difference is that the port acts like a telnet server or client using

13
vl.c
View File

@ -2497,6 +2497,12 @@ static void tcp_chr_telnet_init(int fd)
send(fd, (char *)buf, 3, 0); send(fd, (char *)buf, 3, 0);
} }
static void socket_set_nodelay(int fd)
{
int val = 1;
setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, (char *)&val, sizeof(val));
}
static void tcp_chr_accept(void *opaque) static void tcp_chr_accept(void *opaque)
{ {
CharDriverState *chr = opaque; CharDriverState *chr = opaque;
@ -2530,6 +2536,8 @@ static void tcp_chr_accept(void *opaque)
} }
} }
socket_set_nonblock(fd); socket_set_nonblock(fd);
if (s->do_nodelay)
socket_set_nodelay(fd);
s->fd = fd; s->fd = fd;
qemu_set_fd_handler(s->listen_fd, NULL, NULL, NULL); qemu_set_fd_handler(s->listen_fd, NULL, NULL, NULL);
tcp_chr_connect(chr); tcp_chr_connect(chr);
@ -2554,6 +2562,7 @@ static CharDriverState *qemu_chr_open_tcp(const char *host_str,
int fd = -1, ret, err, val; int fd = -1, ret, err, val;
int is_listen = 0; int is_listen = 0;
int is_waitconnect = 1; int is_waitconnect = 1;
int do_nodelay = 0;
const char *ptr; const char *ptr;
struct sockaddr_in saddr; struct sockaddr_in saddr;
#ifndef _WIN32 #ifndef _WIN32
@ -2584,6 +2593,8 @@ static CharDriverState *qemu_chr_open_tcp(const char *host_str,
is_listen = 1; is_listen = 1;
} else if (!strncmp(ptr,"nowait",6)) { } else if (!strncmp(ptr,"nowait",6)) {
is_waitconnect = 0; is_waitconnect = 0;
} else if (!strncmp(ptr,"nodelay",6)) {
do_nodelay = 1;
} else { } else {
printf("Unknown option: %s\n", ptr); printf("Unknown option: %s\n", ptr);
goto fail; goto fail;
@ -2616,6 +2627,7 @@ static CharDriverState *qemu_chr_open_tcp(const char *host_str,
s->fd = -1; s->fd = -1;
s->listen_fd = -1; s->listen_fd = -1;
s->is_unix = is_unix; s->is_unix = is_unix;
s->do_nodelay = do_nodelay && !is_unix;
chr->opaque = s; chr->opaque = s;
chr->chr_write = tcp_chr_write; chr->chr_write = tcp_chr_write;
@ -2665,6 +2677,7 @@ static CharDriverState *qemu_chr_open_tcp(const char *host_str,
} }
} }
s->fd = fd; s->fd = fd;
socket_set_nodelay(fd);
if (s->connected) if (s->connected)
tcp_chr_connect(chr); tcp_chr_connect(chr);
else else