📄 datasocket.cpp
字号:
// DataSocket.cpp : implementation file
//
#include "stdafx.h"
#include "DataSocket.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CDataSocket
CDataSocket::CDataSocket(CControlSocket* pControlSocket)
{
m_isConnected=false;
m_pClientDlg=0;
m_pControlSocket=pControlSocket;
}
CDataSocket::~CDataSocket()
{
}
// Do not edit the following lines, which are needed by ClassWizard.
#if 0
BEGIN_MESSAGE_MAP(CDataSocket, CSocket)
//{{AFX_MSG_MAP(CDataSocket)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
#endif // 0
/////////////////////////////////////////////////////////////////////////////
// CDataSocket member functions
void CDataSocket::OnAccept(int nErrorCode)
{
CSocket tmpSocket;
Accept(tmpSocket);
SOCKET s=tmpSocket.Detach();
Close();
Attach(s);
m_isConnected=true;
CSocket::OnAccept(nErrorCode);
}
void CDataSocket::OnReceive(int nErrorCode)
{
if(m_pClientDlg==0)
m_pClientDlg=(CFTPClientDlg *)(AfxGetApp()->m_pMainWnd);
if(m_pClientDlg->m_state==STATE_DOWNLOAD)
{
int nRead=m_pClientDlg->SaveToFile(this);
if(nRead==0)
{
m_pClientDlg->m_state=STATE_LIST;
}
return;
}
TCHAR buf[4096];
int nRead=CSocket::Receive(buf,4096);
switch(nRead)
{
case 0: //receive finished;
Close();
m_pClientDlg->AddActivity("Data Socket Receive finished.");
break;
case SOCKET_ERROR:
if(GetLastError()==WSAEWOULDBLOCK)
{
Sleep(0);
}else
{
Close();
m_pClientDlg->AddActivity("Data Socket Receive Errored.");
}
break;
default:
buf[nRead]=0;
receiveBuf+=CString(buf);
int index;
while((index=receiveBuf.Find("\r\n"))!=-1)
{
m_pControlSocket->AddServerReply(receiveBuf.Left(index));
receiveBuf=receiveBuf.Mid(index+2);
}
// m_pClientDlg->ProcessCommand();
break;
}
CSocket::OnReceive(nErrorCode);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -