Changeset 7943c43 in mainline for uspace/srv/net/tl/tcp/ucall.c


Ignore:
Timestamp:
2012-01-16T22:45:38Z (13 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
32817cc, 3fe58d3c
Parents:
9117ef9b (diff), 3ea725e (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge mainline changes.

File:
1 edited

Legend:

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

    r9117ef9b r7943c43  
    5353 * @param fsock         Foreign socket
    5454 * @param acpass        Active/passive
     55 * @param oflags        Open flags
    5556 * @param conn          Connection
    5657 *
     
    6566 */
    6667tcp_error_t tcp_uc_open(tcp_sock_t *lsock, tcp_sock_t *fsock, acpass_t acpass,
    67     tcp_conn_t **conn)
     68    tcp_open_flags_t oflags, tcp_conn_t **conn)
    6869{
    6970        tcp_conn_t *nconn;
    7071
    71         log_msg(LVL_DEBUG, "tcp_uc_open(%p, %p, %s, %p)",
     72        log_msg(LVL_DEBUG, "tcp_uc_open(%p, %p, %s, %s, %p)",
    7273            lsock, fsock, acpass == ap_active ? "active" : "passive",
    73             conn);
     74            oflags == tcp_open_nonblock ? "nonblock" : "none", conn);
    7475
    7576        nconn = tcp_conn_new(lsock, fsock);
     
    8182        }
    8283
     84        if (oflags == tcp_open_nonblock) {
     85                *conn = nconn;
     86                return TCP_EOK;
     87        }
     88
    8389        /* Wait for connection to be established or reset */
    8490        log_msg(LVL_DEBUG, "tcp_uc_open: Wait for connection.");
    85         fibril_mutex_lock(&nconn->cstate_lock);
     91        fibril_mutex_lock(&nconn->lock);
    8692        while (nconn->cstate == st_listen ||
    8793            nconn->cstate == st_syn_sent ||
    8894            nconn->cstate == st_syn_received) {
    89                 fibril_condvar_wait(&nconn->cstate_cv, &nconn->cstate_lock);
     95                fibril_condvar_wait(&nconn->cstate_cv, &nconn->lock);
    9096        }
    9197
     
    9399                log_msg(LVL_DEBUG, "tcp_uc_open: Connection was reset.");
    94100                assert(nconn->cstate == st_closed);
    95                 fibril_mutex_unlock(&nconn->cstate_lock);
     101                fibril_mutex_unlock(&nconn->lock);
    96102                return TCP_ERESET;
    97103        }
    98104
    99         fibril_mutex_unlock(&nconn->cstate_lock);
     105        fibril_mutex_unlock(&nconn->lock);
    100106        log_msg(LVL_DEBUG, "tcp_uc_open: Connection was established.");
    101107
    102108        *conn = nconn;
     109        log_msg(LVL_DEBUG, "tcp_uc_open -> %p", nconn);
    103110        return TCP_EOK;
    104111}
     
    113120        log_msg(LVL_DEBUG, "%s: tcp_uc_send()", conn->name);
    114121
    115         if (conn->cstate == st_closed)
     122        fibril_mutex_lock(&conn->lock);
     123
     124        if (conn->cstate == st_closed) {
     125                fibril_mutex_unlock(&conn->lock);
    116126                return TCP_ENOTEXIST;
     127        }
    117128
    118129        if (conn->cstate == st_listen) {
     
    121132        }
    122133
    123         if (conn->snd_buf_fin)
     134
     135        if (conn->snd_buf_fin) {
     136                fibril_mutex_unlock(&conn->lock);
    124137                return TCP_ECLOSING;
     138        }
    125139
    126140        while (size > 0) {
    127141                buf_free = conn->snd_buf_size - conn->snd_buf_used;
    128                 while (buf_free == 0 && !conn->reset)
    129                         tcp_tqueue_new_data(conn);
    130 
    131                 if (conn->reset)
     142                while (buf_free == 0 && !conn->reset) {
     143                        log_msg(LVL_DEBUG, "%s: buf_free == 0, waiting.",
     144                            conn->name);
     145                        fibril_condvar_wait(&conn->snd_buf_cv, &conn->lock);
     146                        buf_free = conn->snd_buf_size - conn->snd_buf_used;
     147                }
     148
     149                if (conn->reset) {
     150                        fibril_mutex_unlock(&conn->lock);
    132151                        return TCP_ERESET;
     152                }
    133153
    134154                xfer_size = min(size, buf_free);
     
    139159                conn->snd_buf_used += xfer_size;
    140160                size -= xfer_size;
     161
     162                tcp_tqueue_new_data(conn);
    141163        }
    142164
    143165        tcp_tqueue_new_data(conn);
     166        fibril_mutex_unlock(&conn->lock);
    144167
    145168        return TCP_EOK;
     
    154177        log_msg(LVL_DEBUG, "%s: tcp_uc_receive()", conn->name);
    155178
    156         if (conn->cstate == st_closed)
     179        fibril_mutex_lock(&conn->lock);
     180
     181        if (conn->cstate == st_closed) {
     182                fibril_mutex_unlock(&conn->lock);
    157183                return TCP_ENOTEXIST;
    158 
    159         fibril_mutex_lock(&conn->rcv_buf_lock);
     184        }
    160185
    161186        /* Wait for data to become available */
    162187        while (conn->rcv_buf_used == 0 && !conn->rcv_buf_fin && !conn->reset) {
    163188                log_msg(LVL_DEBUG, "tcp_uc_receive() - wait for data");
    164                 fibril_condvar_wait(&conn->rcv_buf_cv, &conn->rcv_buf_lock);
     189                fibril_condvar_wait(&conn->rcv_buf_cv, &conn->lock);
    165190        }
    166191
    167192        if (conn->rcv_buf_used == 0) {
    168                 fibril_mutex_unlock(&conn->rcv_buf_lock);
    169 
    170193                *rcvd = 0;
    171194                *xflags = 0;
     
    173196                if (conn->rcv_buf_fin) {
    174197                        /* End of data, peer closed connection */
     198                        fibril_mutex_unlock(&conn->lock);
    175199                        return TCP_ECLOSING;
    176200                } else {
    177201                        /* Connection was reset */
    178202                        assert(conn->reset);
     203                        fibril_mutex_unlock(&conn->lock);
    179204                        return TCP_ERESET;
    180205                }
     
    192217        conn->rcv_wnd += xfer_size;
    193218
    194         fibril_mutex_unlock(&conn->rcv_buf_lock);
    195 
    196219        /* TODO */
    197220        *xflags = 0;
     
    203226            conn->name, xfer_size);
    204227
     228        fibril_mutex_unlock(&conn->lock);
     229
    205230        return TCP_EOK;
    206231}
     
    211236        log_msg(LVL_DEBUG, "%s: tcp_uc_close()", conn->name);
    212237
    213         if (conn->cstate == st_closed)
     238        fibril_mutex_lock(&conn->lock);
     239
     240        if (conn->cstate == st_closed) {
     241                fibril_mutex_unlock(&conn->lock);
    214242                return TCP_ENOTEXIST;
    215 
    216         if (conn->snd_buf_fin)
     243        }
     244
     245        if (conn->snd_buf_fin) {
     246                fibril_mutex_unlock(&conn->lock);
    217247                return TCP_ECLOSING;
     248        }
    218249
    219250        conn->snd_buf_fin = true;
    220251        tcp_tqueue_new_data(conn);
    221252
     253        fibril_mutex_unlock(&conn->lock);
    222254        return TCP_EOK;
    223255}
     
    233265{
    234266        log_msg(LVL_DEBUG, "tcp_uc_status()");
    235 }
    236 
     267        cstatus->cstate = conn->cstate;
     268}
     269
     270/** Delete connection user call.
     271 *
     272 * (Not in spec.) Inform TCP that the user is done with this connection
     273 * and will not make any further calls/references to it. TCP can deallocate
     274 * the connection from now on.
     275 */
     276void tcp_uc_delete(tcp_conn_t *conn)
     277{
     278        log_msg(LVL_DEBUG, "tcp_uc_delete()");
     279        tcp_conn_delete(conn);
     280}
     281
     282void tcp_uc_set_cstate_cb(tcp_conn_t *conn, tcp_cstate_cb_t cb, void *arg)
     283{
     284        log_msg(LVL_DEBUG, "tcp_uc_set_ctate_cb(%p, %p, %p)",
     285            conn, cb, arg);
     286
     287        conn->cstate_cb = cb;
     288        conn->cstate_cb_arg = arg;
     289}
    237290
    238291/*
     
    249302            sp->local.addr.ipv4, sp->local.port);
    250303
    251         conn = tcp_conn_find(sp);
    252         if (conn != NULL && conn->cstate != st_closed) {
    253                 if (conn->ident.foreign.addr.ipv4 == TCP_IPV4_ANY)
    254                         conn->ident.foreign.addr.ipv4 = sp->foreign.addr.ipv4;
    255                 if (conn->ident.foreign.port == TCP_PORT_ANY)
    256                         conn->ident.foreign.port = sp->foreign.port;
    257                 if (conn->ident.local.addr.ipv4 == TCP_IPV4_ANY)
    258                         conn->ident.local.addr.ipv4 = sp->local.addr.ipv4;
    259 
    260                 tcp_conn_segment_arrived(conn, seg);
    261         } else {
    262                 if (conn == NULL)
    263                         log_msg(LVL_WARN, "No connection found.");
    264                 else
    265                         log_msg(LVL_WARN, "Connection is closed.");
     304        conn = tcp_conn_find_ref(sp);
     305        if (conn == NULL) {
     306                log_msg(LVL_WARN, "No connection found.");
    266307                tcp_unexpected_segment(sp, seg);
    267         }
     308                return;
     309        }
     310
     311        fibril_mutex_lock(&conn->lock);
     312
     313        if (conn->cstate == st_closed) {
     314                log_msg(LVL_WARN, "Connection is closed.");
     315                tcp_unexpected_segment(sp, seg);
     316                fibril_mutex_unlock(&conn->lock);
     317                tcp_conn_delref(conn);
     318                return;
     319        }
     320
     321        if (conn->ident.foreign.addr.ipv4 == TCP_IPV4_ANY)
     322                conn->ident.foreign.addr.ipv4 = sp->foreign.addr.ipv4;
     323        if (conn->ident.foreign.port == TCP_PORT_ANY)
     324                conn->ident.foreign.port = sp->foreign.port;
     325        if (conn->ident.local.addr.ipv4 == TCP_IPV4_ANY)
     326                conn->ident.local.addr.ipv4 = sp->local.addr.ipv4;
     327
     328        tcp_conn_segment_arrived(conn, seg);
     329
     330        fibril_mutex_unlock(&conn->lock);
     331        tcp_conn_delref(conn);
    268332}
    269333
Note: See TracChangeset for help on using the changeset viewer.