slot.cpp

来自「WIN NT/2000 聊天服务程序样例」· C++ 代码 · 共 42 行

CPP
42
字号
#include "stdhdr.h"
#include "main.h"
#include "svc.h"
#include "slot.h"

CSlot::CSlot(CSvc *pSvc, SOCKET sockfd, int id)
{
	char buf[80], num[17];

	m_id = id;
	m_sockfd = sockfd;
	pSvc->AddSlot(this);
	CSlot *pSlot = pSvc->m_pHead;
	strcpy(buf, "User #");
	strcat(buf, itoa(m_id, num, 10));
	strcat(buf, " has arrived.");
	pSvc->SendAll(buf, this);
}

CSlot::~CSlot()
{
	char buf[80], num[17];

	CSlot *pSlot = m_pSvc->m_pHead;
	strcpy(buf, "User #");
	strcat(buf, itoa(m_id, num, 10));
	strcat(buf, " has just left.");
	m_pSvc->SendAll(buf, this);
	m_pSvc->RemoveSlot(this);
	closesocket(m_sockfd);
}

void CSlot::Send(char *pszSend)
{
	send(m_sockfd, pszSend, strlen(pszSend), 0);
}

int CSlot::Recv(char *pszRecv, int n)
{
	return recv(m_sockfd, pszRecv, n, 0);
}

⌨️ 快捷键说明

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