13 Star 69 Fork 22

johnsonyl/cpps

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
cpps_socket_server.h 2.45 KB
一键复制 编辑 原始数据 按行查看 历史
johnsonyl 提交于 2021-01-11 16:01 +08:00 . 2021-01-11 更新
#ifndef cpps_socket_server_h__
#define cpps_socket_server_h__
#include <cpps/cpps.h>
#include <string>
#include <unordered_map>
#include <uv.h>
#ifdef _WIN32
#include <ws2def.h>
#include <windows.h>
#include <time.h>
#include <ws2ipdef.h>
#include <ws2tcpip.h>
#else
#include <unistd.h>
#include <arpa/inet.h>
#endif
#include "cpps_socket_event_callback.h"
namespace cpps {
class cpps_socket_server_option
{
public:
cpps_socket_server_option()
{
option_ip = "0.0.0.0";
option_headsize = 0;
}
std::string option_ip;
cpps::object option_accept;
cpps::object option_data;
cpps::object option_close;
cpps_integer option_headsize;
cpps::object option_parser;
};
class cpps_socket_server_client;
typedef phmap::flat_hash_map<cpps_integer, cpps_socket_server_client*> socket_list;
class cpps_socket_server : public cpps_socket_event_callback
{
public:
cpps_socket_server();
virtual ~cpps_socket_server();
virtual void setcstate(cpps::C* cstate);
cpps_socket_server* setoption( cpps::object opt);
int get_addrinfo(const struct sockaddr* addr, std::string& ip, cpps::usint16& port);
cpps_socket_server* listen(cpps::C* cstate, cpps::usint16 port);
virtual cpps_socket_server_client* create_server_client();
virtual void free_server_client(cpps_socket_server_client* client);
virtual void sends(cpps_integer socketIndex,std::string& buffer);
virtual void send(cpps_integer socketIndex, cpps::Buffer* buffer);
virtual cpps_socket_server_client* getclient(cpps_integer socketIndex);
virtual void run();
virtual void closesocket(cpps_integer socketIndex);
virtual void stop();
void stoped();
bool isrunning();
public:
virtual void onReadCallback(cpps_socket* sock, ssize_t nread, const uv_buf_t* buf);
static void onClsoeCallback(uv_handle_t* handle);
public:
static void stop_cb(uv_handle_t* handle);
static void write_task_cb(uv_async_t* handle);
static void cb_listener(uv_stream_t* server, int status);
public:
uv_tcp_t uv_socket;
uv_async_t async_send_msg;
cpps_socket_server_option server_option;
uv_loop_t* uv_loop;
cpps::C* c;
socket_list server_client_list;
cpps_integer inc_socket_index;
bool sever_running;
};
}
#endif // cpps_socket_server_h__
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C++
1
https://gitee.com/cppscript/cpps.git
git@gitee.com:cppscript/cpps.git
cppscript
cpps
cpps
v1.0.2

搜索帮助