Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/usr.sbin/btpand add code to ensure that SO_SNDBUF is large e...
details: https://anonhg.NetBSD.org/src/rev/4e683c47b537
branches: trunk
changeset: 782063:4e683c47b537
user: plunky <plunky%NetBSD.org@localhost>
date: Sun Oct 14 08:31:35 2012 +0000
description:
add code to ensure that SO_SNDBUF is large enough on client connections,
as was previously done for server mode
diffstat:
usr.sbin/btpand/client.c | 41 ++++++++++++++++++++++++++++++-----------
usr.sbin/btpand/server.c | 22 +++++++++-------------
2 files changed, 39 insertions(+), 24 deletions(-)
diffs (147 lines):
diff -r 322b39ce3fbe -r 4e683c47b537 usr.sbin/btpand/client.c
--- a/usr.sbin/btpand/client.c Sat Oct 13 21:21:52 2012 +0000
+++ b/usr.sbin/btpand/client.c Sun Oct 14 08:31:35 2012 +0000
@@ -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 @@
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 @@
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 @@
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);
diff -r 322b39ce3fbe -r 4e683c47b537 usr.sbin/btpand/server.c
--- a/usr.sbin/btpand/server.c Sat Oct 13 21:21:52 2012 +0000
+++ b/usr.sbin/btpand/server.c Sun Oct 14 08:31:35 2012 +0000
@@ -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 @@
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 @@
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 @@
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 @@
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);
Home |
Main Index |
Thread Index |
Old Index