소스 검색

tcp: ioctl type SIOCOUTQNSD returns amount of data not sent

In contrast to SIOCOUTQ which returns the amount of data sent
but not yet acknowledged plus data not yet sent this patch only
returns the data not sent.

For various methods of live streaming bitrate control it may
be helpful to know how much data are in the tcp outqueue are
not sent yet.

Signed-off-by: Mario Schuknecht <m.schuknecht@dresearch.de>
Signed-off-by: Steffen Sledz <sledz@dresearch.de>
Signed-off-by: David S. Miller <davem@davemloft.net>
Mario Schuknecht 14 년 전
부모
커밋
2f4e1b3970
2개의 변경된 파일12개의 추가작업 그리고 1개의 파일을 삭제
  1. 3 1
      include/linux/sockios.h
  2. 9 0
      net/ipv4/tcp.c

+ 3 - 1
include/linux/sockios.h

@@ -22,7 +22,7 @@
 
 
 /* Linux-specific socket ioctls */
 /* Linux-specific socket ioctls */
 #define SIOCINQ		FIONREAD
 #define SIOCINQ		FIONREAD
-#define SIOCOUTQ	TIOCOUTQ
+#define SIOCOUTQ	TIOCOUTQ        /* output queue size (not sent + not acked) */
 
 
 /* Routing table calls. */
 /* Routing table calls. */
 #define SIOCADDRT	0x890B		/* add routing table entry	*/
 #define SIOCADDRT	0x890B		/* add routing table entry	*/
@@ -83,6 +83,8 @@
 
 
 #define SIOCWANDEV	0x894A		/* get/set netdev parameters	*/
 #define SIOCWANDEV	0x894A		/* get/set netdev parameters	*/
 
 
+#define SIOCOUTQNSD	0x894B		/* output queue size (not sent only) */
+
 /* ARP cache control calls. */
 /* ARP cache control calls. */
 		    /*  0x8950 - 0x8952  * obsolete calls, don't re-use */
 		    /*  0x8950 - 0x8952  * obsolete calls, don't re-use */
 #define SIOCDARP	0x8953		/* delete ARP table entry	*/
 #define SIOCDARP	0x8953		/* delete ARP table entry	*/

+ 9 - 0
net/ipv4/tcp.c

@@ -505,6 +505,15 @@ int tcp_ioctl(struct sock *sk, int cmd, unsigned long arg)
 		else
 		else
 			answ = tp->write_seq - tp->snd_una;
 			answ = tp->write_seq - tp->snd_una;
 		break;
 		break;
+	case SIOCOUTQNSD:
+		if (sk->sk_state == TCP_LISTEN)
+			return -EINVAL;
+
+		if ((1 << sk->sk_state) & (TCPF_SYN_SENT | TCPF_SYN_RECV))
+			answ = 0;
+		else
+			answ = tp->write_seq - tp->snd_nxt;
+		break;
 	default:
 	default:
 		return -ENOIOCTLCMD;
 		return -ENOIOCTLCMD;
 	}
 	}