You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@heron.apache.org by GitBox <gi...@apache.org> on 2018/07/05 16:59:43 UTC
[GitHub] nwangtw commented on a change in pull request #2950: Add signal
handling to stream manager
nwangtw commented on a change in pull request #2950: Add signal handling to stream manager
URL: https://github.com/apache/incubator-heron/pull/2950#discussion_r200422761
##########
File path: heron/common/src/cpp/network/event_loop_impl.cpp
##########
@@ -83,6 +89,39 @@ void EventLoopImpl::loop() {
int EventLoopImpl::loopExit() { return event_base_loopbreak(mDispatcher); }
+int EventLoopImpl::registerSignal(int sig, VCallback<EventLoop::Status> cb) {
+ // Create the appropriate structures and init them.
+ auto* event = new SS_RegisteredEvent<sp_int32>(sig, false, std::move(cb), -1);
+ evsignal_set(event->event(), sig, &EventLoopImpl::eventLoopImplSignalCallback, this);
+ if (event_base_set(mDispatcher, event->event()) < 0) {
+ delete event;
+ throw heron::error::Error_Exception(errno);
+ }
+
+ // Now add it to the list of signals monitored by the mDispatcher
+ if (event_add(event->event(), NULL) < 0) {
+ delete event;
+ throw heron::error::Error_Exception(errno);
+ }
+ mSignalEvents[sig] = event;
+ return 0;
+}
+
+int EventLoopImpl::unRegisterSignal(int sig) {
+ if (mSignalEvents.find(sig) == mSignalEvents.end()) {
+ // This signal wasn't registed. Hence we can't unregister it.
+ return -1;
+ }
+
+ // Delete the underlying event in libevent
+ if (event_del(mSignalEvents[sig]->event()) != 0) {
+ throw heron::error::Error_Exception(errno);
+ }
+ delete mSignalEvents[sig];
Review comment:
safer way is to use a temp var to make sure the object is erased from the map before deleting it.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services