1 Star 2 Fork 0

public_rtos / 基于libevent的websocket

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
libws.h 2.26 KB
一键复制 编辑 原始数据 按行查看 历史
public_rtos 提交于 2022-08-05 05:38 . 主文件
#pragma once
#include <inttypes.h>
#include <event.h>
#include <event2/bufferevent.h>
#include <event2/buffer.h>
#include <event2/listener.h>
#include <event2/util.h>
#include <event2/event.h>
#include <event2/dns.h>
#include <event2/thread.h>
#include <evhttp.h>
#ifdef __cplusplus
extern "C"
{
#endif
#define LIBWS_OP_CONTINUE 0
#define LIBWS_OP_TEXT 1
#define LIBWS_OP_BINARY 2
#define LIBWS_OP_CLOSE 8
#define LIBWS_OP_PING 9
#define LIBWS_OP_PONG 10
#define LIBWS_FLAGS_MASK_FIN 128
#define LIBWS_FLAGS_MASK_OP 15
#define LIBWS_ADD_HEAD(type_, head_, elem_) \
do { \
(elem_)->next = (*head_); \
*(head_) = (elem_); \
} while (0)
#define LIBWS_ADD_TAIL(type_, head_, elem_) \
do { \
type_ **h = head_; \
while (*h != NULL) h = &(*h)->next; \
*h = (elem_); \
} while (0)
#define LIBWS_DELETE(type_, head_, elem_) \
do { \
type_ **h = head_; \
while (*h != (elem_)) h = &(*h)->next; \
*h = (elem_)->next; \
} while (0)
struct libws_t;
typedef struct libws_t *(*new_conn_cb)(struct evhttp_request *req);
typedef int (*libws_conn)(struct libws_t*);
typedef int (*libws_disconn)(struct libws_t*);
typedef int (*libws_data)(struct libws_t*, uint8_t *,size_t);
struct libws_t
{
struct libws_t *next;
libws_conn conn_cb;
libws_disconn disconn_cb;
libws_data rd_cb;
libws_conn wr_cb;
struct evhttp_connection *conn;
uint64_t ms;
int is_active:1; // 是否可用
int is_client:1; // 是不是客户端,用来发送MASK位
int fin:1; // FIN位
};
int libws_send(struct libws_t*pws, uint8_t*pdata, size_t size, uint8_t op);
struct libws_t *libws_connect(struct event_base *base,
const char *url,
struct evkeyvalq *exheader,
libws_data rd, libws_conn wr, libws_conn con,libws_disconn clo);
void init_libws();
void destory_libws();
void set_new_ws(new_conn_cb);
void libws_poll();
#ifdef __cplusplus
}
#endif
C
1
https://gitee.com/public-rtos/src.git
git@gitee.com:public-rtos/src.git
public-rtos
src
基于libevent的websocket
master

搜索帮助