add code to ensure that SO_SNDBUF is large enough on client connections,
as was previously done for server mode
This commit is contained in:
parent
aec6efdd3a
commit
c61317e3bf
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: client.c,v 1.6 2011/08/29 20:38:55 joerg Exp $ */
|
||||
/* $NetBSD: client.c,v 1.7 2012/10/14 08:31:35 plunky Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2008-2009 Iain Hibbert
|
||||
@ -26,7 +26,7 @@
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__RCSID("$NetBSD: client.c,v 1.6 2011/08/29 20:38:55 joerg Exp $");
|
||||
__RCSID("$NetBSD: client.c,v 1.7 2012/10/14 08:31:35 plunky Exp $");
|
||||
|
||||
#include <bluetooth.h>
|
||||
#include <errno.h>
|
||||
@ -45,7 +45,7 @@ client_init(void)
|
||||
struct sockaddr_bt sa;
|
||||
channel_t *chan;
|
||||
socklen_t len;
|
||||
int fd, bufsize;
|
||||
int fd, n;
|
||||
uint16_t mru, mtu;
|
||||
|
||||
if (bdaddr_any(&remote_bdaddr))
|
||||
@ -102,17 +102,15 @@ client_init(void)
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
len = sizeof(bufsize);
|
||||
if (getsockopt(fd, SOL_SOCKET, SO_RCVBUF, &bufsize, &len) == -1) {
|
||||
len = sizeof(n);
|
||||
if (getsockopt(fd, SOL_SOCKET, SO_RCVBUF, &n, &len) == -1) {
|
||||
log_err("Could not read SO_RCVBUF");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
if (bufsize < 10 * mru) {
|
||||
bufsize = 10 * mru;
|
||||
if (setsockopt(fd, SOL_SOCKET, SO_RCVBUF, &bufsize,
|
||||
sizeof(bufsize)) == -1)
|
||||
log_info("Could not increase SO_RCVBUF (from %d)",
|
||||
bufsize);
|
||||
if (n < 10 * mru) {
|
||||
n = 10 * mru;
|
||||
if (setsockopt(fd, SOL_SOCKET, SO_RCVBUF, &n, sizeof(n)) == -1)
|
||||
log_info("Could not increase SO_RCVBUF (to %d)", n);
|
||||
}
|
||||
|
||||
len = sizeof(mtu);
|
||||
@ -125,6 +123,27 @@ client_init(void)
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
len = sizeof(n);
|
||||
if (getsockopt(fd, SOL_SOCKET, SO_SNDBUF, &n, &len) == -1) {
|
||||
log_err("Could not get socket send buffer size: %m");
|
||||
close(fd);
|
||||
return;
|
||||
}
|
||||
if (n < (mtu * 2)) {
|
||||
n = mtu * 2;
|
||||
if (setsockopt(fd, SOL_SOCKET, SO_SNDBUF, &n, sizeof(n)) == -1) {
|
||||
log_err("Could not set socket send buffer size (%d): %m", n);
|
||||
close(fd);
|
||||
return;
|
||||
}
|
||||
}
|
||||
n = mtu;
|
||||
if (setsockopt(fd, SOL_SOCKET, SO_SNDLOWAT, &n, sizeof(n)) == -1) {
|
||||
log_err("Could not set socket low water mark (%d): %m", n);
|
||||
close(fd);
|
||||
return;
|
||||
}
|
||||
|
||||
chan = channel_alloc();
|
||||
if (chan == NULL)
|
||||
exit(EXIT_FAILURE);
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: server.c,v 1.7 2011/02/08 21:59:50 plunky Exp $ */
|
||||
/* $NetBSD: server.c,v 1.8 2012/10/14 08:31:35 plunky Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2008-2009 Iain Hibbert
|
||||
@ -26,7 +26,7 @@
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__RCSID("$NetBSD: server.c,v 1.7 2011/02/08 21:59:50 plunky Exp $");
|
||||
__RCSID("$NetBSD: server.c,v 1.8 2012/10/14 08:31:35 plunky Exp $");
|
||||
|
||||
#include <sys/ioctl.h>
|
||||
|
||||
@ -134,7 +134,7 @@ server_read(int s, short ev, void *arg)
|
||||
struct sockaddr_bt ra, la;
|
||||
channel_t *chan;
|
||||
socklen_t len;
|
||||
int fd, n, bufsize;
|
||||
int fd, n;
|
||||
uint16_t mru, mtu;
|
||||
|
||||
assert(server_count < server_limit);
|
||||
@ -163,18 +163,16 @@ server_read(int s, short ev, void *arg)
|
||||
return;
|
||||
}
|
||||
|
||||
len = sizeof(bufsize);
|
||||
if (getsockopt(fd, SOL_SOCKET, SO_RCVBUF, &bufsize, &len) == -1) {
|
||||
len = sizeof(n);
|
||||
if (getsockopt(fd, SOL_SOCKET, SO_RCVBUF, &n, &len) == -1) {
|
||||
log_err("Could not read SO_RCVBUF");
|
||||
close(fd);
|
||||
return;
|
||||
}
|
||||
if (bufsize < 10 * mru) {
|
||||
bufsize = 10 * mru;
|
||||
if (setsockopt(fd, SOL_SOCKET, SO_RCVBUF, &bufsize,
|
||||
sizeof(bufsize)) == -1)
|
||||
log_info("Could not increase SO_RCVBUF (from %d)",
|
||||
bufsize);
|
||||
if (n < 10 * mru) {
|
||||
n = 10 * mru;
|
||||
if (setsockopt(fd, SOL_SOCKET, SO_RCVBUF, &n, sizeof(n)) == -1)
|
||||
log_info("Could not increase SO_RCVBUF (to %d)", n);
|
||||
}
|
||||
|
||||
len = sizeof(mtu);
|
||||
@ -195,7 +193,6 @@ server_read(int s, short ev, void *arg)
|
||||
close(fd);
|
||||
return;
|
||||
}
|
||||
|
||||
if (n < (mtu * 2)) {
|
||||
n = mtu * 2;
|
||||
if (setsockopt(fd, SOL_SOCKET, SO_SNDBUF, &n, sizeof(n)) == -1) {
|
||||
@ -204,7 +201,6 @@ server_read(int s, short ev, void *arg)
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
n = mtu;
|
||||
if (setsockopt(fd, SOL_SOCKET, SO_SNDLOWAT, &n, sizeof(n)) == -1) {
|
||||
log_err("Could not set socket low water mark (%d): %m", n);
|
||||
|
Loading…
Reference in New Issue
Block a user