Ejemplo n.º 1
0
void ProtocolManager::onConfig(Metadata *m)
{
	Metadata *pm = m->getMetadata("TCPServer");

	if (pm) {
		const char *param = pm->getParameter("port");

		if (param) {
			char *endptr = NULL;
			unsigned short port = (unsigned short)strtoul(param, &endptr, 10);
			
			if (endptr && endptr != param) {
				tcpServerPort = port;
				LOG_ADD("# %s: setting TCP server port to %u\n", getName(), tcpServerPort);
			}
		}

		param = pm->getParameter("backlog");

		if (param) {
			char *endptr = NULL;
			int backlog = (int)strtol(param, &endptr, 10);
			
			if (endptr && endptr != param && backlog > 0) {
				tcpBacklog = backlog;
				LOG_ADD("# %s: setting TCP backlog to %d\n", getName(), tcpBacklog);
			}
		}
	}
}
Ejemplo n.º 2
0
void DebugManager::onDebugReport(Event *e)
{
	LOG_ADD("%s: kernel event queue size=%lu\n", 
		Timeval::now().getAsString().c_str(), kernel->size()); 
	kernel->getNodeStore()->print();
	kernel->getInterfaceStore()->print();

#ifdef DEBUG_DATASTORE
	kernel->getDataStore()->print();
#endif
	kernel->addEvent(new Event(debugEType, NULL, 30));
}
Ejemplo n.º 3
0
int
tb_stream_server(tb_listener_t *listener)
{
	PRT_INFO("Listening");
	tb_listen(listener);
	listener->status = TB_LISTENING;

	while(!(listener->command & TB_E_LOOP)){
		PRT_INFO("Accepting");
		LOG(listener, "Accepting", LOG_INFO);

		tb_session_t *session = tb_create_server_session();

		session->sock_d = accept(listener->sock_d,
				(struct sockaddr*)session->addr_in,
				&session->addr_len);

		//Start timing.
		tb_start_time(listener->transfer_time);

		if(session->sock_d == -1)
		{
			PRT_ERR("Error: tb_stream_server: accept");
			tb_abort(listener);
		}

		LOG_ADD(listener, "Connected address:", session->addr_in);
		session->data = malloc(listener->bufsize);
		session->data_size = listener->bufsize;
		listener->curr_session = session;
		listener->status = TB_CONNECTED;

		do
		{
			tb_recv_data(listener, session);

			session->total_bytes += session->last_trans;
			listener->total_tx_rx += session->last_trans;
		}
		while(session->last_trans != 0 && !(listener->command & TB_E_LOOP));

		tb_finish_time(listener->transfer_time);

		//Lock while destroying session and closing connection
		pthread_mutex_trylock(&listener->stat_lock);

		PRT_INFO("Session closed\n");
		listener->status = TB_DISCONNECTED;

		//Close and destroy current session
		close(session->sock_d);
		tb_destroy_session(session);
		listener->curr_session = NULL;
		PRT_INFO("Session destroyed");

		//Close connection
		listener->protocol->f_close(session->sock_d);

		pthread_mutex_unlock(&listener->stat_lock);

		listener->command = listener->s_tx_end;
	}

	listener->protocol->f_close(listener->sock_d);
	listener->sock_d = -1;

	return listener->total_tx_rx;
}
Ejemplo n.º 4
0
float LOG_ADD_THREE (float x1, float x2, float x3){
  return LOG_ADD (x1, LOG_ADD (x2, x3));
}