Ignore:
File:
1 edited

Legend:

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

    r0edaf0f6 r74c99b5  
    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->lock);
     85        fibril_mutex_lock(&nconn->cstate_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->lock);
     89                fibril_condvar_wait(&nconn->cstate_cv, &nconn->cstate_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->lock);
     95                fibril_mutex_unlock(&nconn->cstate_lock);
    9696                return TCP_ERESET;
    9797        }
    9898
    99         fibril_mutex_unlock(&nconn->lock);
     99        fibril_mutex_unlock(&nconn->cstate_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         fibril_mutex_lock(&conn->lock);
    116 
    117         if (conn->cstate == st_closed) {
    118                 fibril_mutex_unlock(&conn->lock);
     115        if (conn->cstate == st_closed)
    119116                return TCP_ENOTEXIST;
    120         }
    121117
    122118        if (conn->cstate == st_listen) {
     
    125121        }
    126122
    127 
    128         if (conn->snd_buf_fin) {
    129                 fibril_mutex_unlock(&conn->lock);
     123        if (conn->snd_buf_fin)
    130124                return TCP_ECLOSING;
    131         }
    132125
    133126        while (size > 0) {
    134127                buf_free = conn->snd_buf_size - conn->snd_buf_used;
    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);
     128                while (buf_free == 0 && !conn->reset)
     129                        tcp_tqueue_new_data(conn);
     130
     131                if (conn->reset)
    144132                        return TCP_ERESET;
    145                 }
    146133
    147134                xfer_size = min(size, buf_free);
     
    152139                conn->snd_buf_used += xfer_size;
    153140                size -= xfer_size;
    154 
    155                 tcp_tqueue_new_data(conn);
    156141        }
    157142
    158143        tcp_tqueue_new_data(conn);
    159         fibril_mutex_unlock(&conn->lock);
    160144
    161145        return TCP_EOK;
     
    170154        log_msg(LVL_DEBUG, "%s: tcp_uc_receive()", conn->name);
    171155
    172         fibril_mutex_lock(&conn->lock);
    173 
    174         if (conn->cstate == st_closed) {
    175                 fibril_mutex_unlock(&conn->lock);
     156        if (conn->cstate == st_closed)
    176157                return TCP_ENOTEXIST;
    177         }
     158
     159        fibril_mutex_lock(&conn->rcv_buf_lock);
    178160
    179161        /* Wait for data to become available */
    180162        while (conn->rcv_buf_used == 0 && !conn->rcv_buf_fin && !conn->reset) {
    181163                log_msg(LVL_DEBUG, "tcp_uc_receive() - wait for data");
    182                 fibril_condvar_wait(&conn->rcv_buf_cv, &conn->lock);
     164                fibril_condvar_wait(&conn->rcv_buf_cv, &conn->rcv_buf_lock);
    183165        }
    184166
    185167        if (conn->rcv_buf_used == 0) {
     168                fibril_mutex_unlock(&conn->rcv_buf_lock);
     169
    186170                *rcvd = 0;
    187171                *xflags = 0;
     
    189173                if (conn->rcv_buf_fin) {
    190174                        /* End of data, peer closed connection */
    191                         fibril_mutex_unlock(&conn->lock);
    192175                        return TCP_ECLOSING;
    193176                } else {
    194177                        /* Connection was reset */
    195178                        assert(conn->reset);
    196                         fibril_mutex_unlock(&conn->lock);
    197179                        return TCP_ERESET;
    198180                }
     
    210192        conn->rcv_wnd += xfer_size;
    211193
     194        fibril_mutex_unlock(&conn->rcv_buf_lock);
     195
    212196        /* TODO */
    213197        *xflags = 0;
     
    219203            conn->name, xfer_size);
    220204
    221         fibril_mutex_unlock(&conn->lock);
    222 
    223205        return TCP_EOK;
    224206}
     
    229211        log_msg(LVL_DEBUG, "%s: tcp_uc_close()", conn->name);
    230212
    231         fibril_mutex_lock(&conn->lock);
    232 
    233         if (conn->cstate == st_closed) {
    234                 fibril_mutex_unlock(&conn->lock);
     213        if (conn->cstate == st_closed)
    235214                return TCP_ENOTEXIST;
    236         }
    237 
    238         if (conn->snd_buf_fin) {
    239                 fibril_mutex_unlock(&conn->lock);
     215
     216        if (conn->snd_buf_fin)
    240217                return TCP_ECLOSING;
    241         }
    242218
    243219        conn->snd_buf_fin = true;
    244220        tcp_tqueue_new_data(conn);
    245221
    246         fibril_mutex_unlock(&conn->lock);
    247222        return TCP_EOK;
    248223}
     
    260235}
    261236
    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  */
    268 void tcp_uc_delete(tcp_conn_t *conn)
    269 {
    270         log_msg(LVL_DEBUG, "tcp_uc_delete()");
    271         tcp_conn_delete(conn);
    272 }
    273237
    274238/*
     
    285249            sp->local.addr.ipv4, sp->local.port);
    286250
    287         conn = tcp_conn_find_ref(sp);
    288         if (conn == NULL) {
    289                 log_msg(LVL_WARN, "No connection found.");
     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.");
    290266                tcp_unexpected_segment(sp, seg);
    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);
     267        }
    315268}
    316269
Note: See TracChangeset for help on using the changeset viewer.