diff options
author | Uros Majstorovic <majstor@majstor.org> | 2022-03-12 13:08:52 +0100 |
---|---|---|
committer | Uros Majstorovic <majstor@majstor.org> | 2022-03-12 13:08:52 +0100 |
commit | 3436ce5d3ffbc2777e785310bac971c830cbb4ff (patch) | |
tree | c3ffb0d18bb992e8b97818e4d0b369844979012d /ecp/src/ecp/rbuf.h | |
parent | d359dd9981f4137e8873a7a571e5c54c5b2449c4 (diff) |
new rev compile OK
Diffstat (limited to 'ecp/src/ecp/rbuf.h')
-rw-r--r-- | ecp/src/ecp/rbuf.h | 115 |
1 files changed, 55 insertions, 60 deletions
diff --git a/ecp/src/ecp/rbuf.h b/ecp/src/ecp/rbuf.h index 31aeb39..36ff963 100644 --- a/ecp/src/ecp/rbuf.h +++ b/ecp/src/ecp/rbuf.h @@ -5,49 +5,36 @@ #define ECP_RBUF_FLAG_CCONTROL 0x01 #define ECP_RBUF_FLAG_RELIABLE 0x02 -#define ECP_RBUF_FLAG_MSGQ 0x04 -#define ECP_MTYPE_RBACK 0x04 -#define ECP_MTYPE_RBFLUSH 0x05 -#define ECP_MTYPE_RBTIMER 0x06 -#define ECP_MTYPE_NOP 0x07 + +#define ECP_MTYPE_RBNOP (0x08 | ECP_MTYPE_FLAG_SYS) +#define ECP_MTYPE_RBACK (0x09 | ECP_MTYPE_FLAG_SYS) +#define ECP_MTYPE_RBFLUSH (0x0a | ECP_MTYPE_FLAG_SYS) +#define ECP_MTYPE_RBTIMER (0x0b | ECP_MTYPE_FLAG_SYS) #define ECP_ERR_RBUF_DUP -100 +#define ECP_ERR_RBUF_TIMER -101 -typedef uint32_t ecp_win_t; +#define ecp_rbuf_skip(mtype) (mtype & ECP_MTYPE_FLAG_SYS) /* size must be power of 2 */ #define ECP_RBUF_IDX_MASK(idx, size) ((idx) & ((size) - 1)) -#define ecp_rbuf_skip(mtype) ((mtype & ECP_MTYPE_MASK) < ECP_MTYPE_NOP ? 1 : 0) -#ifdef ECP_WITH_MSGQ -#include "msgq.h" -#endif +typedef uint32_t ecp_win_t; -typedef struct ECPRBTimerItem { - ECPTimerItem item; - unsigned char empty; -} ECPRBTimerItem; +struct ECPMsgQ; +struct ECPFragIter; -typedef struct ECPRBTimer { - ECPRBTimerItem item[ECP_MAX_TIMER]; - unsigned short idx_w; -#ifdef ECP_WITH_PTHREAD - pthread_mutex_t mutex; -#endif -} ECPRBTimer; - -typedef struct ECPRBMessage { - unsigned char buf[ECP_MAX_MSG]; +typedef struct ECPRBPayload { + unsigned char buf[ECP_MAX_PLD]; size_t size; unsigned char flags; -} ECPRBMessage; +} ECPRBPayload; typedef struct ECPRBPacket { unsigned char buf[ECP_MAX_PKT]; size_t size; unsigned char flags; - ECPRBTimerItem *timer; } ECPRBPacket; typedef struct ECPRBuffer { @@ -56,27 +43,31 @@ typedef struct ECPRBuffer { unsigned short arr_size; unsigned short idx_start; union { - ECPRBMessage *msg; + ECPRBPayload *pld; ECPRBPacket *pkt; } arr; } ECPRBuffer; typedef struct ECPRBRecv { + unsigned char start; unsigned char flags; - ecp_cts_t deliver_delay; + ecp_sts_t deliver_delay; unsigned short hole_max; unsigned short ack_rate; unsigned short ack_pkt; ecp_seq_t seq_ack; ecp_ack_t ack_map; ECPRBuffer rbuf; +#ifdef ECP_WITH_PTHREAD + pthread_mutex_t mutex; +#endif #ifdef ECP_WITH_MSGQ - ECPConnMsgQ msgq; + struct ECPMsgQ *msgq; #endif - struct ECPFragIter *frag_iter; } ECPRBRecv; typedef struct ECPRBSend { + unsigned char start; unsigned char flags; ecp_win_t win_size; ecp_win_t in_transit; @@ -87,42 +78,46 @@ typedef struct ECPRBSend { unsigned char flush; unsigned int nack_rate; ECPRBuffer rbuf; - ECPRBTimer *timer; #ifdef ECP_WITH_PTHREAD pthread_mutex_t mutex; #endif } ECPRBSend; -typedef struct ECPConnRBuffer { +typedef struct ECPRBConn { + ECPConnection b; ECPRBRecv *recv; ECPRBSend *send; -} ECPConnRBuffer; + struct ECPFragIter *iter; +} ECPRBConn; -int _ecp_rbuf_start(ECPRBuffer *rbuf, ecp_seq_t seq); +ECPRBConn *ecp_rbuf_get_rbconn(ECPConnection *conn); +ECPConnection *ecp_rbuf_get_conn(ECPRBConn *conn); +void _ecp_rbuf_start(ECPRBuffer *rbuf, ecp_seq_t seq); int _ecp_rbuf_msg_idx(ECPRBuffer *rbuf, ecp_seq_t seq, unsigned short *idx); - -int ecp_rbuf_create(struct ECPConnection *conn, ECPRBSend *buf_s, ECPRBPacket *msg_s, unsigned int msg_s_size, ECPRBRecv *buf_r, ECPRBMessage *msg_r, unsigned int msg_r_size); -void ecp_rbuf_destroy(struct ECPConnection *conn); -ssize_t ecp_rbuf_pld_send(struct ECPConnection *conn, struct ECPBuffer *packet, struct ECPBuffer *payload, size_t pld_size, unsigned char flags, ecp_seq_t seq); -int ecp_rbuf_handle_seq(struct ECPConnection *conn, unsigned char mtype); -int ecp_rbuf_set_seq(struct ECPConnection *conn, struct ECPSeqItem *si, unsigned char *payload, size_t pld_size); -ssize_t ecp_rbuf_pkt_send(struct ECPConnection *conn, struct ECPSocket *sock, ECPNetAddr *addr, struct ECPBuffer *packet, size_t pkt_size, unsigned char flags, ECPTimerItem *ti, struct ECPSeqItem *si); - -int ecp_rbuf_recv_create(struct ECPConnection *conn, ECPRBRecv *buf, ECPRBMessage *msg, unsigned short msg_size); -void ecp_rbuf_recv_destroy(struct ECPConnection *conn); -int ecp_rbuf_recv_start(struct ECPConnection *conn, ecp_seq_t seq); -int ecp_rbuf_set_hole(struct ECPConnection *conn, unsigned short hole_max); -int ecp_rbuf_set_delay(struct ECPConnection *conn, ecp_cts_t delay); - -ssize_t ecp_rbuf_store(struct ECPConnection *conn, ecp_seq_t seq, unsigned char *msg, size_t msg_size, struct ECP2Buffer *b); -struct ECPFragIter *ecp_rbuf_get_frag_iter(struct ECPConnection *conn); - -int ecp_rbuf_send_create(struct ECPConnection *conn, ECPRBSend *buf, ECPRBPacket *msg, unsigned short msg_size); -void ecp_rbuf_send_destroy(struct ECPConnection *conn); -int ecp_rbuf_send_start(struct ECPConnection *conn); -int ecp_rbuf_flush(struct ECPConnection *conn); -int ecp_rbuf_set_wsize(struct ECPConnection *conn, ecp_win_t size); - -ssize_t ecp_rbuf_handle_ack(struct ECPConnection *conn, ecp_seq_t seq, unsigned char mtype, unsigned char *msg, ssize_t size, struct ECP2Buffer *b); -ssize_t ecp_rbuf_handle_flush(struct ECPConnection *conn, ecp_seq_t seq, unsigned char mtype, unsigned char *msg, ssize_t size, struct ECP2Buffer *b); -ssize_t ecp_rbuf_handle_timer(struct ECPConnection *conn, ecp_seq_t seq, unsigned char mtype, unsigned char *msg, ssize_t size, struct ECP2Buffer *b); +void ecp_rbuf_conn_init(ECPRBConn *conn); +int ecp_rbuf_conn_create(ECPRBConn *conn, ECPSocket *sock, unsigned char type); +int ecp_rbuf_conn_create_inb(ECPRBConn *conn, ECPSocket *sock, unsigned char type); +void ecp_rbuf_destroy(ECPRBConn *conn); +void ecp_rbuf_start(ECPRBConn *conn); +ssize_t ecp_rbuf_msg_handle(ECPRBConn *conn, ecp_seq_t seq, unsigned char mtype, unsigned char *msg, size_t msg_size, ECP2Buffer *bufs); +int ecp_rbuf_err_handle(ECPRBConn *conn, unsigned char mtype, int err); + +/* send */ +ssize_t ecp_rbuf_send_flush(ECPRBConn *conn); +ssize_t ecp_rbuf_handle_ack(ECPRBConn *conn, unsigned char *msg, size_t msg_size); +int ecp_rbsend_create(ECPRBConn *conn, ECPRBSend *buf, ECPRBPacket *pkt, unsigned short pkt_size); +void ecp_rbsend_destroy(ECPRBConn *conn); +void ecp_rbsend_start(ECPRBConn *conn, ecp_seq_t seq); +int ecp_rbuf_set_wsize(ECPRBConn *conn, ecp_win_t size); +int ecp_rbuf_flush(ECPRBConn *conn); +ssize_t ecp_rbuf_pld_send(ECPRBConn *conn, ECPBuffer *payload, size_t pld_size, ECPBuffer *packet, size_t pkt_size, ECPTimerItem *ti); + +ssize_t ecp_rbuf_handle_nop(ECPRBConn *conn, unsigned char *msg, size_t msg_size); +ssize_t ecp_rbuf_handle_flush(ECPRBConn *conn); +void ecp_rbuf_handle_timer(ECPRBConn *conn) ; +int ecp_rbrecv_create(ECPRBConn *conn, ECPRBRecv *buf, ECPRBPayload *pld, unsigned short pld_size); +void ecp_rbrecv_destroy(ECPRBConn *conn); +void ecp_rbrecv_start(ECPRBConn *conn, ecp_seq_t seq); +int ecp_rbuf_set_hole(ECPRBConn *conn, unsigned short hole_max); +int ecp_rbuf_set_delay(ECPRBConn *conn, ecp_sts_t delay); +ssize_t ecp_rbuf_store(ECPRBConn *conn, ecp_seq_t seq, unsigned char *pld, size_t pld_size); |