?? procfunc.cpp
字號:
#include "stdafx.h"
#include "ProcFunc.h"
#include "SockFunc.h"
extern int g_WaitTime ;
extern int g_TryCount ;
int Func_GetData( LPTSTR p_data[],BOOL binType )
{
int rval ;
int nCount = 0 ;
SOCKET socket ;
struct PG_HEAD pg_head ;
LPTSTR ptr = NULL ;
LPTSTR ans_buff = NULL ;
/*+++++++++++++++++++++++++++++++++++*/
/*| |*/
/*| process the request for 5060 , |*/
/*| just for getting prescan data |*/
/*| |*/
/*+++++++++++++++++++++++++++++++++++*/
TraceLog(_T("=================process begin===============!"));
/*--------------------*/
/* connect the server */
/*--------------------*/
rval = sock_init( &socket ) ;
if ( rval < 0 )
{
TraceLog( _T("server is not found . can not go on processing") ) ;
TraceLog(_T("=================process end===============!\n"));
return -1;
}
else
{
TraceLog( _T("SOCKET has been initialized successfully!") ) ;
}
/*---------------------------------------------------------*/
/* compile the data with the aid of CELL_COLLECTION */
/*---------------------------------------------------------*/
/*---------------------------------------------------------*/
/* send the PACKAGE_50XX_FT package to the server . */
/*---------------------------------------------------------*/
pg_head.binType = binType;
pg_head.reqSize = 0;
pg_head.reqType = ENQ_PACKAGE;
rval = sock_send( socket , pg_head , NULL ) ;
for ( nCount = 0 ; ; )
{
memset(&pg_head ,'\0' , sizeof(pg_head)) ;
if(ans_buff){ delete[]ans_buff ; ans_buff = NULL ;}
rval = sock_recv(socket , &pg_head , ans_buff ) ;//
/*in case that : happen error*/
if(rval < 0)
{
if ( ans_buff ) { delete[]ans_buff ; ans_buff=NULL ; }
return -1 ;
}
/*in case that : timeout*/
else if ( rval == 1 )
{
::MessageBox(NULL , _T("Can not get data from server!") , _T("ERROR") , MB_OK);
nCount++ ;
}
else if ( pg_head.reqType == DATA_PACKAGE )
{
ptr = _tcschr(ans_buff,_T('\r')) ;
if ( ptr != NULL ) {
*ptr = _T('\0') ;
}
ptr = _tcschr(ans_buff,_T('\n')) ;
if ( ptr != NULL ) {
*ptr = _T('\0') ;
}
// max num is 1024
if ( nCount < 1024 )
{
p_data[nCount] = new TCHAR[_tcslen(ans_buff)+1] ;
ZeroMemory( p_data[nCount] , _tcslen(ans_buff)+1 ) ;
_tcscpy(p_data[nCount++] , ans_buff) ;
}
}
else if ( pg_head.reqType == OK_PACKAGE )
{
::MessageBox(NULL , _T("Get data from server successfully!") , _T("OK") , MB_OK);
break ;
}
else if ( pg_head.reqType == NG_PACKAGE )
{
::MessageBox(NULL , _T("Can not get data from server!") , _T("ERROR") , MB_OK);
break ;
}
}
if ( ans_buff ) { delete[]ans_buff ; ans_buff=NULL ; }
/*+++++++++++++++++++++++++++++++++++*/
/*| |*/
/*| desplay the detail data for |*/
/*| prescaning |*/
/*| |*/
/*+++++++++++++++++++++++++++++++++++*/
closesocket(socket);
TraceLog(_T("=================process end===============!\n"));
return nCount ;
}
int Func_StoreData( LPCTSTR pData ,BOOL binType)
{
int rval ;
SOCKET socket ;
struct PG_HEAD pg_head ;
LPTSTR buff = NULL ;
LPTSTR ans_buff = NULL ;
//pdata can't be null
if ( (pData==NULL) || (_tcslen(pData)==0) )
{
TraceLog(_T("No any input data!"));
::MessageBox(NULL , _T("Please input data!") , _T("Warning!") , MB_OK);
return -1 ;
}
/*+++++++++++++++++++++++++++++++++++*/
/*| |*/
/*| process the request for 5060 , |*/
/*| just for getting prescan data |*/
/*| |*/
/*+++++++++++++++++++++++++++++++++++*/
TraceLog(_T("=================process begin===============!"));
/*--------------------*/
/* connect the server */
/*--------------------*/
rval = sock_init( &socket ) ;
if ( rval < 0 )
{
TraceLog( _T("server is not found . can not go on processing") ) ;
TraceLog(_T("=================process end===============!\n") );
return -1;
}
else
{
TraceLog( _T("SOCKET has been initialized successfully!") ) ;
}
/*---------------------------------------------------------*/
/* compile the data with the aid of CELL_COLLECTION */
/*---------------------------------------------------------*/
/*---------------------------------------------------------*/
/* send the PACKAGE_50XX_FT package to the server . */
/*---------------------------------------------------------*/
pg_head.reqType = DATA_PACKAGE;
pg_head.binType = binType;
pg_head.reqSize = _tcslen(pData);
rval = sock_send( socket , pg_head , (LPTSTR)pData ) ;
for ( int nCount = 0 ; ; )
{
memset( &pg_head ,'\0' , sizeof(pg_head) ) ;
if( ans_buff ) { delete[]ans_buff ; ans_buff = NULL ;}
rval = sock_recv(socket , &pg_head , ans_buff ) ;
/*in case that : happen error*/
if ( rval < 0 )
{
if ( ans_buff ) { delete[]ans_buff ; ans_buff=NULL ; }
return -1 ;
}
/*in case that : timeout*/
else if ( rval == 1 )
{
::MessageBox(NULL , _T("Can not store data into server !") , _T("ERROR") , MB_OK);
nCount++ ;
}
else if ( pg_head.reqType = OK_PACKAGE )
{
::MessageBox(NULL , _T("Store data into server successfully!") , _T("OK") , MB_OK);
break ;
}
else if ( pg_head.reqType = NG_PACKAGE )
{
::MessageBox(NULL , _T("Can not store data into server !") , _T("ERROR") , MB_OK);
break ;
}
}
if ( ans_buff ) { delete[]ans_buff ; ans_buff=NULL ; }
/*+++++++++++++++++++++++++++++++++++*/
/*| |*/
/*| desplay the detail data for |*/
/*| prescaning |*/
/*| |*/
/*+++++++++++++++++++++++++++++++++++*/
closesocket(socket);
TraceLog(_T("=================process end===============!\n"));
return 0 ;
}
int Func_ClearLog(BOOL binType )
{
int rval ;
int nCount ;
SOCKET socket ;
struct PG_HEAD pg_head ;
LPTSTR ptr = NULL ;
LPTSTR ans_buff = NULL ;
/*+++++++++++++++++++++++++++++++++++*/
/*| |*/
/*| process the request for 5060 , |*/
/*| just for getting prescan data |*/
/*| |*/
/*+++++++++++++++++++++++++++++++++++*/
TraceLog(_T("=================process begin===============!"));
/*--------------------*/
/* connect the server */
/*--------------------*/
rval = sock_init( &socket ) ;
if ( rval < 0 )
{
TraceLog( _T("server is not found . can not go on processing") ) ;
TraceLog(_T("=================process end===============!\n"));
return -1;
}
else
{
TraceLog( _T("SOCKET has been initialized successfully!") ) ;
}
/*---------------------------------------------------------*/
/* compile the data with the aid of CELL_COLLECTION */
/*---------------------------------------------------------*/
/*---------------------------------------------------------*/
/* send the PACKAGE_50XX_FT package to the server . */
/*---------------------------------------------------------*/
pg_head.reqType = CLEAR_PACKAGE ;
pg_head.binType = binType;
rval = sock_send( socket , pg_head , NULL ) ;
for ( nCount = 0 ; ; )
{
memset( &pg_head ,'\0' , sizeof(pg_head) ) ;
if( ans_buff ) { delete[]ans_buff ; ans_buff = NULL ;}
rval = sock_recv(socket , &pg_head , ans_buff ) ;
/*in case that : happen error*/
if ( rval < 0 )
{
if ( ans_buff ) { delete[]ans_buff ; ans_buff=NULL ; }
return -1 ;
}
/*in case that : timeout*/
else if ( rval == 1 )
{
::MessageBox(NULL , _T("Can not clear the log files !") , _T("OK") , MB_OK);
nCount++ ;
}
else if ( pg_head.reqType == OK_PACKAGE )
{
::MessageBox(NULL , _T("Clear the log files successfully!") , _T("OK") , MB_OK);
break ;
}
else if ( pg_head.reqType == NG_PACKAGE )
{
::MessageBox(NULL , _T("Can not clear the log files !") , _T("OK") , MB_OK);
break ;
}
}
if ( ans_buff ) { delete[]ans_buff ; ans_buff=NULL ; }
/*+++++++++++++++++++++++++++++++++++*/
/*| |*/
/*| desplay the detail data for |*/
/*| prescaning |*/
/*| |*/
/*+++++++++++++++++++++++++++++++++++*/
closesocket(socket);
TraceLog(_T("=================process end===============!\n"));
return 0 ;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -