Changeset 7a8c1c4e in mainline for uspace/srv/net/tl/tcp/conn.c


Ignore:
Timestamp:
2011-12-14T17:11:31Z (12 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
0edaf0f6
Parents:
bbf159a
Message:

Deallocate connection structures.

File:
1 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
Note: See TracChangeset for help on using the changeset viewer.