File tree Expand file tree Collapse file tree 2 files changed +14
-7
lines changed
Expand file tree Collapse file tree 2 files changed +14
-7
lines changed Original file line number Diff line number Diff line change @@ -61,12 +61,8 @@ int main(int argc, char* argv[]) {
6161 try {
6262 Connection connection (broker, port);
6363 connection.queueBind (" timed_queue_test" );
64- while (true ) {
65- std::vector<uint8_t > v = connection.collect ();
66- if (v.size () != 0 ) {
67- std::cout << " recieved message from timed queue!" << std::endl;
68- }
69- }
64+ std::vector<uint8_t > v = connection.collect ();
65+ std::cout << " recieved message from timed queue!" << std::endl;
7066 } catch (PostmanException e) {
7167 std::cout << e.what () << std::endl;
7268 }
Original file line number Diff line number Diff line change 1010#include < algorithm>
1111#include < cerrno>
1212#include < vector>
13+ #include < thread>
14+ #include < chrono>
1315
1416const int queueNameSize = 255 ;
1517const int keySize = 255 ;
@@ -119,7 +121,16 @@ void ConnectionReciever::handleMessageCollection() {
119121 return ;
120122 }
121123
122- std::vector<uint8_t > message = _queue->collect ();
124+ bool waiting = true ;
125+ std::vector<uint8_t > message;
126+ while (waiting) {
127+ message = _queue->collect ();
128+ if (message.size () != 0 ) {
129+ waiting = false ;
130+ } else {
131+ std::this_thread::sleep_for (std::chrono::milliseconds (100 ));
132+ }
133+ }
123134 uint64_t size = message.size ();
124135
125136 if (write (_socket, &size, 8 ) < 0 ) {
You can’t perform that action at this time.
0 commit comments