mysocket.cpp

来自「多线程文件传输。分5个线程发送」· C++ 代码 · 共 64 行

CPP
64
字号
// MySocket.cpp : implementation file
//

#include "stdafx.h"
#include "FileTransferServer.h"
#include "MySocket.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CMySocket
CMySocket::CMySocket():Thdidx(0)
{
}

CMySocket::~CMySocket()
{
}


// Do not edit the following lines, which are needed by ClassWizard.
#if 0
BEGIN_MESSAGE_MAP(CMySocket, CAsyncSocket)
	//{{AFX_MSG_MAP(CMySocket)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()
#endif	// 0

/////////////////////////////////////////////////////////////////////////////
// CMySocket member functions
//OnAccept重载函数
void CMySocket::OnAccept(int nErrorCode) 
{
	// TODO: Add your specialized code here and/or call the base class
	static int File_Socket_Accepted=0;
	//接受套接字连接
	if(!listenSocket.Accept(sendSockets[File_Socket_Accepted]))
	{
		AfxMessageBox("Connect fail");
		return;
	}
	sendSockets[File_Socket_Accepted].AsyncSelect(FD_READ|FD_WRITE|FD_CLOSE);
	Thdidx=++File_Socket_Accepted;
	if(File_Socket_Accepted==NumOfThread)
	{
		AfxMessageBox("Connect success");
		listenSocket.Close();
	}
	CAsyncSocket::OnAccept(nErrorCode);
}
//OnSend重载函数
void CMySocket::OnSend(int nErrorCode)
{
	// TODO: Add your specialized code here and/or call the base class
	//设置文件发送事件对象,通知线程可以发送数据
	SetEvent(hMessageSend[Thdidx-1]);
	CAsyncSocket::OnSend(nErrorCode);
}


⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?