Changeset 2a3214e in mainline for uspace/srv/net/tl/tcp/conn.c


Ignore:
Timestamp:
2011-10-26T16:50:52Z (13 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
8218b6b
Parents:
6e88fea
Message:

Fibril timer primitive.
TCP Time-Wait timeout.

File:
1 edited

Legend:

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

    r6e88fea r2a3214e  
    4545#include "segment.h"
    4646#include "seq_no.h"
     47#include "state.h"
    4748#include "tcp_type.h"
    4849#include "tqueue.h"
     
    5152#define SND_BUF_SIZE 4096
    5253
     54#define MAX_SEGMENT_LIFETIME    (15*1000*1000) //(2*60*1000*1000)
     55#define TIME_WAIT_TIMEOUT       (2*MAX_SEGMENT_LIFETIME)
     56
    5357LIST_INITIALIZE(conn_list);
    5458
    5559static void tcp_conn_seg_process(tcp_conn_t *conn, tcp_segment_t *seg);
     60static void tcp_conn_tw_timer_set(tcp_conn_t *conn);
    5661
    5762/** Create new segment structure.
     
    6368tcp_conn_t *tcp_conn_new(tcp_sock_t *lsock, tcp_sock_t *fsock)
    6469{
    65         tcp_conn_t *conn;
     70        tcp_conn_t *conn = NULL;
    6671
    6772        /* Allocate connection structure */
    6873        conn = calloc(1, sizeof(tcp_conn_t));
    6974        if (conn == NULL)
    70                 return NULL;
     75                goto error;
     76
     77        conn->tw_timer = fibril_timer_create();
     78        if (conn->tw_timer == NULL)
     79                goto error;
    7180
    7281        /* Allocate receive buffer */
     
    7887
    7988        conn->rcv_buf = calloc(1, conn->rcv_buf_size);
    80         if (conn->rcv_buf == NULL) {
    81                 free(conn);
    82                 return NULL;
    83         }
     89        if (conn->rcv_buf == NULL)
     90                goto error;
    8491
    8592        /** Allocate send buffer */
     
    8895        conn->snd_buf_fin = false;
    8996        conn->snd_buf = calloc(1, conn->snd_buf_size);
    90         if (conn->snd_buf == NULL) {
    91                 free(conn);
    92                 return NULL;
    93         }
     97        if (conn->snd_buf == NULL)
     98                goto error;
    9499
    95100        /* Set up receive window. */
     
    109114
    110115        return conn;
     116
     117error:
     118        if (conn != NULL && conn->rcv_buf != NULL)
     119                free(conn->rcv_buf);
     120        if (conn != NULL && conn->snd_buf != NULL)
     121                free(conn->snd_buf);
     122        if (conn != NULL && conn->tw_timer != NULL)
     123                fibril_timer_destroy(conn->tw_timer);
     124        if (conn != NULL)
     125                free(conn);
     126
     127        return NULL;
    111128}
    112129
     
    803820                        log_msg(LVL_DEBUG, "FIN received -> Time-Wait");
    804821                        conn->cstate = st_time_wait;
    805                         /* XXX start time-wait timer */
     822                        /* Start the Time-Wait timer */
     823                        tcp_conn_tw_timer_set(conn);
    806824                        break;
    807825                case st_close_wait:
     
    811829                        break;
    812830                case st_time_wait:
    813                         /* XXX Restart the 2 MSL time-wait timeout */
     831                        /* Restart the Time-Wait timer */
     832                        tcp_conn_tw_timer_set(conn);
    814833                        break;
    815834                }
     
    912931}
    913932
     933/** Time-Wait timeout handler.
     934 *
     935 * @param arg   Connection
     936 */
     937static void tw_timeout_func(void *arg)
     938{
     939        tcp_conn_t *conn = (tcp_conn_t *) arg;
     940
     941        log_msg(LVL_DEBUG, "tw_timeout_func(%p)", conn);
     942        log_msg(LVL_DEBUG, " TW Timeout -> Closed");
     943
     944        tcp_conn_remove(conn);
     945        conn->cstate = st_closed;
     946}
     947
     948/** Start or restart the Time-Wait timeout.
     949 *
     950 * @param conn          Connection
     951 */
     952void tcp_conn_tw_timer_set(tcp_conn_t *conn)
     953{
     954        fibril_timer_set(conn->tw_timer, TIME_WAIT_TIMEOUT, tw_timeout_func,
     955            (void *)conn);
     956}
     957
    914958/** Trim segment to the receive window.
    915959 *
Note: See TracChangeset for help on using the changeset viewer.