use TCP_NODELAY

This commit is contained in:
Alexandre Ratchov 2011-04-28 08:10:14 +02:00
parent a583ebc5d9
commit 32a1e3d36e
2 changed files with 19 additions and 2 deletions

View File

@ -21,6 +21,7 @@
#include <sys/un.h>
#include <netinet/in.h>
#include <netinet/tcp.h>
#include <netdb.h>
#include <err.h>
@ -178,7 +179,7 @@ listen_revents(struct file *file, struct pollfd *pfd)
struct listen *f = (struct listen *)file;
struct sockaddr caddr;
socklen_t caddrlen;
int sock;
int sock, opt;
if (pfd->revents & POLLIN) {
caddrlen = sizeof(caddrlen);
@ -193,6 +194,15 @@ listen_revents(struct file *file, struct pollfd *pfd)
close(sock);
return 0;
}
if (f->path == NULL) {
opt = 1;
if (setsockopt(sock, IPPROTO_TCP, TCP_NODELAY,
&opt, sizeof(int)) < 0) {
perror("setsockopt");
close(sock);
return 0;
}
}
if (sock_new(&sock_ops, sock) == NULL) {
close(sock);
return 0;

View File

@ -21,6 +21,7 @@
#include <sys/un.h>
#include <netinet/in.h>
#include <netinet/tcp.h>
#include <netdb.h>
#include <errno.h>
@ -316,7 +317,7 @@ bad_gen:
int
aucat_connect_tcp(struct aucat *hdl, char *host, char *unit, int isaudio)
{
int s, error;
int s, error, opt;
struct addrinfo *ailist, *ai, aihints;
unsigned port;
char serv[NI_MAXSERV];
@ -356,6 +357,12 @@ aucat_connect_tcp(struct aucat *hdl, char *host, char *unit, int isaudio)
freeaddrinfo(ailist);
if (s < 0)
return 0;
opt = 1;
if (setsockopt(s, IPPROTO_TCP, TCP_NODELAY, &opt, sizeof(int)) < 0) {
DPERROR("setsockopt");
close(s);
return 0;
}
hdl->fd = s;
return 1;
}