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


Ignore:
Timestamp:
2011-12-19T18:50:17Z (12 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
1440eae, d9cf684a
Parents:
58f6229 (diff), 522a4f9 (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 TCP improvements.

File:
1 edited

Legend:

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

    r58f6229 ra438de4  
    8383        /* Wait for connection to be established or reset */
    8484        log_msg(LVL_DEBUG, "tcp_uc_open: Wait for connection.");
    85         fibril_mutex_lock(&nconn->cstate_lock);
     85        fibril_mutex_lock(&nconn->lock);
    8686        while (nconn->cstate == st_listen ||
    8787            nconn->cstate == st_syn_sent ||
    8888            nconn->cstate == st_syn_received) {
    89                 fibril_condvar_wait(&nconn->cstate_cv, &nconn->cstate_lock);
     89                fibril_condvar_wait(&nconn->cstate_cv, &nconn->lock);
    9090        }
    9191
     
    9393                log_msg(LVL_DEBUG, "tcp_uc_open: Connection was reset.");
    9494                assert(nconn->cstate == st_closed);
    95                 fibril_mutex_unlock(&nconn->cstate_lock);
     95                fibril_mutex_unlock(&nconn->lock);
    9696                return TCP_ERESET;
    9797        }
    9898
    99         fibril_mutex_unlock(&nconn->cstate_lock);
     99        fibril_mutex_unlock(&nconn->lock);
    100100        log_msg(LVL_DEBUG, "tcp_uc_open: Connection was established.");
    101101
     
    113113        log_msg(LVL_DEBUG, "%s: tcp_uc_send()", conn->name);
    114114
    115         if (conn->cstate == st_closed)
     115        fibril_mutex_lock(&conn->lock);
     116
     117        if (conn->cstate == st_closed) {
     118                fibril_mutex_unlock(&conn->lock);
    116119                return TCP_ENOTEXIST;
     120        }
    117121
    118122        if (conn->cstate == st_listen) {
     
    121125        }
    122126
    123         if (conn->snd_buf_fin)
     127
     128        if (conn->snd_buf_fin) {
     129                fibril_mutex_unlock(&conn->lock);
    124130                return TCP_ECLOSING;
     131        }
    125132
    126133        while (size > 0) {
    127134                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)
     135                while (buf_free == 0 && !conn->reset) {
     136                        log_msg(LVL_DEBUG, "%s: buf_free == 0, waiting.",
     137                            conn->name);
     138                        fibril_condvar_wait(&conn->snd_buf_cv, &conn->lock);
     139                        buf_free = conn->snd_buf_size - conn->snd_buf_used;
     140                }
     141
     142                if (conn->reset) {
     143                        fibril_mutex_unlock(&conn->lock);
    132144                        return TCP_ERESET;
     145                }
    133146
    134147                xfer_size = min(size, buf_free);
     
    139152                conn->snd_buf_used += xfer_size;
    140153                size -= xfer_size;
     154
     155                tcp_tqueue_new_data(conn);
    141156        }
    142157
    143158        tcp_tqueue_new_data(conn);
     159        fibril_mutex_unlock(&conn->lock);
    144160
    145161        return TCP_EOK;
     
    154170        log_msg(LVL_DEBUG, "%s: tcp_uc_receive()", conn->name);
    155171
    156         if (conn->cstate == st_closed)
     172        fibril_mutex_lock(&conn->lock);
     173
     174        if (conn->cstate == st_closed) {
     175                fibril_mutex_unlock(&conn->lock);
    157176                return TCP_ENOTEXIST;
    158 
    159         fibril_mutex_lock(&conn->rcv_buf_lock);
     177        }
    160178
    161179        /* Wait for data to become available */
    162180        while (conn->rcv_buf_used == 0 && !conn->rcv_buf_fin && !conn->reset) {
    163181                log_msg(LVL_DEBUG, "tcp_uc_receive() - wait for data");
    164                 fibril_condvar_wait(&conn->rcv_buf_cv, &conn->rcv_buf_lock);
     182                fibril_condvar_wait(&conn->rcv_buf_cv, &conn->lock);
    165183        }
    166184
    167185        if (conn->rcv_buf_used == 0) {
    168                 fibril_mutex_unlock(&conn->rcv_buf_lock);
    169 
    170186                *rcvd = 0;
    171187                *xflags = 0;
     
    173189                if (conn->rcv_buf_fin) {
    174190                        /* End of data, peer closed connection */
     191                        fibril_mutex_unlock(&conn->lock);
    175192                        return TCP_ECLOSING;
    176193                } else {
    177194                        /* Connection was reset */
    178195                        assert(conn->reset);
     196                        fibril_mutex_unlock(&conn->lock);
    179197                        return TCP_ERESET;
    180198                }
     
    192210        conn->rcv_wnd += xfer_size;
    193211
    194         fibril_mutex_unlock(&conn->rcv_buf_lock);
    195 
    196212        /* TODO */
    197213        *xflags = 0;
     
    203219            conn->name, xfer_size);
    204220
     221        fibril_mutex_unlock(&conn->lock);
     222
    205223        return TCP_EOK;
    206224}
     
    211229        log_msg(LVL_DEBUG, "%s: tcp_uc_close()", conn->name);
    212230
    213         if (conn->cstate == st_closed)
     231        fibril_mutex_lock(&conn->lock);
     232
     233        if (conn->cstate == st_closed) {
     234                fibril_mutex_unlock(&conn->lock);
    214235                return TCP_ENOTEXIST;
    215 
    216         if (conn->snd_buf_fin)
     236        }
     237
     238        if (conn->snd_buf_fin) {
     239                fibril_mutex_unlock(&conn->lock);
    217240                return TCP_ECLOSING;
     241        }
    218242
    219243        conn->snd_buf_fin = true;
    220244        tcp_tqueue_new_data(conn);
    221245
     246        fibril_mutex_unlock(&conn->lock);
    222247        return TCP_EOK;
    223248}
     
    235260}
    236261
     262/** Delete connection user call.
     263 *
     264 * (Not in spec.) Inform TCP that the user is done with this connection
     265 * and will not make any further calls/references to it. TCP can deallocate
     266 * the connection from now on.
     267 */
     268void tcp_uc_delete(tcp_conn_t *conn)
     269{
     270        log_msg(LVL_DEBUG, "tcp_uc_delete()");
     271        tcp_conn_delete(conn);
     272}
    237273
    238274/*
     
    249285            sp->local.addr.ipv4, sp->local.port);
    250286
    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.");
     287        conn = tcp_conn_find_ref(sp);
     288        if (conn == NULL) {
     289                log_msg(LVL_WARN, "No connection found.");
    266290                tcp_unexpected_segment(sp, seg);
    267         }
     291                return;
     292        }
     293
     294        fibril_mutex_lock(&conn->lock);
     295
     296        if (conn->cstate == st_closed) {
     297                log_msg(LVL_WARN, "Connection is closed.");
     298                tcp_unexpected_segment(sp, seg);
     299                fibril_mutex_unlock(&conn->lock);
     300                tcp_conn_delref(conn);
     301                return;
     302        }
     303
     304        if (conn->ident.foreign.addr.ipv4 == TCP_IPV4_ANY)
     305                conn->ident.foreign.addr.ipv4 = sp->foreign.addr.ipv4;
     306        if (conn->ident.foreign.port == TCP_PORT_ANY)
     307                conn->ident.foreign.port = sp->foreign.port;
     308        if (conn->ident.local.addr.ipv4 == TCP_IPV4_ANY)
     309                conn->ident.local.addr.ipv4 = sp->local.addr.ipv4;
     310
     311        tcp_conn_segment_arrived(conn, seg);
     312
     313        fibril_mutex_unlock(&conn->lock);
     314        tcp_conn_delref(conn);
    268315}
    269316
Note: See TracChangeset for help on using the changeset viewer.