Ejemplo n.º 1
0
void mq_stream_read_destroy(mq_stream_t *mqs)
{

    log_printf(1, "START msid=%d\n", mqs->msid);

    if (mqs->mpool == NULL) {  //** Nothing to do
        pack_destroy(mqs->pack);
        if (mqs->stream_id != NULL) free(mqs->stream_id);
        free(mqs);
        return;
    }

    //** Change the flag which signals we don't want anything else
    apr_thread_mutex_lock(mqs->lock);
    mqs->want_more = MQS_ABORT;

    //** Consume all the current data and request the pending
    while ((mqs->gop_processed != NULL) || (mqs->gop_waiting != NULL)) {
        log_printf(1, "Clearing pending processed=%d waiting=%p msid=%d\n", mqs->gop_processed, mqs->gop_waiting, mqs->msid);
        if (mqs->gop_processed != NULL) log_printf(1, "processed gid=%d\n", gop_id(mqs->gop_processed));
        if (mqs->gop_waiting != NULL) log_printf(1, "waiting gid=%d\n", gop_id(mqs->gop_waiting));
        mqs->want_more = MQS_ABORT;
        apr_thread_mutex_unlock(mqs->lock);
        mq_stream_read_wait(mqs);
        apr_thread_mutex_lock(mqs->lock);
    }

    if (log_level() >= 15) {
        char *rhost = mq_address_to_string(mqs->remote_host);
        log_printf(15, "remote_host as string = %s\n", rhost);
        if (rhost) free(rhost);
    }
    if (mqs->remote_host != NULL) mq_ongoing_host_dec(mqs->ongoing, mqs->remote_host, mqs->host_id, mqs->hid_len);

    apr_thread_mutex_unlock(mqs->lock);

    log_printf(2, "msid=%d transfer_packets=%d\n", mqs->msid, mqs->transfer_packets);

    //** Clean up
    if (mqs->stream_id != NULL) free(mqs->stream_id);
    pack_destroy(mqs->pack);
    apr_thread_mutex_destroy(mqs->lock);
    apr_thread_cond_destroy(mqs->cond);
    apr_pool_destroy(mqs->mpool);
    if (mqs->remote_host != NULL) mq_msg_destroy(mqs->remote_host);
    free(mqs);

    return;
}
Ejemplo n.º 2
0
// wait for "timeout" milliseconds to receive a packet on socket "s"
pack_t* sock_receive( sock_t* s, int timeout, unsigned long long* wait_ts )
{
	int res_cs, res_ur;
	assert( s );

	timeout = timeout < 0 ? 0 : timeout;
	res_cs = SDLNet_CheckSockets( s->sset, timeout );	assert( res_cs != -1 );
	if( wait_ts )		*wait_ts = get_t();
	if( !res_cs )		return NULL;			// no_activity

	pack_t* pck = pack_create( NULL, -1 );
	res_ur = SDLNet_UDP_Recv( s->sock, pck->p );
	if( res_ur == -1 ){printf("[E] Error receiving UDP packet");pack_destroy(pck);return NULL;}
	if( res_ur ==  0 ){printf("[W] No UDP packet received on an active port");pack_destroy(pck);return NULL;}
	s->bytes_recv += pck->p->len;

	pck->type = streamer_rdint( pck->st );
	return pck;
}
Ejemplo n.º 3
0
void sock_send( sock_t* s, pack_t* pck )
{
	int res_us;
	assert( s && pck );

	res_us = SDLNet_UDP_Send( s->sock, -1, pck->p );
	if( res_us == 0 )	printf("[E] Error sending UDP packet\n");

	s->bytes_sent += ( pck->p->status > 0 ? pck->p->status : 0 );
	pack_destroy(pck);
}