Fork us on GitHub Follow us on Facebook Follow us on Twitter

Changeset 7a8c1c4e in mainline


Ignore:
Timestamp:
2011-12-14T17:11:31Z (10 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master
Children:
0edaf0f6
Parents:
bbf159a
Message:

Deallocate connection structures.

Location:
uspace/srv/net/tl/tcp
Files:
6 edited

Legend:

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

    rbbf159a r7a8c1c4e  
    6161static void tcp_conn_tw_timer_clear(tcp_conn_t *conn);
    6262
    63 /** Create new segment structure.
     63/** Create new connection structure.
    6464 *
    6565 * @param lsock         Local socket (will be deeply copied)
    6666 * @param fsock         Foreign socket (will be deeply copied)
    67  * @return              New segment or NULL
     67 * @return              New connection or NULL
    6868 */
    6969tcp_conn_t *tcp_conn_new(tcp_sock_t *lsock, tcp_sock_t *fsock)
     
    120120        conn->cstate = st_listen;
    121121        conn->reset = false;
     122        conn->deleted = false;
    122123        conn->ap = ap_passive;
    123124        conn->fin_is_acked = false;
     
    143144}
    144145
     146/** Destroy connection structure.
     147 *
     148 * Connection structure should be destroyed when both of two conditions are
     149 * met: (1) user has deleted the connection and (2) the connection has entered
     150 * closed state.
     151 *
     152 * @param conn          Connection
     153 */
     154static void tcp_conn_free(tcp_conn_t *conn)
     155{
     156        log_msg(LVL_DEBUG, "%s: tcp_conn_free(%p)", conn->name, conn);
     157        tcp_tqueue_fini(&conn->retransmit);
     158
     159        if (conn->rcv_buf != NULL)
     160                free(conn->rcv_buf);
     161        if (conn->snd_buf != NULL)
     162                free(conn->snd_buf);
     163        if (conn->tw_timer != NULL)
     164                fibril_timer_destroy(conn->tw_timer);
     165        free(conn);
     166}
     167
     168/** Delete connection.
     169 *
     170 * The caller promises not make no further references to @a conn.
     171 * TCP will free @a conn eventually.
     172 *
     173 * @param conn          Connection
     174 */
     175void tcp_conn_delete(tcp_conn_t *conn)
     176{
     177        fibril_mutex_lock(&conn->cstate_lock);
     178        conn->deleted = true;
     179
     180        if (conn->cstate == st_closed) {
     181                fibril_mutex_unlock(&conn->cstate_lock);
     182                tcp_conn_free(conn);
     183        } else {
     184                fibril_mutex_unlock(&conn->cstate_lock);
     185        }
     186}
     187
    145188/** Enlist connection.
    146189 *
     
    166209        conn->cstate = nstate;
    167210        fibril_condvar_broadcast(&conn->cstate_cv);
    168         fibril_mutex_unlock(&conn->cstate_lock);
     211
     212        if (nstate == st_closed && conn->deleted) {
     213                fibril_mutex_unlock(&conn->cstate_lock);
     214                tcp_conn_free(conn);
     215        } else {
     216                fibril_mutex_unlock(&conn->cstate_lock);
     217        }
    169218}
    170219
  • uspace/srv/net/tl/tcp/conn.h

    rbbf159a r7a8c1c4e  
    4040
    4141extern tcp_conn_t *tcp_conn_new(tcp_sock_t *, tcp_sock_t *);
     42extern void tcp_conn_delete(tcp_conn_t *);
    4243extern void tcp_conn_add(tcp_conn_t *);
    4344extern void tcp_conn_remove(tcp_conn_t *);
  • uspace/srv/net/tl/tcp/sock.c

    rbbf159a r7a8c1c4e  
    615615        } while (trc == TCP_EOK);
    616616
     617        tcp_uc_delete(socket->conn);
     618
    617619        rc = socket_destroy(net_sess, socket_id, &client->sockets, &gsock,
    618620            tcp_free_sock_data);
  • uspace/srv/net/tl/tcp/tcp_type.h

    rbbf159a r7a8c1c4e  
    166166        /** True if connection was reset */
    167167        bool reset;
     168        /** True if connection was deleted by user */
     169        bool deleted;
    168170        /** Protects @c cstate */
    169171        fibril_mutex_t cstate_lock;
  • uspace/srv/net/tl/tcp/ucall.c

    rbbf159a r7a8c1c4e  
    251251}
    252252
     253/** Delete connection user call.
     254 *
     255 * (Not in spec.) Inform TCP that the user is done with this connection
     256 * and will not make any further calls/references to it. TCP can deallocate
     257 * the connection from now on.
     258 */
     259void tcp_uc_delete(tcp_conn_t *conn)
     260{
     261        log_msg(LVL_DEBUG, "tcp_uc_delete()");
     262        tcp_conn_delete(conn);
     263}
    253264
    254265/*
  • uspace/srv/net/tl/tcp/ucall.h

    rbbf159a r7a8c1c4e  
    4848extern void tcp_uc_abort(tcp_conn_t *);
    4949extern void tcp_uc_status(tcp_conn_t *, tcp_conn_status_t *);
     50extern void tcp_uc_delete(tcp_conn_t *);
    5051
    5152/*
Note: See TracChangeset for help on using the changeset viewer.