diff options
-rw-r--r-- | include/salticidae/event.h | 10 | ||||
-rw-r--r-- | include/salticidae/netaddr.h | 1 | ||||
-rw-r--r-- | src/event.cpp | 17 | ||||
-rw-r--r-- | src/msg.cpp | 4 | ||||
-rw-r--r-- | src/network.cpp | 6 | ||||
-rw-r--r-- | src/stream.cpp | 4 |
6 files changed, 31 insertions, 11 deletions
diff --git a/include/salticidae/event.h b/include/salticidae/event.h index 4dd00d7..c4f65ba 100644 --- a/include/salticidae/event.h +++ b/include/salticidae/event.h @@ -235,6 +235,8 @@ class TimerEvent { } operator bool() const { return ev_timer != nullptr; } + + const EventContext &get_ec() const { return ec; } }; class TimedFdEvent: public FdEvent, public TimerEvent { @@ -412,6 +414,8 @@ class SigEvent { } operator bool() const { return ev_sig != nullptr; } + + const EventContext &get_ec() const { return ec; } }; template<typename T> @@ -681,12 +685,15 @@ typedef void (*threadcall_callback_t)(threadcall_handle_t *handle, void *userdat threadcall_t *threadcall_new(const eventcontext_t *ec); void threadcall_free(threadcall_t *self); void threadcall_async_call(threadcall_t *self, threadcall_callback_t callback, void *userdata); -eventcontext_t *threadcall_get_ec(threadcall_t *self); +const eventcontext_t *threadcall_get_ec(const threadcall_t *self); typedef void (*sigev_callback_t)(int signum, void *); sigev_t *sigev_new(const eventcontext_t *ec, sigev_callback_t cb, void *userdata); void sigev_free(sigev_t *self); void sigev_add(sigev_t *self, int signum); +void sigev_del(sigev_t *self); +void sigev_clear(sigev_t *self); +const eventcontext_t *sigev_get_ec(const sigev_t *self); typedef void (*timerev_callback_t)(timerev_t *, void *); timerev_t *timerev_new(const eventcontext_t *ec, timerev_callback_t callback, void *); @@ -695,6 +702,7 @@ void timerev_free(timerev_t *self); void timerev_add(timerev_t *self, double t_sec); void timerev_del(timerev_t *self); void timerev_clear(timerev_t *self); +const eventcontext_t *timerev_get_ec(const timerev_t *self); #ifdef __cplusplus } diff --git a/include/salticidae/netaddr.h b/include/salticidae/netaddr.h index a25bf6f..bff4cb7 100644 --- a/include/salticidae/netaddr.h +++ b/include/salticidae/netaddr.h @@ -147,6 +147,7 @@ uint32_t netaddr_get_ip(const netaddr_t *self); uint16_t netaddr_get_port(const netaddr_t *self); netaddr_array_t *netaddr_array_new(); netaddr_array_t *netaddr_array_new_from_addrs(const netaddr_t * const *paddrs, size_t naddrs); +void netaddr_array_free(netaddr_array_t *self); #ifdef __cplusplus } diff --git a/src/event.cpp b/src/event.cpp index 4e5ce0b..2fe2861 100644 --- a/src/event.cpp +++ b/src/event.cpp @@ -28,14 +28,22 @@ void threadcall_async_call(threadcall_t *self, threadcall_callback_t callback, v }); } -eventcontext_t *threadcall_get_ec(threadcall_t *self) { - return new eventcontext_t(self->get_ec()); +const eventcontext_t *threadcall_get_ec(const threadcall_t *self) { + return &self->get_ec(); } void sigev_free(sigev_t *self) { delete self; } void sigev_add(sigev_t *self, int signum) { self->add(signum); } +void sigev_del(sigev_t *self) { self->del(); } + +void sigev_clear(sigev_t *self) { self->clear(); } + +const eventcontext_t *sigev_get_ec(const sigev_t *self) { + return &self->get_ec(); +} + timerev_t *timerev_new(const eventcontext_t *ec, timerev_callback_t callback, void *userdata) { return new timerev_t(*ec, [=](salticidae::TimerEvent &ev) { callback(&ev, userdata); @@ -48,6 +56,11 @@ void timerev_set_callback(timerev_t *self, timerev_callback_t callback, void *us }); } + +const eventcontext_t *timerev_get_ec(const timerev_t *self) { + return &self->get_ec(); +} + void timerev_free(timerev_t *self) { delete self; } void timerev_add(timerev_t *self, double t_sec) { self->add(t_sec); } diff --git a/src/msg.cpp b/src/msg.cpp index d525cd5..be5b4b1 100644 --- a/src/msg.cpp +++ b/src/msg.cpp @@ -5,9 +5,7 @@ extern "C" { msg_t *msg_new_moved_from_bytearray(_opcode_t opcode, bytearray_t *_moved_payload) { - auto res = new msg_t(opcode, std::move(*_moved_payload)); - bytearray_free(_moved_payload); - return res; + return new msg_t(opcode, std::move(*_moved_payload)); } void msg_free(msg_t *msg) { delete msg; } diff --git a/src/network.cpp b/src/network.cpp index ef16bed..a1666ec 100644 --- a/src/network.cpp +++ b/src/network.cpp @@ -47,7 +47,7 @@ void msgnetwork_config_queue_capacity(msgnetwork_config_t *self, size_t cap) { void msgnetwork_send_msg_by_move(msgnetwork_t *self, msg_t *_moved_msg, const msgnetwork_conn_t *conn) { self->_send_msg(std::move(*_moved_msg), *conn); - delete _moved_msg; + //delete _moved_msg; } msgnetwork_conn_t *msgnetwork_connect(msgnetwork_t *self, const netaddr_t *addr, SalticidaeCError *cerror) { @@ -204,14 +204,14 @@ void peernetwork_conn_free(const peernetwork_conn_t *self) { delete self; } void peernetwork_send_msg_by_move(peernetwork_t *self, msg_t * _moved_msg, const netaddr_t *paddr) { self->_send_msg(std::move(*_moved_msg), *paddr); - delete _moved_msg; + //delete _moved_msg; } void peernetwork_multicast_msg_by_move(peernetwork_t *self, msg_t *_moved_msg, const netaddr_array_t *paddrs) { self->_multicast_msg(std::move(*_moved_msg), *paddrs); - delete _moved_msg; + //delete _moved_msg; } void peernetwork_listen(peernetwork_t *self, const netaddr_t *listen_addr, SalticidaeCError *cerror) { diff --git a/src/stream.cpp b/src/stream.cpp index 1d88785..13ee98f 100644 --- a/src/stream.cpp +++ b/src/stream.cpp @@ -51,7 +51,7 @@ bool datastream_assign_by_copy(datastream_t *dst, const datastream_t *src) { bool datastream_assign_by_move(datastream_t *dst, datastream_t *_moved_src) { try { *dst = std::move(*_moved_src); - delete _moved_src; + //delete _moved_src; } catch (...) { return false; } return true; } @@ -108,7 +108,7 @@ uint256_t *datastream_get_hash(const datastream_t *self) { bytearray_t *bytearray_new_moved_from_datastream(datastream_t *_moved_src) { try { auto res = new bytearray_t(std::move(*_moved_src)); - delete _moved_src; + //delete _moved_src; return res; } catch (...) { return nullptr; |