Navigation


Changeset 34:0e2b57789361 in freeDiameter for freeDiameter/peers.c


Ignore:
Timestamp:
Oct 30, 2009, 5:23:06 PM (15 years ago)
Author:
Sebastien Decugis <sdecugis@nict.go.jp>
Branch:
default
Phase:
public
Message:

Backup for the WE, some warnings remaining

File:
1 edited

Legend:

Unmodified
Added
Removed
  • freeDiameter/peers.c

    r33 r34  
    7878        CHECK_FCT( fd_fifo_new(&p->p_events) );
    7979        CHECK_FCT( fd_fifo_new(&p->p_tosend) );
    80         fd_list_init(&p->p_sentreq, p);
     80        fd_list_init(&p->p_sr.srs, p);
     81        CHECK_POSIX( pthread_mutex_init(&p->p_sr.mtx, NULL) );
    8182       
    8283        return 0;
     
    180181        }
    181182
     183/* Empty the lists of p_tosend and p_sentreq messages */
     184void fd_peer_failover_msg(struct fd_peer * peer)
     185{
     186        struct msg *m;
     187        TRACE_ENTRY("%p", peer);
     188        CHECK_PARAMS_DO(CHECK_PEER(peer), return);
     189       
     190        /* Requeue all messages in the "out" queue */
     191        while ( fd_fifo_tryget(peer->p_tosend, &m) == 0 ) {
     192                CHECK_FCT_DO(fd_fifo_post(fd_g_outgoing, &m),
     193                                /* fallback: destroy the message */
     194                                CHECK_FCT_DO(fd_msg_free(m), /* What can we do more? */));
     195        }
     196       
     197        /* Requeue all routable sent requests */
     198        fd_p_sr_failover(&peer->p_sr);
     199       
     200        /* Done */
     201        return;
     202}
     203
    182204/* Destroy a structure once all cleanups have been performed */
    183205int fd_peer_free(struct fd_peer ** ptr)
     
    197219        free_null(p->p_hdr.info.pi_realm);
    198220        free_list( &p->p_hdr.info.pi_endpoints );
    199         /* Assume the security data is already freed */
     221        TODO("Free the security data if any ?");
    200222        free_null(p->p_hdr.info.pi_prodname);
    201223        free_list( &p->p_hdr.info.pi_apps );
     
    214236       
    215237        CHECK_FCT( fd_thr_term(&p->p_outthr) );
    216         while ( fd_fifo_tryget(p->p_tosend, &t) == 0 ) {
    217                 struct msg * m = t;
    218                 TRACE_DEBUG(FULL, "Found message %p in outgoing queue of peer %p being destroyed, requeue", m, p);
    219                 /* We simply requeue in global, the routing thread will re-handle it. */
    220                 CHECK_FCT(fd_fifo_post(fd_g_outgoing, &m));
    221         }
    222         CHECK_FCT( fd_fifo_del(&p->p_tosend) );
    223        
    224         while (!FD_IS_LIST_EMPTY(&p->p_sentreq)) {
    225                 struct sentreq * sr = (struct sentreq *)(p->p_sentreq.next);
    226                 fd_list_unlink(&sr->chain);
    227                 TRACE_DEBUG(FULL, "Found message %p in list of sent requests to peer %p being destroyed, requeue (fallback)", sr->req, p);
    228                 CHECK_FCT(fd_fifo_post(fd_g_outgoing, &sr->req));
    229                 free(sr);
    230         }
    231238       
    232239        if (p->p_cnxctx) {
     
    234241        }
    235242       
     243        /* Requeue any remaining message into global structures if possible */
     244        fd_peer_failover_msg(p);
     245        CHECK_FCT_DO( fd_fifo_del(&p->p_tosend), /* continue */ );
     246        CHECK_POSIX_DO( pthread_mutex_destroy(&p->p_sr.mtx), /* continue */);
     247       
     248        /* If the callback is still around... */
    236249        if (p->p_cb)
    237250                (*p->p_cb)(NULL, p->p_cb_data);
    238251       
     252        /* Free the structure */
    239253        free(p);
    240        
    241254        return 0;
    242255}
Note: See TracChangeset for help on using the changeset viewer.