コード例 #1
0
void
CBFDNSSDService::Cleanup()
{
	m_stopped = PR_TRUE;
	if ( m_job )
	{
		PR_CancelJob( m_job );
		m_job = NULL;
	}
	
	if ( m_threadPool != NULL )
	{
		PR_ShutdownThreadPool( m_threadPool );
		m_threadPool = NULL;
	}
	
	if ( m_fileDesc != NULL )
	{
		PR_Close( m_fileDesc );
		m_fileDesc = NULL;
	}
	
	if ( m_sdRef )
	{
		DNSServiceRefDeallocate( m_sdRef );
		m_sdRef = NULL;
	}
}
コード例 #2
0
void
CDNSSDService::Cleanup()
{
	if ( m_master )
	{
		if ( m_job )
		{
			PR_CancelJob( m_job );
			m_job = NULL;
		}

		if ( m_threadPool != NULL )
		{	
			PR_ShutdownThreadPool( m_threadPool );
			m_threadPool = NULL;
		}
	
		if ( m_fileDesc != NULL )
		{
			PR_Close( m_fileDesc );
			m_fileDesc = NULL;
		}

		if ( m_mainRef )
		{
			DNSServiceRefDeallocate( m_mainRef );
			m_mainRef = NULL;
		}
	}
	else
	{
		if ( m_subRef )
		{
			DNSServiceRefDeallocate( m_subRef );
			m_subRef = NULL;
		}
	}
}
コード例 #3
0
static void
TCP_Server_Accept(void *arg)
{
    Server_Param *sp = (Server_Param *) arg;
    PRThreadPool *tp = sp->tp;
    Serve_Client_Param *scp;
	PRFileDesc *newsockfd;
	PRJob *jobp;

	if ((newsockfd = PR_Accept(sp->iod.socket, &sp->netaddr,
		PR_INTERVAL_NO_TIMEOUT)) == NULL) {
		fprintf(stderr,"%s: ERROR - PR_Accept failed\n", program_name);
		failed_already=1;
		goto exit;
	}
	scp = PR_NEW(Serve_Client_Param);
	if (scp == NULL) {
		fprintf(stderr,"%s: PR_NEW failed\n", program_name);
		failed_already=1;
		goto exit;
	}

	/*
	 * Start a Serve_Client job for each incoming connection
	 */
	scp->iod.socket = newsockfd;
	scp->iod.timeout = PR_SecondsToInterval(60);
	scp->datalen = tcp_mesg_size;
	scp->exit_mon = sp->exit_mon;
	scp->job_counterp = sp->job_counterp;
	scp->tp = sp->tp;

	PR_EnterMonitor(sp->exit_mon);
	(*sp->job_counterp)++;
	PR_ExitMonitor(sp->exit_mon);
	jobp = PR_QueueJob(tp, Serve_Client, scp,
						PR_FALSE);

	PR_ASSERT(NULL != jobp);
	DPRINTF(("TCP_Server: Created Serve_Client = 0x%lx\n", jobp));

	/*
	 * single-threaded update; no lock needed
	 */
    sp->conn_counter++;
    if (sp->conn_counter <
			(num_tcp_clients * num_tcp_connections_per_client)) {
		jobp = PR_QueueJob_Accept(tp, &sp->iod, TCP_Server_Accept, sp,
								PR_FALSE);
		PR_ASSERT(NULL != jobp);
		return;
	}
	jobp = PR_QueueJob_Timer(tp, PR_MillisecondsToInterval(500),
						print_stats, sp, PR_FALSE);

	PR_ASSERT(NULL != jobp);
	DPRINTF(("TCP_Server: Created print_stats timer job = 0x%lx\n", jobp));

exit:
	PR_EnterMonitor(sp->exit_mon);
    /* Wait for server jobs to finish */
    while (0 != *sp->job_counterp) {
        PR_Wait(sp->exit_mon, PR_INTERVAL_NO_TIMEOUT);
        DPRINTF(("TCP_Server: conn_counter = %d\n",
												*sp->job_counterp));
    }

    PR_ExitMonitor(sp->exit_mon);
    if (sp->iod.socket) {
        PR_Close(sp->iod.socket);
    }
	PR_DestroyMonitor(sp->exit_mon);
    printf("%30s","TCP_Socket_Client_Server_Test:");
    printf("%2ld Server %2ld Clients %2ld connections_per_client\n",1l,
        num_tcp_clients, num_tcp_connections_per_client);
    printf("%30s %2ld messages_per_connection %4ld bytes_per_message\n",":",
        num_tcp_mesgs_per_connection, tcp_mesg_size);

	DPRINTF(("%s: calling PR_ShutdownThreadPool\n", program_name));
	PR_ShutdownThreadPool(sp->tp);
	PR_DELETE(sp);
}