102 lines
1.9 KiB
C++
102 lines
1.9 KiB
C++
|
// CCEXPipe.cpp : <20><><EFBFBD><EFBFBD> DLL Ӧ<>ó<EFBFBD><C3B3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڵ㡣
|
|||
|
//
|
|||
|
|
|||
|
#include "stdafx.h"
|
|||
|
#include "CCEXPipe.h"
|
|||
|
|
|||
|
|
|||
|
#ifdef _MANAGED
|
|||
|
#pragma managed(push, off)
|
|||
|
#endif
|
|||
|
|
|||
|
BOOL APIENTRY DllMain( HMODULE hModule,
|
|||
|
DWORD ul_reason_for_call,
|
|||
|
LPVOID lpReserved
|
|||
|
)
|
|||
|
{
|
|||
|
WSADATA wsaData;
|
|||
|
WORD wVersionRequested=MAKEWORD(2, 2);
|
|||
|
if( 0 == WSAStartup (wVersionRequested, &wsaData))
|
|||
|
{
|
|||
|
;
|
|||
|
}
|
|||
|
LogOutToFile("Pipe Load succ");
|
|||
|
return TRUE;
|
|||
|
}
|
|||
|
|
|||
|
#ifdef _MANAGED
|
|||
|
#pragma managed(pop)
|
|||
|
#endif
|
|||
|
|
|||
|
|
|||
|
BOOL ReadPipePacket(SOCKET rsocket, char* pcReadBuf, int lMaxSize, int& lRead)
|
|||
|
{
|
|||
|
lRead = 0;
|
|||
|
int lLen = 0;
|
|||
|
//<2F><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD>
|
|||
|
int lNeedRead = sizeof(lLen);
|
|||
|
int lReadPos = 0;
|
|||
|
while (lNeedRead > 0)
|
|||
|
{
|
|||
|
int lReadTemp = recv(rsocket, ((char*)&lLen)+lReadPos, lNeedRead, 0);
|
|||
|
if(lReadTemp <= 0)
|
|||
|
{
|
|||
|
LogOutToFile("ReadPipePacket recv len error.[%d] [%d]", GetLastError(), lReadTemp);
|
|||
|
return FALSE;
|
|||
|
}
|
|||
|
lNeedRead -= lReadTemp;
|
|||
|
lReadPos += lReadTemp;
|
|||
|
}
|
|||
|
|
|||
|
lRead = lLen;
|
|||
|
|
|||
|
if (lLen >= lMaxSize)
|
|||
|
{
|
|||
|
LogOutToFile("ReadPipePacket limit max.[%d] recv[%d]", GetLastError(), lMaxSize, lLen);
|
|||
|
return FALSE;
|
|||
|
}
|
|||
|
|
|||
|
//<2F><>ȡ<EFBFBD><C8A1><EFBFBD>ݰ<EFBFBD>
|
|||
|
lNeedRead = lLen;
|
|||
|
lReadPos = 0;
|
|||
|
while (lNeedRead > 0)
|
|||
|
{
|
|||
|
int lReadTemp = recv(rsocket, pcReadBuf+lReadPos, lNeedRead, 0);
|
|||
|
if(lReadTemp <= 0)
|
|||
|
{
|
|||
|
LogOutToFile("ReadPipePacket recv body error.[%d] [%d]", GetLastError(), lReadTemp);
|
|||
|
return FALSE;
|
|||
|
}
|
|||
|
lNeedRead -= lReadTemp;
|
|||
|
lReadPos += lReadTemp;
|
|||
|
}
|
|||
|
|
|||
|
return TRUE;
|
|||
|
}
|
|||
|
|
|||
|
BOOL SendeData(SOCKET wsocket, const char* pData, int lLen)
|
|||
|
{
|
|||
|
if (-1 == wsocket)
|
|||
|
{
|
|||
|
return FALSE;
|
|||
|
}
|
|||
|
|
|||
|
int lSend = -1;
|
|||
|
|
|||
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ܵ<EFBFBD><DCB5><EFBFBD>д<EFBFBD><D0B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
lSend = send(wsocket, (const char*)&lLen, sizeof(lLen), 0);
|
|||
|
if(sizeof(lLen) != lSend)
|
|||
|
{
|
|||
|
LogOutToFile("д<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݳ<EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD><EFBFBD>,Ԥ<><D4A4>д<EFBFBD><D0B4>[%d]<5D><>ʵ<EFBFBD><CAB5>д<EFBFBD><D0B4>[%d]\r\n", (int)sizeof(lLen), lSend);
|
|||
|
return FALSE;
|
|||
|
}
|
|||
|
|
|||
|
lSend = send(wsocket, pData, lLen, 0);
|
|||
|
if(lLen != lSend)
|
|||
|
{
|
|||
|
LogOutToFile("д<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD><EFBFBD>,Ԥ<><D4A4>д<EFBFBD><D0B4>[%d]<5D><>ʵ<EFBFBD><CAB5>д<EFBFBD><D0B4>[%d]\r\n", lLen, lSend);
|
|||
|
return FALSE;
|
|||
|
}
|
|||
|
|
|||
|
return TRUE;
|
|||
|
}
|