Author: emax
Date: Thu Oct 18 16:34:00 2012
New Revision: 241699
URL: http://svn.freebsd.org/changeset/base/241699

Log:
  make sure that socket's send and receive buffers are properly sized
  
  Submitted by: Iain Hibbert plunky at rya-online dot net
  MFC after:    3 weeks

Modified:
  head/usr.sbin/bluetooth/btpand/client.c
  head/usr.sbin/bluetooth/btpand/server.c

Modified: head/usr.sbin/bluetooth/btpand/client.c
==============================================================================
--- head/usr.sbin/bluetooth/btpand/client.c     Thu Oct 18 15:52:00 2012        
(r241698)
+++ head/usr.sbin/bluetooth/btpand/client.c     Thu Oct 18 16:34:00 2012        
(r241699)
@@ -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);

Modified: head/usr.sbin/bluetooth/btpand/server.c
==============================================================================
--- head/usr.sbin/bluetooth/btpand/server.c     Thu Oct 18 15:52:00 2012        
(r241698)
+++ head/usr.sbin/bluetooth/btpand/server.c     Thu Oct 18 16:34:00 2012        
(r241699)
@@ -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");
_______________________________________________
svn-src-head@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"

Reply via email to