⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 recthread.cpp

📁 关于联通的一个统一定制程序
💻 CPP
字号:
// RecThread.cpp : implementation file
//

#include "stdafx.h"
#include "RecThread.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CRecThread

IMPLEMENT_DYNCREATE(CRecThread, CWinThread)

CRecThread::CRecThread()
{
}

CRecThread::~CRecThread()
{
}

BOOL CRecThread::InitInstance()
{
	// TODO:  perform and per-thread initialization here
	return TRUE;
}

int CRecThread::ExitInstance()
{
	// TODO:  perform any per-thread cleanup here
	return CWinThread::ExitInstance();
}

BEGIN_MESSAGE_MAP(CRecThread, CWinThread)
	//{{AFX_MSG_MAP(CRecThread)
		// NOTE - the ClassWizard will add and remove mapping macros here.
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CRecThread message handlers

int CRecThread::Run() 
{
	// client socket
	sockaddr_in remote;
	SOCKET sock = INVALID_SOCKET;
	int addrlen = sizeof(remote);
	// received message
	int nRec = 0;
	TCHAR szMsg[MAX_CONTENT_LEN];
	// received time limited
	int timeout = 1000;

	while (theData.m_socket != INVALID_SOCKET && !theData.m_bServiceExit)
	{
		sock = accept(theData.m_socket, (sockaddr*)&remote, &addrlen);
		if (sock == INVALID_SOCKET)
			continue;

		memset(szMsg, 0x0, sizeof(szMsg));

		setsockopt(sock, SOL_SOCKET, SO_RCVTIMEO, (LPTSTR)&timeout, sizeof(timeout));

		nRec = recv(sock, szMsg, sizeof(szMsg), 0);
		if (nRec != SOCKET_ERROR && nRec > 0)
			theData.AddOneRecMsg(inet_ntoa(remote.sin_addr), szMsg, nRec);

		closesocket(sock);
		sock = INVALID_SOCKET;
	}

	return CWinThread::Run();
}

⌨️ 快捷键说明

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