summaryrefslogtreecommitdiff
path: root/ecp/src/ecp/ext/rbuf.c
diff options
context:
space:
mode:
Diffstat (limited to 'ecp/src/ecp/ext/rbuf.c')
-rw-r--r--ecp/src/ecp/ext/rbuf.c52
1 files changed, 32 insertions, 20 deletions
diff --git a/ecp/src/ecp/ext/rbuf.c b/ecp/src/ecp/ext/rbuf.c
index 70ee0d2..e1fab7b 100644
--- a/ecp/src/ecp/ext/rbuf.c
+++ b/ecp/src/ecp/ext/rbuf.c
@@ -1,6 +1,6 @@
#include <stdlib.h>
-#include <core.h>
+#include <ecp/core.h>
#include "rbuf.h"
@@ -28,41 +28,35 @@ int _ecp_rbuf_msg_idx(ECPRBuffer *rbuf, ecp_seq_t seq, unsigned short *idx) {
return ECP_OK;
}
-void ecp_rbuf_conn_init(ECPRBConn *conn) {
+void ecp_rbuf_init(ECPRBConn *conn) {
ECPConnection *_conn = ecp_rbuf_get_conn(conn);
ecp_conn_set_flags(_conn, ECP_CONN_FLAG_RBUF);
conn->send = NULL;
conn->recv = NULL;
- conn->iter = NULL;
}
-int ecp_rbuf_conn_create(ECPRBConn *conn, ECPSocket *sock, unsigned char type) {
- ECPConnection *_conn = ecp_rbuf_get_conn(conn);
+int ecp_rbuf_create(ECPRBConn *conn) {
int rv;
- rv = ecp_conn_create(_conn, sock, type);
- if (rv) return rv;
-
- ecp_rbuf_conn_init(conn);
- return ECP_OK;
-}
-
-int ecp_rbuf_conn_create_inb(ECPRBConn *conn, ECPSocket *sock, unsigned char type) {
- ECPConnection *_conn = ecp_rbuf_get_conn(conn);
- int rv;
-
- rv = ecp_conn_create_inb(_conn, sock, type);
- if (rv) return rv;
+ if (conn->send) {
+ rv = ecp_rbsend_create(conn);
+ if (rv) return rv;
+ }
+ if (conn->recv) {
+ rv = ecp_rbrecv_create(conn);
+ if (rv) {
+ if (conn->send) ecp_rbsend_destroy(conn);
+ return rv;
+ }
+ }
- ecp_rbuf_conn_init(conn);
return ECP_OK;
}
void ecp_rbuf_destroy(ECPRBConn *conn) {
if (conn->send) ecp_rbsend_destroy(conn);
if (conn->recv) ecp_rbrecv_destroy(conn);
- conn->iter = NULL;
}
void ecp_rbuf_start(ECPRBConn *conn) {
@@ -71,14 +65,32 @@ void ecp_rbuf_start(ECPRBConn *conn) {
if (conn->send) {
ecp_seq_t seq_out;
+#ifdef ECP_WITH_PTHREAD
+ pthread_mutex_lock(&_conn->mutex);
+#endif
+
seq_out = (ecp_seq_t)(_conn->nonce_out);
+
+#ifdef ECP_WITH_PTHREAD
+ pthread_mutex_unlock(&_conn->mutex);
+#endif
+
ecp_rbsend_start(conn, seq_out);
}
if (conn->recv) {
ecp_seq_t seq_in;
+#ifdef ECP_WITH_PTHREAD
+ pthread_mutex_lock(&_conn->mutex);
+#endif
+
seq_in = (ecp_seq_t)(_conn->nonce_in);
+
+#ifdef ECP_WITH_PTHREAD
+ pthread_mutex_unlock(&_conn->mutex);
+#endif
+
ecp_rbrecv_start(conn, seq_in);
}
}