Changeset b99f6e2 in mainline for uspace/srv/net/tcp/service.c


Ignore:
Timestamp:
2015-05-11T16:15:54Z (10 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
d6ff08a0
Parents:
309469de
Message:

Accepting connections.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/net/tcp/service.c

    r309469de rb99f6e2  
    5959static void tcp_ev_conn_failed(tcp_cconn_t *);
    6060static void tcp_ev_conn_reset(tcp_cconn_t *);
     61static void tcp_ev_new_conn(tcp_clst_t *, tcp_cconn_t *);
    6162
    6263static void tcp_service_cstate_change(tcp_conn_t *, void *, tcp_cstate_t);
    6364static void tcp_service_recv_data(tcp_conn_t *, void *);
     65static void tcp_service_lst_cstate_change(tcp_conn_t *, void *, tcp_cstate_t);
     66
     67static int tcp_cconn_create(tcp_client_t *, tcp_conn_t *, tcp_cconn_t **);
    6468
    6569static tcp_cb_t tcp_service_cb = {
     
    6872};
    6973
     74static tcp_cb_t tcp_service_lst_cb = {
     75        .cstate_change = tcp_service_lst_cstate_change,
     76        .recv_data = NULL
     77};
     78
    7079static void tcp_service_cstate_change(tcp_conn_t *conn, void *arg,
    7180    tcp_cstate_t old_state)
     
    93102}
    94103
     104static void tcp_service_lst_cstate_change(tcp_conn_t *conn, void *arg,
     105    tcp_cstate_t old_state)
     106{
     107        tcp_cstate_t nstate;
     108        tcp_clst_t *clst;
     109        tcp_cconn_t *cconn;
     110        int rc;
     111        tcp_error_t trc;
     112
     113        log_msg(LOG_DEFAULT, LVL_DEBUG, "tcp_service_lst_cstate_change()");
     114        nstate = conn->cstate;
     115        clst = tcp_uc_get_userptr(conn);
     116
     117        if ((old_state == st_syn_sent || old_state == st_syn_received) &&
     118            (nstate == st_established)) {
     119                /* Connection established */
     120                clst->conn = NULL;
     121
     122                rc = tcp_cconn_create(clst->client, conn, &cconn);
     123                if (rc != EOK) {
     124                        /* XXX Could not create client connection */
     125                        return;
     126                }
     127
     128                /* XXX Is there a race here (i.e. the connection is already active)? */
     129                tcp_uc_set_cb(conn, &tcp_service_cb, cconn);
     130
     131                /* New incoming connection */
     132                tcp_ev_new_conn(clst, cconn);
     133        }
     134
     135        if (old_state != st_closed && nstate == st_closed && conn->reset) {
     136                /* Connection reset */
     137                /* XXX */
     138        }
     139
     140        /* XXX Failed to establish connection */
     141        if (0) {
     142                /* XXX */
     143        }
     144
     145        /* Replenish sentinel connection */
     146
     147        trc = tcp_uc_open(&clst->elocal, NULL, ap_passive, tcp_open_nonblock,
     148            &conn);
     149        if (trc != TCP_EOK) {
     150                /* XXX Could not replenish connection */
     151                return;
     152        }
     153
     154        clst->conn = conn;
     155
     156        /* XXX Is there a race here (i.e. the connection is already active)? */
     157        tcp_uc_set_cb(conn, &tcp_service_lst_cb, clst);
     158}
     159
    95160static void tcp_service_recv_data(tcp_conn_t *conn, void *arg)
    96161{
     
    150215        exch = async_exchange_begin(cconn->client->sess);
    151216        aid_t req = async_send_1(exch, TCP_EV_CONN_RESET, cconn->id, NULL);
     217        async_exchange_end(exch);
     218
     219        async_forget(req);
     220}
     221
     222/** New incoming connection */
     223static void tcp_ev_new_conn(tcp_clst_t *clst, tcp_cconn_t *cconn)
     224{
     225        async_exch_t *exch;
     226
     227        log_msg(LOG_DEFAULT, LVL_DEBUG, "tcp_ev_new_conn()");
     228
     229        exch = async_exchange_begin(clst->client->sess);
     230        aid_t req = async_send_2(exch, TCP_EV_NEW_CONN, clst->id, cconn->id,
     231            NULL);
    152232        async_exchange_end(exch);
    153233
     
    343423        local.port = ep->port;
    344424
    345         trc = tcp_uc_open(&local, NULL, ap_passive, 0, &conn);
     425        trc = tcp_uc_open(&local, NULL, ap_passive, tcp_open_nonblock, &conn);
    346426        if (trc != TCP_EOK)
    347427                return EIO;
     
    354434        }
    355435
    356 //      assoc->cb = &udp_cassoc_cb;
    357 //      assoc->cb_arg = cassoc;
     436        clst->elocal = local;
     437
     438        /* XXX Is there a race here (i.e. the connection is already active)? */
     439        tcp_uc_set_cb(conn, &tcp_service_lst_cb, clst);
    358440
    359441        *rlst_id = clst->id;
Note: See TracChangeset for help on using the changeset viewer.