btpand problem
Iain Hibbert
plunky at rya-online.net
Sun Oct 14 08:18:26 UTC 2012
On Sun, 14 Oct 2012, Iain Hibbert wrote:
> but, btpand should also ensure that the buffer sizes are suitable. The
> server_init() function already does this in FreeBSD, though I also added
> some code to increase the RCVBUF size in NetBSD code, and also added (but
> didn't yet commit) the similar for client code.. I will prepare a patch
patch for btpand attached
regards,
iain
-------------- next part --------------
Index: client.c
===================================================================
RCS file: /home/ncvs/src/usr.sbin/bluetooth/btpand/client.c,v
retrieving revision 1.1
diff -u -p -r1.1 client.c
--- client.c 30 Jan 2009 22:23:21 -0000 1.1
+++ client.c 14 Oct 2012 08:15:50 -0000
@@ -47,7 +47,7 @@ client_init(void)
struct sockaddr_l2cap sa;
channel_t *chan;
socklen_t len;
- int fd;
+ int fd, n;
uint16_t mru, mtu;
if (bdaddr_any(&remote_bdaddr))
@@ -97,6 +97,17 @@ client_init(void)
exit(EXIT_FAILURE);
}
+ len = sizeof(n);
+ if (getsockopt(fd, SOL_SOCKET, SO_RCVBUF, &n, &len) == -1) {
+ log_err("Could not read SO_RCVBUF");
+ exit(EXIT_FAILURE);
+ }
+ if (n < (mru * 10)) {
+ n = mru * 10;
+ if (setsockopt(fd, SOL_SOCKET, SO_RCVBUF, &n, sizeof(n)) == -1)
+ log_info("Could not increase SO_RCVBUF (from %d)", n);
+ }
+
len = sizeof(mtu);
if (getsockopt(fd, SOL_L2CAP, SO_L2CAP_OMTU, &mtu, &len) == -1) {
log_err("Could not get L2CAP OMTU: %m");
@@ -107,6 +118,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);
Index: server.c
===================================================================
RCS file: /home/ncvs/src/usr.sbin/bluetooth/btpand/server.c,v
retrieving revision 1.2
diff -u -p -r1.2 server.c
--- server.c 2 Feb 2009 18:08:22 -0000 1.2
+++ server.c 14 Oct 2012 08:15:51 -0000
@@ -177,6 +177,18 @@ server_read(int s, short ev, void *arg)
return;
}
+ len = sizeof(n);
+ if (getsockopt(fd, SOL_SOCKET, SO_RCVBUF, &n, &len) == -1) {
+ log_err("Could not read SO_RCVBUF");
+ close(fd);
+ return;
+ }
+ if (n < (mru * 10)) {
+ n = mru * 10;
+ if (setsockopt(fd, SOL_SOCKET, SO_RCVBUF, &n, sizeof(n)) == -1)
+ log_info("Could not increase SO_RCVBUF (from %d)", n);
+ }
+
len = sizeof(mtu);
if (getsockopt(fd, SOL_L2CAP, SO_L2CAP_OMTU, &mtu, &len) == -1) {
log_err("Could not get L2CAP OMTU: %m");
More information about the freebsd-bluetooth
mailing list