代码拉取完成,页面将自动刷新
#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;
};
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。