socket.h

来自「模仿wiondws写的linux/freeBSD系统的IOCP」· C头文件 代码 · 共 60 行

H
60
字号
#ifndef _SOCKET_H
#define _SOCKET_H
#include "cmd.h"
#include "cirbuf.h"
#include "iocp/iocomplete.h"
#include "utility/lock.h"
#include <list>

class ksocket
{
public:
	ksocket(SockHandle sockdl):sockdl(sockdl),canRecv(true),canSend(true){}

	ksocket():canRecv(true),canSend(true){}

	Cmd *unpack();

	int recv(unsigned int size);

	int send(char *buf,unsigned int size);

	void setCanRecv()
	{
		Scope_lock scope_lock(lock);
		canRecv = true;
	}
	
	void setCanSend()
	{
		Scope_lock scope_lock(lock);
		canSend = true;
	}

	unsigned int put(const char *buffer,unsigned int size)
	{
		Scope_lock scope_lock(lock);
		return recv_buf.put(buffer,size);
	}

	


private:
	IO_CONTEXT io_context[2];
	SockHandle sockdl;
	bool canRecv;
	bool canSend;

	cirbuf<40960>   recv_buf;//接受缓冲
	char sendbuf[40960];
	char recvbuf[40960];

	Lock lock;

	//std::list<Cmd*> send_que;//等待发送的数据包
};


#endif

⌨️ 快捷键说明

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