Changeset 854e79a6 in mainline for uspace/srv/net/tl/tcp/state.c


Ignore:
Timestamp:
2011-11-17T14:53:35Z (14 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
004a5fe
Parents:
4f3f6285
Message:

TCP user call error codes. Some state checking and error reporting from
user calls.

File:
1 edited

Legend:

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

    r4f3f6285 r854e79a6  
    5454 * @param acpass        Active/passive
    5555 * @param conn          Connection
     56 *
     57 * XXX We should be able to call active open on an existing listening
     58 * connection.
    5659 */
    5760void tcp_uc_open(uint16_t lport, tcp_sock_t *fsock, acpass_t acpass,
     
    8083
    8184/** SEND user call */
    82 void tcp_uc_send(tcp_conn_t *conn, void *data, size_t size, xflags_t flags)
     85tcp_error_t tcp_uc_send(tcp_conn_t *conn, void *data, size_t size,
     86    xflags_t flags)
    8387{
    8488        size_t buf_free;
     
    8690
    8791        log_msg(LVL_DEBUG, "tcp_uc_send()");
     92
     93        if (conn->cstate == st_closed)
     94                return TCP_ENOTEXIST;
     95
     96        if (conn->cstate == st_listen) {
     97                /* Change connection to active */
     98                tcp_conn_sync(conn);
     99        }
     100
     101        if (conn->snd_buf_fin)
     102                return TCP_ECLOSING;
    88103
    89104        while (size > 0) {
     
    102117
    103118        tcp_tqueue_new_data(conn);
     119
     120        return TCP_EOK;
    104121}
    105122
    106123/** RECEIVE user call */
    107 void tcp_uc_receive(tcp_conn_t *conn, void *buf, size_t size, size_t *rcvd,
    108     xflags_t *xflags)
     124tcp_error_t tcp_uc_receive(tcp_conn_t *conn, void *buf, size_t size,
     125    size_t *rcvd, xflags_t *xflags)
    109126{
    110127        size_t xfer_size;
     
    112129        log_msg(LVL_DEBUG, "tcp_uc_receive()");
    113130
    114         /*
    115          * XXX Handle all states for all user calls properly, return
    116          * errors as appropriate.
    117          */
    118131        if (conn->cstate == st_closed)
    119                 return;
    120 
     132                return TCP_ENOTEXIST;
    121133
    122134        fibril_mutex_lock(&conn->rcv_buf_lock);
     
    130142        if (conn->rcv_buf_used == 0) {
    131143                /* End of data, peer closed connection. */
    132                 /* XXX How should RECEIVE signal end of data? */
    133144                assert(conn->rcv_buf_fin);
    134145                *rcvd = 0;
    135146                *xflags = 0;
    136                 return;
     147                return TCP_ECLOSING;
    137148        }
    138149
     
    158169        log_msg(LVL_DEBUG, "tcp_uc_receive() - returning %zu bytes",
    159170            xfer_size);
     171
     172        return TCP_EOK;
    160173}
    161174
    162175/** CLOSE user call */
    163 void tcp_uc_close(tcp_conn_t *conn)
     176tcp_error_t tcp_uc_close(tcp_conn_t *conn)
    164177{
    165178        log_msg(LVL_DEBUG, "tcp_uc_close()");
     179
     180        if (conn->cstate == st_closed)
     181                return TCP_ENOTEXIST;
     182
     183        if (conn->snd_buf_fin)
     184                return TCP_ECLOSING;
    166185
    167186        conn->snd_buf_fin = true;
    168187        tcp_tqueue_new_data(conn);
     188
     189        return TCP_EOK;
    169190}
    170191
     
    211232}
    212233
    213 /** Retransmission timeout */
    214 void tcp_to_retransmit(void)
    215 {
    216         log_msg(LVL_DEBUG, "tcp_to_retransmit()");
    217 }
    218 
    219234/**
    220235 * @}
Note: See TracChangeset for help on using the changeset viewer.