diff options
author | Uros Majstorovic <majstor@majstor.org> | 2018-03-21 05:57:15 +0100 |
---|---|---|
committer | Uros Majstorovic <majstor@majstor.org> | 2018-03-21 05:57:15 +0100 |
commit | 5afe15b354c2b7818924110f0a2d580f0f970001 (patch) | |
tree | bd5dcc4c74bc831971420dcf7015700c24c8e6a0 /code/ecp/rbuf.c | |
parent | 6c7ac8ffd4f21a159438959cb365c7caa279e149 (diff) |
rbuf code refactor
Diffstat (limited to 'code/ecp/rbuf.c')
-rw-r--r-- | code/ecp/rbuf.c | 59 |
1 files changed, 30 insertions, 29 deletions
diff --git a/code/ecp/rbuf.c b/code/ecp/rbuf.c index 080ba42..534381c 100644 --- a/code/ecp/rbuf.c +++ b/code/ecp/rbuf.c @@ -1,5 +1,35 @@ #include "core.h" +int ecp_rbuf_create(ECPConnection *conn, ECPRBSend *buf_s, ECPRBMessage *msg_s, unsigned int msg_s_size, ECPRBRecv *buf_r, ECPRBMessage *msg_r, unsigned int msg_r_size) { + int rv; + + if (buf_s) { + rv = ecp_rbuf_send_create(conn, buf_s, msg_s, msg_s_size); + if (rv) return rv; + + rv = ecp_rbuf_send_start(conn); + if (rv) { + ecp_rbuf_send_destroy(conn); + return rv; + } + } + + if (buf_r) { + rv = ecp_rbuf_recv_create(conn, buf_r, msg_r, msg_r_size); + if (rv) { + if (buf_s) ecp_rbuf_send_destroy(conn); + return rv; + } + } + + return ECP_OK; +} + +void ecp_rbuf_destroy(ECPConnection *conn) { + ecp_rbuf_send_destroy(conn); + ecp_rbuf_recv_destroy(conn); +} + int ecp_rbuf_init(ECPRBuffer *rbuf, ECPRBMessage *msg, unsigned int msg_size) { rbuf->msg = msg; if (msg_size) { @@ -65,32 +95,3 @@ ssize_t ecp_rbuf_pld_send(ECPConnection *conn, ECPBuffer *packet, ECPBuffer *pay return rv; } -int ecp_rbuf_create(ECPConnection *conn, ECPRBSend *buf_s, ECPRBMessage *msg_s, unsigned int msg_s_size, ECPRBRecv *buf_r, ECPRBMessage *msg_r, unsigned int msg_r_size) { - int rv; - - if (buf_s) { - rv = ecp_rbuf_send_create(conn, buf_s, msg_s, msg_s_size); - if (rv) return rv; - - rv = ecp_rbuf_send_start(conn); - if (rv) { - ecp_rbuf_send_destroy(conn); - return rv; - } - } - - if (buf_r) { - rv = ecp_rbuf_recv_create(conn, buf_r, msg_r, msg_r_size); - if (rv) { - if (buf_s) ecp_rbuf_send_destroy(conn); - return rv; - } - } - - return ECP_OK; -} - -void ecp_rbuf_destroy(ECPConnection *conn) { - ecp_rbuf_send_destroy(conn); - ecp_rbuf_recv_destroy(conn); -} |