f-stack/app/micro_thread/mt_net_api.h

124 lines
3.2 KiB
C
Raw Normal View History

2017-04-21 10:43:26 +00:00
/**
* Tencent is pleased to support the open source community by making MSEC available.
*
* Copyright (C) 2016 THL A29 Limited, a Tencent company. All rights reserved.
*
* Licensed under the GNU General Public License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. You may
* obtain a copy of the License at
*
* https://opensource.org/licenses/GPL-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the
* License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific language governing permissions
* and limitations under the License.
*/
/**
* @file mt_net_api.h
* @info ΢<EFBFBD>̷߳<EFBFBD>װ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӿ<EFBFBD><EFBFBD><EFBFBD>
**/
#ifndef __MT_NET_API_H__
#define __MT_NET_API_H__
#include <netinet/in.h>
namespace NS_MICRO_THREAD {
/**
* @brief Э<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ͷ<EFBFBD><EFBFBD><EFBFBD>
*/
enum MT_PROTO_TYPE
{
NET_PROTO_UNDEF = 0,
NET_PROTO_UDP = 0x1, ///< <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> UDP
NET_PROTO_TCP = 0x2 ///< <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> TCP
};
/**
* @brief <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ͷ<EFBFBD><EFBFBD><EFBFBD>
*/
enum MT_RC_TYPE
{
RC_SUCCESS = 0,
RC_ERR_SOCKET = -1, ///< <20><><EFBFBD><EFBFBD>socketʧ<74><CAA7>
RC_SEND_FAIL = -2, ///< <20><><EFBFBD><EFBFBD>ʧ<EFBFBD><CAA7>
RC_RECV_FAIL = -3, ///< <20><><EFBFBD><EFBFBD>ʧ<EFBFBD><CAA7>
RC_CONNECT_FAIL = -4, ///< <20><><EFBFBD><EFBFBD>ʧ<EFBFBD><CAA7>
RC_CHECK_PKG_FAIL = -5, ///< <20><><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD>ʧ<EFBFBD><CAA7>
RC_NO_MORE_BUFF = -6, ///< <20>ռ<D5BC><E4B3AC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
RC_REMOTE_CLOSED = -7, ///< <20><><EFBFBD>˹ر<CBB9><D8B1><EFBFBD><EFBFBD><EFBFBD>
RC_INVALID_PARAM = -10, ///< <20><>Ч<EFBFBD><D0A7><EFBFBD><EFBFBD>
RC_INVALID_HANDLER = -11, ///< <20><>Ч<EFBFBD>ľ<EFBFBD><C4BE><EFBFBD>
RC_MEM_ERROR = -12, ///< <20>ڴ<EFBFBD><DAB4>
RC_CONFLICT_SID = -13, ///< SESSION ID<49><44>ͻ
RC_KQUEUE_ERROR = -14, ///< rst<73>źŵ<C5BA>
};
/**
* @brief <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>, <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȡsession<EFBFBD>Ļص<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* @info <EFBFBD>need_len<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ԭ<EFBFBD><EFBFBD>, <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>޷<EFBFBD>ȷ<EFBFBD>ϱ<EFBFBD><EFBFBD>ij<EFBFBD><EFBFBD><EFBFBD>ʱ, <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ÿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>չϣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>, <EFBFBD><EFBFBD><EFBFBD>޷<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* @param data -ʵ<EFBFBD>ʽ<EFBFBD><EFBFBD>յ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ָ<EFBFBD><EFBFBD>
* @param len -<EFBFBD>Ѿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ջ<EFBFBD>׼<EFBFBD><EFBFBD><EFBFBD>ij<EFBFBD><EFBFBD><EFBFBD>
* @param session_id -<EFBFBD>ɹ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>sessionid<EFBFBD><EFBFBD>Ϣ
* @param need_len -ϣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>չһ<EFBFBD><EFBFBD>buff, Ŀǰ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>100M
* @return >0 <EFBFBD>ɹ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʵ<EFBFBD>ʵİ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>; =0 <EFBFBD><EFBFBD><EFBFBD>IJ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>, <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ո<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>; <0 <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD><EFBFBD>
*/
typedef int32_t (*CHECK_SESSION_CALLBACK)(const void* data, uint32_t len,
uint64_t* session_id, uint32_t* need_len);
/**
* @brief <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
*/
class CNetHelper
{
public:
// ת<><D7AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ, <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȡ
static char* GetErrMsg(int32_t result);
// ͬ<><CDAC><EFBFBD>շ<EFBFBD><D5B7>ӿ<EFBFBD>
int32_t SendRecv(void* data, uint32_t len, uint32_t timeout);
// <20><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD>buff<66><66>Ϣ, <20><>Ч<EFBFBD><D0A7>ֱ<EFBFBD><D6B1>helper<65><72><EFBFBD><EFBFBD>
void* GetRspBuff();
// <20><>ȡ<EFBFBD><C8A1><EFBFBD>ذ<EFBFBD><D8B0>ij<EFBFBD><C4B3><EFBFBD>
uint32_t GetRspLen();
// <20><><EFBFBD><EFBFBD>Э<EFBFBD><D0AD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>, Ĭ<><C4AC>UDP
void SetProtoType(MT_PROTO_TYPE type);
// <20><><EFBFBD><EFBFBD>Ŀ<EFBFBD><C4BF>IP<49><50>ַ
void SetDestAddress(struct sockaddr_in* dst);
// <20><><EFBFBD><EFBFBD>session<6F><6E><EFBFBD><EFBFBD>session id<69><64>Ϣ, <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>0
void SetSessionId(uint64_t sid);
// <20><><EFBFBD><EFBFBD>session<6F><6E><EFBFBD><EFBFBD><EFBFBD>ص<EFBFBD><D8B5><EFBFBD><EFBFBD><EFBFBD>
void SetSessionCallback(CHECK_SESSION_CALLBACK function);
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
CNetHelper();
~CNetHelper();
private:
void* handler; // ˽<>о<EFBFBD><D0BE><EFBFBD>, <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>չ
};
}
#endif