-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathConnection.h
63 lines (47 loc) · 1.44 KB
/
Connection.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#ifndef _CONNECTION_H
#define _CONNECTION_H
#include "KendyNet.h"
#include "wpacket.h"
#include "rpacket.h"
#include "SocketWrapper.h"
#include <stdint.h>
struct connection;
struct OVERLAPCONTEXT
{
st_io m_super;
int8_t isUsed;
struct connection *c;
};
typedef void (*process_packet)(struct connection*,rpacket_t);
typedef void (*on_disconnect)(struct connection*,int32_t reason);
#define MAX_WBAF 1024
struct connection
{
HANDLE socket;
struct iovec wsendbuf[MAX_WBAF];
struct iovec wrecvbuf[2];
struct OVERLAPCONTEXT send_overlap;
struct OVERLAPCONTEXT recv_overlap;
uint32_t unpack_size; //还未解包的数据大小
uint32_t unpack_pos;
uint32_t next_recv_pos;
buffer_t next_recv_buf;
buffer_t unpack_buf;
struct link_list *send_list;//待发送的包
process_packet _process_packet;
on_disconnect _on_disconnect;
uint8_t mt;
uint8_t raw;
uint16_t is_close;
};
struct connection *connection_create(HANDLE s,uint8_t is_raw,uint8_t mt,process_packet,on_disconnect);
void connection_active_close(struct connection*);//active close connection
int connection_destroy(struct connection**);
//仅仅把包放入发送队列
void connection_push_packet(struct connection*,wpacket_t,packet_send_finish);
//返回值:0,连接断开;否则正常
int32_t connection_send(struct connection*,wpacket_t,packet_send_finish);
int32_t connection_start_recv(struct connection*);
void SendFinish(int32_t bytetransfer,st_io *io);
void RecvFinish(int32_t bytetransfer,st_io *io);
#endif