没分了,帮忙看一下吧,还是关于完全端口问题 ( 积分: 0 )

  • 主题发起人 主题发起人 男生111
  • 开始时间 开始时间

男生111

Unregistered / Unconfirmed
GUEST, unregistred user!
我的主线程如下,执行WSARE函数后,另一个线程中的GetQueuedCompletionStatus函数无响应,
DWORD WINAPI ServerZhuThread(LPVOID CompletionPortID)
{
ThreadHandle = CreateThread(NULL, 0,
ServerWorkerThread, CompletionPort,0, NULL);
CloseHandle(ThreadHandle);
Listen = socket(AF_INET,SOCK_STREAM,IPPROTO_TCP);
InternetAddr.sin_family = AF_INET;
InternetAddr.sin_addr.s_addr = htonl(INADDR_ANY);
InternetAddr.sin_port = htons(1005);
bind(Listen, (PSOCKADDR) &InternetAddr,sizeof(InternetAddr));
listen(Listen, 3000);
while(TRUE)
{
PER_HANDLE_DATA *PerHandleData=NULL;
SOCKADDR_IN saRemote;
SOCKET Accept;
int RemoteLen;
RemoteLen = sizeof(saRemote);
Accept = accept(Listen, (SOCKADDR *)&saRemote,&RemoteLen);
if(SOCKET_ERROR == Accept)
{
closesocket(Accept);
}
else{
PerHandleData = (LPPER_HANDLE_DATA)
PerHandleData->Socket = Accept;
memcpy(&PerHandleData->ClientAddr, &saRemote, RemoteLen);

CreateIoCompletionPort((HANDLE) Accept,
CompletionPort, (DWORD) PerHandleData, 0);
LPPER_IO_DATA PerIoData=NULL;
DWORD Flags;
DWORD RecvBytes;
Flags=1;
// PerIoData->DataBuf.len = 4095;如果加上将报内存错误?为什么?
// PerIoData->DataBuf.buf = PerIoData->szBuffer;
// PerIoData->OperationType = RECV_POSTED;

WSARecv(PerHandleData->Socket,
&(PerIoData->DataBuf), 1, &RecvBytes,
&Flags, &(PerIoData->Overlapped), NULL);
}
}
}
 
我的主线程如下,执行WSARE函数后,另一个线程中的GetQueuedCompletionStatus函数无响应,
DWORD WINAPI ServerZhuThread(LPVOID CompletionPortID)
{
ThreadHandle = CreateThread(NULL, 0,
ServerWorkerThread, CompletionPort,0, NULL);
CloseHandle(ThreadHandle);
Listen = socket(AF_INET,SOCK_STREAM,IPPROTO_TCP);
InternetAddr.sin_family = AF_INET;
InternetAddr.sin_addr.s_addr = htonl(INADDR_ANY);
InternetAddr.sin_port = htons(1005);
bind(Listen, (PSOCKADDR) &InternetAddr,sizeof(InternetAddr));
listen(Listen, 3000);
while(TRUE)
{
PER_HANDLE_DATA *PerHandleData=NULL;
SOCKADDR_IN saRemote;
SOCKET Accept;
int RemoteLen;
RemoteLen = sizeof(saRemote);
Accept = accept(Listen, (SOCKADDR *)&saRemote,&RemoteLen);
if(SOCKET_ERROR == Accept)
{
closesocket(Accept);
}
else{
PerHandleData = (LPPER_HANDLE_DATA)
PerHandleData->Socket = Accept;
memcpy(&PerHandleData->ClientAddr, &saRemote, RemoteLen);

CreateIoCompletionPort((HANDLE) Accept,
CompletionPort, (DWORD) PerHandleData, 0);
LPPER_IO_DATA PerIoData=NULL;
DWORD Flags;
DWORD RecvBytes;
Flags=1;
// PerIoData->DataBuf.len = 4095;如果加上将报内存错误?为什么?
// PerIoData->DataBuf.buf = PerIoData->szBuffer;
// PerIoData->OperationType = RECV_POSTED;

WSARecv(PerHandleData->Socket,
&(PerIoData->DataBuf), 1, &RecvBytes,
&Flags, &(PerIoData->Overlapped), NULL);
}
}
}
 
后退
顶部