getsockopt: Add SO_SNDSPACE
authorSepherosa Ziehau <sephe@dragonflybsd.org>
Fri, 5 Aug 2011 05:53:17 +0000 (13:53 +0800)
committerSepherosa Ziehau <sephe@dragonflybsd.org>
Fri, 5 Aug 2011 05:53:17 +0000 (13:53 +0800)
This SOL_SOCKET get-only option is used to get the approximate free space
of send buffer.

sys/kern/uipc_socket.c
sys/sys/socket.h

index ff5236a..204ff48 100644 (file)
@@ -1549,6 +1549,7 @@ int
 sogetopt(struct socket *so, struct sockopt *sopt)
 {
        int     error, optval;
+       long    optval_l;
        struct  linger l;
        struct  timeval tv;
 #ifdef INET
@@ -1635,6 +1636,11 @@ integer:
                        error = sooptcopyout(sopt, &tv, sizeof tv);
                        break;                  
 
+               case SO_SNDSPACE:
+                       optval_l = ssb_space(&so->so_snd);
+                       error = sooptcopyout(sopt, &optval_l, sizeof(optval_l));
+                       break;
+
                default:
                        error = ENOPROTOOPT;
                        break;
index 65a0745..593c423 100644 (file)
@@ -101,6 +101,7 @@ typedef __socklen_t socklen_t;
 #define        SO_ERROR        0x1007          /* get error status and clear */
 #define        SO_TYPE         0x1008          /* get socket type */
 /*efine        SO_PRIVSTATE    0x1009             get/deny privileged state */
+#define        SO_SNDSPACE     0x100a          /* get appr. send buffer free space */
 
 /*
  * Structure used for manipulating linger option.