2 Star 14 Fork 4

gavingqf/anet

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
anet.hpp 2.81 KB
一键复制 编辑 原始数据 按行查看 历史
gaoqingfeng 提交于 2023-09-16 22:22 . update
#pragma once
// Copyright (c) 2022 - 2023 gavingqf (gavingqf@126.com)
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
#include "define.hpp"
namespace anet {
namespace tcp {
// Parse packet return enum.
enum codecRet {
retError = -1,
retNotComplete = 0,
};
// user tcp session abstract interface
// 使用者必须实现的会话接口。
class ISession {
public:
virtual ~ISession() {}
// onConnected denotes tcp connection is connected callback.
// 建立连接回调,这个函数和OnRecv, onTerminate, release 不在同一个线程调用的
// 但是这个函数最先调用,有happen-before 功能。
virtual void onConnected(connSharePtr conn) = 0;
// onRecv denotes the tcp connection receives data callback: data and its length.
// it must note that the msg data includes tcp head and its message body.
// 接受到消息回调,这个消息包含定义的包头。
virtual void onRecv(const char *msg, int len) = 0;
// onTerminate denotes the connection is terminated callback.
// 断开连接回调
virtual void onTerminate() = 0;
// release denotes the ISession is released.
// 释放对象回调
virtual void release() = 0;
};
// session factory interface
// 对ISession的factory。
class ISessionFactory {
public:
virtual ~ISessionFactory() {}
// createSession creates session which is executed in multiple thread.
// 返回一个用户实现的ISession的实例。
virtual ISession *createSession() = 0;
};
// packet codec interface
// codec 的接口:网络的分包工具
class ICodec {
public:
virtual ~ICodec() {}
// parsePacket parses a complete packet and return its length:
// if a complete packet, return its size.
// else if error return -1(or < 0), anet will close the connection.
// else return 0 for there is no complete packet.
virtual int parsePacket(const char *msg, int len) = 0;
};
}
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C++
1
https://gitee.com/gavingqf/anet.git
git@gitee.com:gavingqf/anet.git
gavingqf
anet
anet
master

搜索帮助