Skip to content

Commit

Permalink
sock: send FIN with last portion of data
Browse files Browse the repository at this point in the history
  • Loading branch information
milabs committed Jun 29, 2016
1 parent 66acfc7 commit c72fcea
Showing 1 changed file with 16 additions and 13 deletions.
29 changes: 16 additions & 13 deletions tempesta_fw/sock.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ ss_sock_active(struct sock *sk)
return (1 << sk->sk_state) & (TCPF_ESTABLISHED | TCPF_CLOSE_WAIT);
}

static void
static inline void
ss_skb_entail(struct sock *sk, struct sk_buff *skb)
{
struct tcp_sock *tp = tcp_sk(sk);
Expand All @@ -114,14 +114,25 @@ ss_skb_entail(struct sock *sk, struct sk_buff *skb)
tcb->seq = tcb->end_seq = tp->write_seq;
tcb->tcp_flags = TCPHDR_ACK;
tcb->sacked = 0;
skb_header_release(skb);
__skb_header_release(skb);
tcp_add_write_queue_tail(sk, skb);
sk->sk_wmem_queued += skb->truesize;
sk_mem_charge(sk, skb->truesize);
if (tp->nonagle & TCP_NAGLE_PUSH)
tp->nonagle &= ~TCP_NAGLE_PUSH;
}

static inline void
ss_tcp_shutdown(struct sock *sk)
{
struct sk_buff *skb = tcp_write_queue_tail(sk);
struct tcp_sock *tp = tcp_sk(sk);

TCP_SKB_CB(skb)->tcp_flags |= TCPHDR_FIN;
TCP_SKB_CB(skb)->end_seq++;
tp->write_seq++;
}

/*
* ------------------------------------------------------------------------
* Server and client connections handling
Expand Down Expand Up @@ -169,15 +180,6 @@ ss_do_send(struct sock *sk, SsSkbList *skb_list, int flags)
skb->ip_summed = CHECKSUM_PARTIAL;
tcp_skb_pcount_set(skb, 0);

/*
* TODO Mark all data with PUSH to force receiver to consume
* the data. Currently we do this for debugging purposes.
* We need to do this only for complete messages/skbs.
* Actually tcp_push() already does it for the last skb.
* MSG_MORE should be used, probably by connection layer.
*/
tcp_mark_push(tp, skb);

SS_DBG("[%d]: %s: entail skb=%p data_len=%u len=%u\n",
smp_processor_id(), __func__,
skb, skb->data_len, skb->len);
Expand All @@ -192,6 +194,9 @@ ss_do_send(struct sock *sk, SsSkbList *skb_list, int flags)
smp_processor_id(), __func__,
sk, tcp_send_head(sk), sk->sk_state);

if ((flags & SS_SEND_F_CONN_CLOSE) && tcp_close_state(sk))
ss_tcp_shutdown(sk);

tcp_push(sk, MSG_DONTWAIT, mss, TCP_NAGLE_OFF|TCP_NAGLE_PUSH, size);
}

Expand All @@ -201,8 +206,6 @@ ss_do_send(struct sock *sk, SsSkbList *skb_list, int flags)
* copying. See do_tcp_sendpages() and tcp_sendmsg() in linux/net/ipv4/tcp.c.
*
* Can be called in softirq context as well as from kernel thread.
*
* TODO use MSG_MORE untill we reach end of message.
*/
int
ss_send(struct sock *sk, SsSkbList *skb_list, int flags)
Expand Down

0 comments on commit c72fcea

Please sign in to comment.