Changeset 32105348 in mainline for uspace/srv/net/tl/tcp/tqueue.c


Ignore:
Timestamp:
2011-10-04T18:12:41Z (14 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
d9ce049
Parents:
032bbe7
Message:

Send buffer, sketch data transmission.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/net/tl/tcp/tqueue.c

    r032bbe7 r32105348  
    3737#include <byteorder.h>
    3838#include <io/log.h>
     39#include <macros.h>
     40#include <mem.h>
     41#include "conn.h"
    3942#include "header.h"
    4043#include "rqueue.h"
     
    5053
    5154        seg = tcp_segment_make_ctrl(ctrl);
    52         seg->seq = conn->snd_nxt;
    53         seg->ack = conn->rcv_nxt;
    5455        tcp_tqueue_seg(conn, seg);
    5556}
     
    6061        /* XXX queue */
    6162
     63        /*
     64         * Always send ACK once we have received SYN, except for RST segments.
     65         * (Spec says we should always send ACK once connection has been
     66         * established.)
     67         */
     68        if (tcp_conn_got_syn(conn) && (seg->ctrl & CTL_RST) == 0)
     69                seg->ctrl |= CTL_ACK;
     70
     71        seg->seq = conn->snd_nxt;
     72        seg->wnd = conn->rcv_wnd;
     73
     74        if ((seg->ctrl & CTL_ACK) != 0)
     75                seg->ack = conn->rcv_nxt;
     76        else
     77                seg->ack = 0;
     78
    6279        conn->snd_nxt += seg->len;
     80
    6381        tcp_transmit_segment(&conn->ident, seg);
     82}
     83
     84/** Transmit data from the send buffer.
     85 *
     86 * @param conn  Connection
     87 */
     88void tcp_tqueue_new_data(tcp_conn_t *conn)
     89{
     90        size_t data_size;
     91        tcp_segment_t *seg;
     92
     93        log_msg(LVL_DEBUG, "tcp_tqueue_new_data()");
     94
     95        data_size = min(conn->snd_buf_used, conn->snd_wnd);
     96        log_msg(LVL_DEBUG, "conn->snd_buf_used = %zu, SND.WND = %zu, "
     97            "data_size = %zu", conn->snd_buf_used, conn->snd_wnd, data_size);
     98
     99        if (data_size == 0)
     100                return;
     101
     102        /* XXX Do not always send immediately */
     103
     104        seg = tcp_segment_make_data(0, conn->snd_buf, data_size);
     105        if (seg == NULL) {
     106                log_msg(LVL_ERROR, "Memory allocation failure.");
     107                return;
     108        }
     109
     110        /* Remove data from send buffer */
     111        memmove(conn->snd_buf, conn->snd_buf + data_size,
     112            conn->snd_buf_used - data_size);
     113        conn->snd_buf_used -= data_size;
     114
     115        tcp_tqueue_seg(conn, seg);
    64116}
    65117
Note: See TracChangeset for help on using the changeset viewer.