UINT TSend(LPVOID pParam)
{
CFileviewDlg* pDlg=(CFileviewDlg*)pParam;
for (;;)
{
::GetMessage(&(pDlg->ConSock.BufMsg),NULL,0,0);
SendMessage(pDlg->m_hWnd,WM_ST_SEND,0,0);
pDlg->ConSock.EventSend.Lock();
char* buf=(char*)(pDlg->ConSock.BufMsg.lParam);
delete buf;
}
return 0;
}void CFileviewDlg::OnButton1()
{
// TODO: Add your control notification handler code here
int num=10240*3;
num=1024;
char* str=new char[num];
::PostThreadMessage(pTSend->m_nThreadID,0,num,LPARAM(str));
}void CFileviewDlg::OnSTSend()
{
ConSock.HASMSG=TRUE;
ConSock.AsyncSelect();
}class CConSock : public CAsyncSocket
{
// Attributes
public:
CEvent EventSend;
MSG BufMsg;
char* pSData;
int m_nBytesBufferSize; //bufsize
int m_nBytesSent; //n_bytesent
BOOL MSGSended;
BOOL HASMSG;CConSock::CConSock()
{
pSData=(char*)&BufMsg;
m_nBytesBufferSize=sizeof(BufMsg);
m_nBytesSent=0;
MSGSended=FALSE;
HASMSG=FALSE;
}void CConSock::OnSend(int nErrorCode)
{
// TODO: Add your specialized code here and/or call the base class
if (HASMSG)
{
if (MSGSended==FALSE/*&&DATASended==FALSE*/)
{
while (m_nBytesSent<m_nBytesBufferSize)
{
int dwByte;
if((dwByte=Send(pSData+m_nBytesSent,m_nBytesBufferSize-m_nBytesSent))==SOCKET_ERROR)
{
if (GetLastError() == WSAEWOULDBLOCK)
{
AsyncSelect(FD_WRITE);
return;
}
else
{
TCHAR szError[256];
wsprintf(szError, "Server Socket failed to send: %d",
GetLastError());
Close();
AfxMessageBox (szError);
}
}
else
{
m_nBytesSent+=dwByte;
}
}
if(m_nBytesSent==m_nBytesBufferSize)
{
MSGSended=TRUE;
pSData=(char*)BufMsg.lParam;
m_nBytesBufferSize=BufMsg.wParam;
m_nBytesSent=0;
}
}
if(MSGSended==TRUE/*&&DATASended==FALSE*/)
{
while (m_nBytesSent<m_nBytesBufferSize)
{
int dwByte;
if((dwByte=Send(pSData+m_nBytesSent,m_nBytesBufferSize-m_nBytesSent))==SOCKET_ERROR)
{
if (GetLastError() == WSAEWOULDBLOCK)
{
AsyncSelect(FD_WRITE);
return;
}
else
{
TCHAR szError[256];
wsprintf(szError, "Server Socket failed to send: %d",
GetLastError());
Close();
AfxMessageBox (szError);
}
}
else
{
m_nBytesSent+=dwByte;
}
}
if(m_nBytesSent==m_nBytesBufferSize)
{
//DATASended=TRUE;
pSData=pSData=(char*)&BufMsg;
m_nBytesBufferSize=sizeof(BufMsg);
m_nBytesSent=0;
MSGSended=FALSE;
//DATASended=FALSE;
HASMSG=FALSE;
//AfxMessageBox("ok");
EventSend.SetEvent();
}
}
}
CAsyncSocket::OnSend(nErrorCode);
}
{
CFileviewDlg* pDlg=(CFileviewDlg*)pParam;
for (;;)
{
::GetMessage(&(pDlg->ConSock.BufMsg),NULL,0,0);
SendMessage(pDlg->m_hWnd,WM_ST_SEND,0,0);
pDlg->ConSock.EventSend.Lock();
char* buf=(char*)(pDlg->ConSock.BufMsg.lParam);
delete buf;
}
return 0;
}void CFileviewDlg::OnButton1()
{
// TODO: Add your control notification handler code here
int num=10240*3;
num=1024;
char* str=new char[num];
::PostThreadMessage(pTSend->m_nThreadID,0,num,LPARAM(str));
}void CFileviewDlg::OnSTSend()
{
ConSock.HASMSG=TRUE;
ConSock.AsyncSelect();
}class CConSock : public CAsyncSocket
{
// Attributes
public:
CEvent EventSend;
MSG BufMsg;
char* pSData;
int m_nBytesBufferSize; //bufsize
int m_nBytesSent; //n_bytesent
BOOL MSGSended;
BOOL HASMSG;CConSock::CConSock()
{
pSData=(char*)&BufMsg;
m_nBytesBufferSize=sizeof(BufMsg);
m_nBytesSent=0;
MSGSended=FALSE;
HASMSG=FALSE;
}void CConSock::OnSend(int nErrorCode)
{
// TODO: Add your specialized code here and/or call the base class
if (HASMSG)
{
if (MSGSended==FALSE/*&&DATASended==FALSE*/)
{
while (m_nBytesSent<m_nBytesBufferSize)
{
int dwByte;
if((dwByte=Send(pSData+m_nBytesSent,m_nBytesBufferSize-m_nBytesSent))==SOCKET_ERROR)
{
if (GetLastError() == WSAEWOULDBLOCK)
{
AsyncSelect(FD_WRITE);
return;
}
else
{
TCHAR szError[256];
wsprintf(szError, "Server Socket failed to send: %d",
GetLastError());
Close();
AfxMessageBox (szError);
}
}
else
{
m_nBytesSent+=dwByte;
}
}
if(m_nBytesSent==m_nBytesBufferSize)
{
MSGSended=TRUE;
pSData=(char*)BufMsg.lParam;
m_nBytesBufferSize=BufMsg.wParam;
m_nBytesSent=0;
}
}
if(MSGSended==TRUE/*&&DATASended==FALSE*/)
{
while (m_nBytesSent<m_nBytesBufferSize)
{
int dwByte;
if((dwByte=Send(pSData+m_nBytesSent,m_nBytesBufferSize-m_nBytesSent))==SOCKET_ERROR)
{
if (GetLastError() == WSAEWOULDBLOCK)
{
AsyncSelect(FD_WRITE);
return;
}
else
{
TCHAR szError[256];
wsprintf(szError, "Server Socket failed to send: %d",
GetLastError());
Close();
AfxMessageBox (szError);
}
}
else
{
m_nBytesSent+=dwByte;
}
}
if(m_nBytesSent==m_nBytesBufferSize)
{
//DATASended=TRUE;
pSData=pSData=(char*)&BufMsg;
m_nBytesBufferSize=sizeof(BufMsg);
m_nBytesSent=0;
MSGSended=FALSE;
//DATASended=FALSE;
HASMSG=FALSE;
//AfxMessageBox("ok");
EventSend.SetEvent();
}
}
}
CAsyncSocket::OnSend(nErrorCode);
}
LRESULT OnSTSend(); ==>
LRESULT OnSTSend(WPARAM wp, LPARAM lp);
但是在RELEASE模式下,不会执行
因此会出现问题