Changeset 854e79a6 in mainline


Ignore:
Timestamp:
2011-11-17T14:53:35Z (12 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.

Location:
uspace/srv/net/tl/tcp
Files:
3 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 * @}
  • uspace/srv/net/tl/tcp/state.h

    r4f3f6285 r854e79a6  
    4343 */
    4444extern void tcp_uc_open(uint16_t, tcp_sock_t *, acpass_t, tcp_conn_t **);
    45 extern void tcp_uc_send(tcp_conn_t *, void *, size_t, xflags_t);
    46 extern void tcp_uc_receive(tcp_conn_t *, void *, size_t, size_t *, xflags_t *);
    47 extern void tcp_uc_close(tcp_conn_t *);
     45extern tcp_error_t tcp_uc_send(tcp_conn_t *, void *, size_t, xflags_t);
     46extern tcp_error_t tcp_uc_receive(tcp_conn_t *, void *, size_t, size_t *, xflags_t *);
     47extern tcp_error_t tcp_uc_close(tcp_conn_t *);
    4848extern void tcp_uc_abort(tcp_conn_t *);
    4949extern void tcp_uc_status(tcp_conn_t *, tcp_conn_status_t *);
     
    5858 */
    5959extern void tcp_to_user(void);
    60 extern void tcp_to_retransmit(void);
    6160
    6261#endif
  • uspace/srv/net/tl/tcp/tcp_type.h

    r4f3f6285 r854e79a6  
    6868} tcp_cstate_t;
    6969
     70/** Error codes returned by TCP user calls (per the spec). */
     71typedef enum {
     72        /* OK */
     73        TCP_EOK,
     74        /* Connection aborted due to user timeout */
     75        TCP_EABORTED,
     76        /* Connection already exists */
     77        TCP_EEXISTS,
     78        /* Connection closing */
     79        TCP_ECLOSING,
     80        /* Connection does not exist */
     81        TCP_ENOTEXIST,
     82        /* Connection illegal for this process */
     83        TCP_EILLEGAL,
     84        /* Connection not open */
     85        TCP_ENOTOPEN,
     86        /* Connection reset */
     87        TCP_ERESET,
     88        /* Foreign socket unspecified */
     89        TCP_EUNSPEC,
     90        /* Insufficient resources */
     91        TCP_ENORES,
     92        /* Precedence not allowed */
     93        TCP_EINVPREC,
     94        /* Security/compartment not allowed */
     95        TCP_EINVCOMP
     96} tcp_error_t;
     97
    7098typedef enum {
    7199        XF_PUSH         = 0x1,
Note: See TracChangeset for help on using the changeset viewer.