[DCCP]: Introduce dccp_wait_for_ccid and use it in dccp_write_xmit
authorArnaldo Carvalho de Melo <acme@mandriva.com>
Sat, 27 Aug 2005 06:06:35 +0000 (03:06 -0300)
committerDavid S. Miller <davem@sunset.davemloft.net>
Mon, 29 Aug 2005 23:11:38 +0000 (16:11 -0700)
This is not quite what I think we should have long term but improves
performance for now, so lets use it till we get CCID3 working well,
then we can think about using sk_write_queue, perhaps using some ideas
from Juwen Lai's old stack for 2.4.20.

Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
net/dccp/ccids/ccid3.c
net/dccp/dccp.h
net/dccp/output.c
net/dccp/proto.c

index cf93b019ecbe719d13c4bdaadd30a0431342a90c..9866dc175258ce3bc357fb6b05dde35d72829a7c 100644 (file)
@@ -985,7 +985,7 @@ static int ccid3_hc_tx_send_packet(struct sock *sk,
                ccid3_pr_debug("send_packet delay=%ld\n", delay);
                delay /= -1000;
                /* divide by -1000 is to convert to ms and get sign right */
-               rc = delay > 0 ? -EAGAIN : 0;
+               rc = delay > 0 ? delay : 0;
                break;
        default:
                printk(KERN_CRIT "%s: %s, sk=%p, Illegal state (%d)!\n",
index c6ba07ea1a9f7293c3ee2a5a5d7c3d91bfff531e..6ba21509e79748a5d059fb12186429c80eca5795 100644 (file)
@@ -126,8 +126,7 @@ extern void dccp_send_delayed_ack(struct sock *sk);
 extern void dccp_send_sync(struct sock *sk, const u64 seq,
                           const enum dccp_pkt_type pkt_type);
 
-extern int dccp_write_xmit(struct sock *sk, struct sk_buff *skb,
-                          const int len);
+extern int dccp_write_xmit(struct sock *sk, struct sk_buff *skb, long *timeo);
 
 extern void dccp_init_xmit_timers(struct sock *sk);
 static inline void dccp_clear_xmit_timers(struct sock *sk)
index f96dedd3ad5efc83c4fe16309be7dec6e37fee62..116f6db5678dea9cbc3aed23e6b51e9edc2acbbf 100644 (file)
@@ -150,14 +150,71 @@ unsigned int dccp_sync_mss(struct sock *sk, u32 pmtu)
        return mss_now;
 }
 
-int dccp_write_xmit(struct sock *sk, struct sk_buff *skb, const int len)
+/**
+ * dccp_wait_for_ccid - Wait for ccid to tell us we can send a packet
+ * @sk: socket to wait for
+ * @timeo: for how long
+ */
+static int dccp_wait_for_ccid(struct sock *sk, struct sk_buff *skb,
+                             long *timeo)
+{
+       struct dccp_sock *dp = dccp_sk(sk);
+       DEFINE_WAIT(wait);
+       long delay;
+       int rc;
+
+       while (1) {
+               prepare_to_wait(sk->sk_sleep, &wait, TASK_INTERRUPTIBLE);
+
+               if (sk->sk_err || (sk->sk_shutdown & SEND_SHUTDOWN))
+                       goto do_error;
+               if (!*timeo)
+                       goto do_nonblock;
+               if (signal_pending(current))
+                       goto do_interrupted;
+
+               rc = ccid_hc_tx_send_packet(dp->dccps_hc_tx_ccid, sk, skb,
+                                           skb->len);
+               if (rc <= 0)
+                       break;
+               delay = msecs_to_jiffies(rc);
+               if (delay > *timeo || delay < 0)
+                       goto do_nonblock;
+
+               sk->sk_write_pending++;
+               release_sock(sk);
+               *timeo -= schedule_timeout(delay);
+               lock_sock(sk);
+               sk->sk_write_pending--;
+       }
+out:
+       finish_wait(sk->sk_sleep, &wait);
+       return rc;
+
+do_error:
+       rc = -EPIPE;
+       goto out;
+do_nonblock:
+       rc = -EAGAIN;
+       goto out;
+do_interrupted:
+       rc = sock_intr_errno(*timeo);
+       goto out;
+}
+
+int dccp_write_xmit(struct sock *sk, struct sk_buff *skb, long *timeo)
 {
        const struct dccp_sock *dp = dccp_sk(sk);
-       int err = ccid_hc_tx_send_packet(dp->dccps_hc_tx_ccid, sk, skb, len);
+       int err = ccid_hc_tx_send_packet(dp->dccps_hc_tx_ccid, sk, skb,
+                                        skb->len);
+
+       if (err > 0)
+               err = dccp_wait_for_ccid(sk, skb, timeo);
 
        if (err == 0) {
                const struct dccp_ackpkts *ap = dp->dccps_hc_rx_ackpkts;
                struct dccp_skb_cb *dcb = DCCP_SKB_CB(skb);
+               const int len = skb->len;
 
                if (sk->sk_state == DCCP_PARTOPEN) {
                        /* See 8.1.5.  Handshake Completion */
index f97e92ea34f32870760171d064455b474d0d1bc9..f4da6561e40c87e36608ca9cc9f1a3ccf24110f9 100644 (file)
@@ -261,7 +261,7 @@ int dccp_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
        if (rc != 0)
                goto out_discard;
 
-       rc = dccp_write_xmit(sk, skb, len);
+       rc = dccp_write_xmit(sk, skb, &timeo);
        /*
         * XXX we don't use sk_write_queue, so just discard the packet.
         *     Current plan however is to _use_ sk_write_queue with