我的年中考核任务:求下面的重叠通讯代码,为何回调函数里打断点无法进入?
#include "stdafx.h"
#include <WinSock2.h>
#include <iostream>
#include "heartbeat.h"
#include "ManageMessage.h"
#pragma comment(lib,"ws2_32.lib")
using namespace std;
VOID WINAPI RecvCompletionRoutine(DWORD dwError,DWORD cbTransferred,
LPWSAOVERLAPPED lpOverlapped,DWORD dwFlags)
{
cout<<"RecvCompletionRoutine start"<<endl;
LPWSASRDATA overlapp = (LPWSASRDATA)lpOverlapped;
overlapp->pucmanage.manageMesg(overlapp->buffer);
if (WSARecv(overlapp->socket,&(overlapp->buffer),1,&(overlapp->NumberOfBytesSRd),&(overlapp->Flags),&static_cast<WSAOVERLAPPED&>(*overlapp),RecvCompletionRoutine) != 0)
{
cout<<"WSARecv failed GetLastError = "<<GetLastError()<<endl;
return ;
}
};
VOID WINAPI SendCompletionRoutine(DWORD dwError,DWORD cbTransferred,
LPWSAOVERLAPPED lpOverlapped,DWORD dwFlags)
{
}
int _tmain(int argc, _TCHAR* argv[])
{
WSADATA lpData;
WORD lpVersion = MAKEWORD(2,2);
SOCKET ulsocksend;
int port = 3000;
struct sockaddr_in ser;
char buff[MAXRECVLEN];
memset(buff,0,sizeof(buff));
LPWSASRDATA pucRecvData = NULL;
LPWSASRDATA pucSendData = NULL;
pucRecvData = new WSASRDATA;
pucSendData = new WSASRDATA;
if (pucRecvData == NULL||pucSendData == NULL)
{
return 1;
}
memset(pucRecvData,0,sizeof(WSASRDATA));
memset(pucSendData,0,sizeof(WSASRDATA));
if (WSAStartup(lpVersion,&lpData) != 0 )
{
cout<<"WSAStartup failed";
return 0;
}
if (lpData.wVersion != lpVersion)
{
cout<<"winsock version is not matching"<<endl;
return 0;
}
ulsocksend = WSASocket(AF_INET,SOCK_STREAM,IPPROTO_TCP,NULL,NULL,WSA_FLAG_OVERLAPPED);
if (ulsocksend == INVALID_SOCKET)
{
cout<<"socket create failed"<<endl;
return 0;
}
ser.sin_family = AF_INET;
ser.sin_addr.s_addr = inet_addr("127.0.0.1");
ser.sin_port = htons(port);
int ret = connect(ulsocksend,(const sockaddr*)&ser,sizeof(ser));
if (ret == SOCKET_ERROR)
{
int error = WSAGetLastError();
cout<<"connect failed,GetLastError is ="<<error<<endl;
return 0;
}
cout<<"connect IP="<<inet_ntoa(ser.sin_addr)<<"PORT="<<ntohs(ser.sin_port)<<endl;
pucRecvData->socket = ulsocksend;
pucRecvData->buffer.buf = buff;
pucRecvData->buffer.len = MAXRECVLEN;