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

📄 notifythread.cpp

📁 vc++6.0开发网络典型应用实例导航 1. 本光盘提供了本书中所有的实例源程序文件。 2. 附录文件夹下是Winsock 函数参考以及错误码列表
💻 CPP
字号:
// NotifyThread.cpp : implementation file
//

#include "stdafx.h"
#include "Netmsg.h"
#include "NotifyThread.h"
#include "NetSocket.h"
#include "Contact.h"
#include "MainFrm.h"
#include "ContactView.h"
#include "NetmsgView.h"

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

//This thread is running most of the time attepting to connect to the offline contacts
//once it makes a connection it will pass the socket back to the main thread

IMPLEMENT_DYNCREATE(CNotifyThread, CWinThread)

CNotifyThread::CNotifyThread()
{
}

CNotifyThread::~CNotifyThread()
{
}

BOOL CNotifyThread::InitInstance()
{
	POSITION pos;
	pos = List->GetHeadPosition();
	while (pos)
	{
		SOCKET Sock;
		bool nResult;
		Contact = List->GetNext(pos);
		
		if (IsSocket(Contact->GetSock())) continue;

		CNetSocket *NewSocket = new CNetSocket(Contact);

		Contact->SetSock(NULL);

		nResult = NewSocket->Open();

		if (!IsContact(Contact))
			continue; //might have been deleted while we were pissing around trying to connect

		if (!nResult)
		{	
			Contact->WeConnected = false;
			Contact->SetSock(NULL);
			delete NewSocket;
		}
		else
		{
			Contact->SetSock(NewSocket);
			Sock = NewSocket->Detach();
			delete NewSocket;
			Contact->SetSock(NULL);
			::SendMessage(GetApp()->View->GetSafeHwnd(), WM_SOCKCONNECT, (WPARAM)Sock, (LPARAM)Contact);
			//pass the new socket to the main thread
		}
	}
	view->Notify = NULL;
	view->Load++;
	PluginsNotifyContactsConnected();
	PostThreadMessage(WM_QUIT, 0, 0);
	return TRUE;
}

int CNotifyThread::ExitInstance()
{
	return CWinThread::ExitInstance();
}

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

/////////////////////////////////////////////////////////////////////////////
// CNotifyThread message handlers

⌨️ 快捷键说明

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