1 2 /** 3 * Tencent is pleased to support the open source community by making MSEC available. 4 * 5 * Copyright (C) 2016 THL A29 Limited, a Tencent company. All rights reserved. 6 * 7 * Licensed under the GNU General Public License, Version 2.0 (the "License"); 8 * you may not use this file except in compliance with the License. You may 9 * obtain a copy of the License at 10 * 11 * https://opensource.org/licenses/GPL-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, software distributed under the 14 * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 15 * either express or implied. See the License for the specific language governing permissions 16 * and limitations under the License. 17 */ 18 19 20 /** 21 * @file mt_net_api.h 22 * @info �̷߳�װ������ӿ��� 23 **/ 24 25 #ifndef __MT_NET_API_H__ 26 #define __MT_NET_API_H__ 27 28 #include <netinet/in.h> 29 30 namespace NS_MICRO_THREAD { 31 32 /** 33 * @brief Э�����Ͷ��� 34 */ 35 enum MT_PROTO_TYPE 36 { 37 NET_PROTO_UNDEF = 0, 38 NET_PROTO_UDP = 0x1, ///< �������� UDP 39 NET_PROTO_TCP = 0x2 ///< �������� TCP 40 }; 41 42 /** 43 * @brief �������Ͷ��� 44 */ 45 enum MT_RC_TYPE 46 { 47 RC_SUCCESS = 0, 48 RC_ERR_SOCKET = -1, ///< ����socketʧ�� 49 RC_SEND_FAIL = -2, ///< ����ʧ�� 50 RC_RECV_FAIL = -3, ///< ����ʧ�� 51 RC_CONNECT_FAIL = -4, ///< ����ʧ�� 52 RC_CHECK_PKG_FAIL = -5, ///< ���ļ��ʧ�� 53 RC_NO_MORE_BUFF = -6, ///< �ռ䳬������ 54 RC_REMOTE_CLOSED = -7, ///< ��˹ر����� 55 56 RC_INVALID_PARAM = -10, ///< ��Ч���� 57 RC_INVALID_HANDLER = -11, ///< ��Ч�ľ�� 58 RC_MEM_ERROR = -12, ///< �ڴ��쳣 59 RC_CONFLICT_SID = -13, ///< SESSION ID��ͻ 60 RC_KQUEUE_ERROR = -14, ///< rst�źŵ� 61 }; 62 63 64 /** 65 * @brief ��鱨���Ƿ�����, ����ȡsession�Ļص����� 66 * @info �ṩneed_len������ԭ��, ������ȷ�ϱ��ij���ʱ, ����ÿ����չϣ������ 67 * �����������ֵ����������, ��������������� 68 * @param data -ʵ�ʽ��յ�����ָ�� 69 * @param len -�Ѿ����ջ����ij��� 70 * @param session_id -�ɹ�������sessionid��Ϣ 71 * @param need_len -ϣ����չһ��buff, Ŀǰ���100M 72 * @return >0 �ɹ���������ʵ�ʵİ�����; =0 ���IJ�����, �������ո�������; <0 ����ʧ�� 73 */ 74 typedef int32_t (*CHECK_SESSION_CALLBACK)(const void* data, uint32_t len, 75 uint64_t* session_id, uint32_t* need_len); 76 77 78 /** 79 * @brief ����ӿ��ඨ�� 80 */ 81 class CNetHelper 82 { 83 public: 84 85 // ת����������Ϣ, �����ȡ 86 static char* GetErrMsg(int32_t result); 87 88 // ͬ���շ��ӿ� 89 int32_t SendRecv(void* data, uint32_t len, uint32_t timeout); 90 91 // ��ȡ����buff��Ϣ, ��Ч��ֱ��helper���� 92 void* GetRspBuff(); 93 94 // ��ȡ���ذ��ij��� 95 uint32_t GetRspLen(); 96 97 // ����Э�������, Ĭ��UDP 98 void SetProtoType(MT_PROTO_TYPE type); 99 100 // ����Ŀ��IP��ַ 101 void SetDestAddress(struct sockaddr_in* dst); 102 103 // ����session����session id��Ϣ, �����0 104 void SetSessionId(uint64_t sid); 105 106 // ����session�����ص����� 107 void SetSessionCallback(CHECK_SESSION_CALLBACK function); 108 109 // �������鹹 110 CNetHelper(); 111 ~CNetHelper(); 112 113 private: 114 115 void* handler; // ˽�о��, ������չ 116 }; 117 118 119 } 120 121 #endif 122 123 124