diff options
author | Determinant <[email protected]> | 2019-07-01 23:35:17 -0400 |
---|---|---|
committer | Determinant <[email protected]> | 2019-07-01 23:35:17 -0400 |
commit | 53f776997d0e92650b9f3a16224cef1c0c76b716 (patch) | |
tree | de7c0a20dd4ba1d4bc5ea229e723ab8608ed94af /src | |
parent | 85b9affbce70ac4b5922158802b227a42c42a203 (diff) |
add async id for error handling
Diffstat (limited to 'src')
-rw-r--r-- | src/conn.cpp | 4 | ||||
-rw-r--r-- | src/network.cpp | 40 | ||||
-rw-r--r-- | src/util.cpp | 1 |
3 files changed, 25 insertions, 20 deletions
diff --git a/src/conn.cpp b/src/conn.cpp index abea7ac..13486ee 100644 --- a/src/conn.cpp +++ b/src/conn.cpp @@ -303,7 +303,7 @@ void ConnPool::accept_client(int fd, int) { conn->worker = &worker; worker.feed(conn, client_fd); } - } catch (...) { recoverable_error(std::current_exception()); } + } catch (...) { recoverable_error(std::current_exception(), -1); } } void ConnPool::conn_server(const conn_t &conn, int fd, int events) { @@ -324,7 +324,7 @@ void ConnPool::conn_server(const conn_t &conn, int fd, int events) { } } catch (...) { disp_terminate(conn); - recoverable_error(std::current_exception()); + recoverable_error(std::current_exception(), -1); } } diff --git a/src/network.cpp b/src/network.cpp index 05e7b50..2e98439 100644 --- a/src/network.cpp +++ b/src/network.cpp @@ -67,22 +67,26 @@ void msgnetwork_config_tls_cert_by_move(msgnetwork_config_t *self, x509_t *cert) self->tls_cert(new x509_t(std::move(*cert))); } -void msgnetwork_send_msg(msgnetwork_t *self, const msg_t *msg, const msgnetwork_conn_t *conn) { - self->_send_msg(*msg, *conn); +bool msgnetwork_send_msg(msgnetwork_t *self, const msg_t *msg, const msgnetwork_conn_t *conn) { + return self->_send_msg(*msg, *conn); } -void msgnetwork_send_msg_deferred_by_move(msgnetwork_t *self, +int32_t msgnetwork_send_msg_deferred_by_move(msgnetwork_t *self, msg_t *_moved_msg, const msgnetwork_conn_t *conn) { - self->_send_msg_deferred(std::move(*_moved_msg), *conn); + return self->_send_msg_deferred(std::move(*_moved_msg), *conn); } -msgnetwork_conn_t *msgnetwork_connect(msgnetwork_t *self, const netaddr_t *addr, bool blocking, SalticidaeCError *cerror) { +msgnetwork_conn_t *msgnetwork_connect_sync(msgnetwork_t *self, const netaddr_t *addr, SalticidaeCError *cerror) { SALTICIDAE_CERROR_TRY(cerror) - return new msgnetwork_conn_t(self->connect(*addr, blocking)); + return new msgnetwork_conn_t(self->connect_sync(*addr)); SALTICIDAE_CERROR_CATCH(cerror) return nullptr; } +int32_t msgnetwork_connect(msgnetwork_t *self, const netaddr_t *addr) { + return self->connect(*addr); +} + msgnetwork_conn_t *msgnetwork_conn_copy(const msgnetwork_conn_t *self) { return new msgnetwork_conn_t(*self); } @@ -126,7 +130,7 @@ void msgnetwork_reg_conn_handler(msgnetwork_t *self, void msgnetwork_reg_error_handler(msgnetwork_t *self, msgnetwork_error_callback_t cb, void *userdata) { - self->reg_error_handler([=](const std::exception_ptr _err, bool fatal) { + self->reg_error_handler([=](const std::exception_ptr _err, bool fatal, int32_t async_id) { SalticidaeCError cerror; try { std::rethrow_exception(_err); @@ -135,7 +139,7 @@ void msgnetwork_reg_error_handler(msgnetwork_t *self, } catch (...) { cerror = salticidae_cerror_unknown(); } - cb(&cerror, fatal, userdata); + cb(&cerror, fatal, async_id, userdata); }); } @@ -194,12 +198,12 @@ peernetwork_t *peernetwork_new(const eventcontext_t *ec, const peernetwork_confi void peernetwork_free(const peernetwork_t *self) { delete self; } -void peernetwork_add_peer(peernetwork_t *self, const netaddr_t *addr) { - self->add_peer(*addr); +int32_t peernetwork_add_peer(peernetwork_t *self, const netaddr_t *addr) { + return self->add_peer(*addr); } -void peernetwork_del_peer(peernetwork_t *self, const netaddr_t *addr) { - self->del_peer(*addr); +int32_t peernetwork_del_peer(peernetwork_t *self, const netaddr_t *addr) { + return self->del_peer(*addr); } bool peernetwork_has_peer(const peernetwork_t *self, const netaddr_t *addr) { @@ -248,14 +252,14 @@ bool peernetwork_send_msg(peernetwork_t *self, const msg_t * msg, const netaddr_ } } -void peernetwork_send_msg_deferred_by_move(peernetwork_t *self, +int32_t peernetwork_send_msg_deferred_by_move(peernetwork_t *self, msg_t *_moved_msg, const netaddr_t *addr) { - self->_send_msg_deferred(std::move(*_moved_msg), *addr); + return self->_send_msg_deferred(std::move(*_moved_msg), *addr); } -void peernetwork_multicast_msg_by_move(peernetwork_t *self, +int32_t peernetwork_multicast_msg_by_move(peernetwork_t *self, msg_t *_moved_msg, const netaddr_array_t *addrs) { - self->_multicast_msg(std::move(*_moved_msg), *addrs); + return self->_multicast_msg(std::move(*_moved_msg), *addrs); } void peernetwork_listen(peernetwork_t *self, const netaddr_t *listen_addr, SalticidaeCError *cerror) { @@ -318,8 +322,8 @@ bool clientnetwork_send_msg(clientnetwork_t *self, const msg_t * msg, const neta } } -void clientnetwork_send_msg_deferred_by_move(clientnetwork_t *self, msg_t *_moved_msg, const netaddr_t *addr) { - self->_send_msg_deferred(std::move(*_moved_msg), *addr); +int32_t clientnetwork_send_msg_deferred_by_move(clientnetwork_t *self, msg_t *_moved_msg, const netaddr_t *addr) { + return self->_send_msg_deferred(std::move(*_moved_msg), *addr); } } diff --git a/src/util.cpp b/src/util.cpp index ff41c9b..0fb990e 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -58,6 +58,7 @@ const char *SALTICIDAE_ERROR_STRINGS[] = { "tls fail to get peer cert", "fd error", "rand source is not available, try again", + "connection is not ready", "unknown error" }; |