コード例 #1
0
char *TcWebApiStat_get(int id)
{
	switch(id)
	{
		case GB_C_STATISTICS_INTERFACE:
			if(!ASP_ISPOST)
				return val_def->stat_ethernet;
			else
				return web_api->stat_interface;
		
		case GB_C_STATISTICS_INTERFACEETHERNET://radio ethernet    
			if(!strcmp(web_api->stat_interface,val_def->stat_ethernet) || (!ASP_ISPOST))
				ASP_OUTPUT("CHECKED");
			break;
		case GB_C_STATISTICS_INTERFACEADSL://radio adsl   
			if(!strcmp(web_api->stat_interface,val_def->stat_adsl))
				ASP_OUTPUT("CHECKED");
			break;		
		case GB_C_STATISTICS_INTERFACEWLAN://radio wlan   
			if(!strcmp(web_api->stat_interface, val_def->stat_wlan))
				ASP_OUTPUT("CHECKED");
			break;
		case GB_C_STATISTICS_ETHERNET:
	  		get_eth_stats();
			break;	
		case GB_C_STATISTICS_ADSL:
			get_adsl_stats();
			break;			
		case GB_C_STATISTICS_WLAN:
			get_wlan_stats();
			break;			
	}
	return ASP_OK;
}
コード例 #2
0
ファイル: client_mtcp.c プロジェクト: carriercomm/ix
int main(int argc, char **argv)
{
	int i;
	int j;
	int k;
	int sum;
	int cores;
	int connections;
	long long total_connections;
	long long total_messages;
	int active_connections;
	int timeouts_connect;
	int timeouts_recv;
	char buf;
	int ret;
	char ifname[64];
	long rx_bytes, rx_packets, tx_bytes, tx_packets;

	prctl(PR_SET_PDEATHSIG, SIGHUP, 0, 0, 0);

	if (argc != 7) {
		fprintf(stderr, "Usage: %s IP PORT CORES CONNECTIONS MSG_SIZE MESSAGES_PER_CONNECTION\n", argv[0]);
		return 1;
	}

	server_addr.sin_family = AF_INET;
	if (!inet_aton(argv[1], &server_addr.sin_addr)) {
		fprintf(stderr, "Invalid server IP address \"%s\".\n", argv[1]);
		return 1;
	}
	server_addr.sin_port = htons(atoi(argv[2]));
	cores = atoi(argv[3]);
	connections = atoi(argv[4]);
	msg_size = atoi(argv[5]);
	messages_per_connection = strtol(argv[6], NULL, 10);

	if (timer_calibrate_tsc()) {
		fprintf(stderr, "Error: Timer calibration failed.\n");
		return 1;
	}
    
    if (mtcp_init("client_mtcp.conf")) {
        fprintf(stderr, "Error: mTCP initialization failed.\n");
        return 1;
    }

	get_ifname(&server_addr, ifname);

	start_threads(cores, connections);
	puts("ok");
	fflush(stdout);

	while (1) {
		ret = read(STDIN_FILENO, &buf, 1);
		if (ret == 0) {
			fprintf(stderr, "Error: EOF on STDIN.\n");
			return 1;
		} else if (ret == -1) {
			perror("read");
			return 1;
		}
		get_eth_stats(ifname, &rx_bytes, &rx_packets, &tx_bytes, &tx_packets);
		total_connections = 0;
		total_messages = 0;
		active_connections = 0;
		timeouts_connect = 0;
		timeouts_recv = 0;
		for (i = 0; i < cores; i++) {
			total_connections += worker[i].total_connections;
			total_messages += worker[i].total_messages;
			active_connections += worker[i].active_connections;
			timeouts_connect += worker[i].timeouts_connect;
			timeouts_recv += worker[i].timeouts_recv;
		}
		printf("%lld %lld %d %d %d ", total_connections, total_messages, active_connections, timeouts_connect, timeouts_recv);
		printf("%ld %ld %ld %ld ", rx_bytes, rx_packets, tx_bytes, tx_packets);
		printf("0 ");
		for (i = 0; i < MAX_ERRSOURCE; i++) {
			for (j = 0; j < MAX_ERRNO; j++) {
				sum = 0;
				for (k = 0; k < cores; k++)
					sum += worker[k].errors[i][j];
				if (sum)
					printf("%d %d %d ", i, j, sum);
			}
		}

		puts("");
		fflush(stdout);
	}
    
    mtcp_destroy();
	return 0;
}