www.pudn.com > NetIO.rar > NetIO.cpp


// NetIO.cpp : Defines the entry point for the console application. 
// 
 
#include "stdafx.h" 
 
#include "NetIO.h" 
#include "cpuInfo.h" 
#include "netIOlog.h" 
#include "CTNetTraffic.h" 
 
#ifdef _DEBUG 
#define new DEBUG_NEW 
#undef THIS_FILE 
static char THIS_FILE[] = __FILE__; 
#endif 
 
///////////////////////////////////////////////////////////////////////////// 
// The one and only application object 
 
CWinApp theApp; 
 
using namespace std; 
 
void _tmain(int argc, TCHAR* argv[], TCHAR* envp[]) 
{ 
 
	if( argc < 3  ) 
	{ 
		writeLog("Wrong command ,Parameters is't enough.",true); 
		return; 
	} 
	 
	// 参数合法判断	 
	int limitTime = atoi(argv[1]); 
	if (0 == limitTime) 
	{ 
		writeLog("Wrong command ,the first Parameter should be a integer.",true); 
		return; 
	} 
	char* fileName = argv[2]; 
	 
	int nOpenRet = openNetFileTest(limitTime,fileName); 
	switch(nOpenRet)  
	{ 
	case ERROR_OPEN_FILE: 
		{ 
			char* strLogPrefix = "Error open "; 
			char* strLog = new char[strlen(strLogPrefix)+strlen(fileName)+1]; 
 
			strcpy(strLog,strLogPrefix); 
			strcat(strLog,fileName); 
			writeLog(strLog,true); 
 
			delete[] strLog; 
 
			// cpu and IO 
			remarkCPU(); 
			remarkIO(); 
		} 
		break; 
	case SATISFY_OPEN_FILE: 
		break; 
	default: 
		{			 
			char* strLogPrefix = "over time to open "; 
			char* strLog = new char[strlen(strLogPrefix)+strlen(fileName)+1]; 
			 
			strcpy(strLog,strLogPrefix); 
			strcat(strLog,fileName); 
			writeLog(strLog,true); 
 
			delete[] strLog; 
 
			// cpu and IO 
			remarkCPU(); 
			remarkIO(); 
 
		} 
	} 
 
	Sleep(1000); 
 
	return; 
} 
 
/* 
	测试用到的方法 
	功能:增加'\' 
*/ 
/* 
char* changeFileName(const char* oldFileName) 
{ 
 
	int oldSize = strlen(oldFileName) ; 
	int symbolSize = 0; 
	 
	for(int i = 0;i < oldSize;i++) 
	{ 
		if ('\\' == oldFileName[i]) 
			symbolSize++; 
 
	} 
	char* newFileName = new char[oldSize+symbolSize]; 
	 
	int oldNameIndex = 0,newNameIndex = 0; 
	while(oldNameIndex < oldSize)  
	{ 
		if ('\\' == oldFileName[oldNameIndex]) 
		{ 
			newFileName[newNameIndex++] = '\\'; 
			newFileName[newNameIndex++] = '\\'; 
			oldNameIndex++; 
		} 
		else 
		{ 
			newFileName[newNameIndex] = oldFileName[oldNameIndex]; 
			oldNameIndex++; 
			newNameIndex++; 
		} 
	} 
	newFileName[newNameIndex] = '\0'; 
	 
	//delete[] newFileName; 
	return newFileName; 
} 
*/ 
 
/* 
	取所有接口的I/O流量,写入日志 
*/ 
void remarkIO(void) 
{ 
	const int buffSize = 400; 
	int size,ret ; 
 
	CTNetTraffic oNetTraff; 
	int conInters = oNetTraff.GetNetworkInterfacesCount();	 
	 
	for(int i = 0;i