2
2
#include < cstring>
3
3
#include < iostream>
4
4
#include < cstdlib>
5
- #include < csignal>
6
5
#include < cerrno>
7
6
8
7
#include " msgq/impl_msgq.h"
9
8
10
-
11
- volatile sig_atomic_t msgq_do_exit = 0 ;
12
-
13
- void sig_handler (int signal) {
14
- assert (signal == SIGINT || signal == SIGTERM);
15
- msgq_do_exit = 1 ;
16
- }
17
-
18
-
19
9
MSGQContext::MSGQContext () {
20
10
}
21
11
@@ -72,23 +62,14 @@ int MSGQSubSocket::connect(Context *context, std::string endpoint, std::string a
72
62
73
63
74
64
Message * MSGQSubSocket::receive (bool non_blocking){
75
- msgq_do_exit = 0 ;
76
-
77
- void (*prev_handler_sigint)(int );
78
- void (*prev_handler_sigterm)(int );
79
- if (!non_blocking){
80
- prev_handler_sigint = std::signal (SIGINT, sig_handler);
81
- prev_handler_sigterm = std::signal (SIGTERM, sig_handler);
82
- }
83
-
84
65
msgq_msg_t msg;
85
66
86
67
MSGQMessage *r = NULL ;
87
68
88
69
int rc = msgq_msg_recv (&msg, q);
89
70
90
71
// Hack to implement blocking read with a poller. Don't use this
91
- while (!non_blocking && rc == 0 && msgq_do_exit == 0 ){
72
+ while (!non_blocking && rc == 0 ){
92
73
msgq_pollitem_t items[1 ];
93
74
items[0 ].q = q;
94
75
@@ -107,21 +88,9 @@ Message * MSGQSubSocket::receive(bool non_blocking){
107
88
}
108
89
}
109
90
110
-
111
- if (!non_blocking){
112
- std::signal (SIGINT, prev_handler_sigint);
113
- std::signal (SIGTERM, prev_handler_sigterm);
114
- }
115
-
116
- errno = msgq_do_exit ? EINTR : 0 ;
117
-
118
91
if (rc > 0 ){
119
- if (msgq_do_exit){
120
- msgq_msg_close (&msg); // Free unused message on exit
121
- } else {
122
- r = new MSGQMessage;
123
- r->takeOwnership (msg.data , msg.size );
124
- }
92
+ r = new MSGQMessage;
93
+ r->takeOwnership (msg.data , msg.size );
125
94
}
126
95
127
96
return (Message*)r;
0 commit comments