| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #include <fstream> | ||
| 2 | #include <iostream> | ||
| 3 | #include <thread> | ||
| 4 | #include <unistd.h> | ||
| 5 | |||
| 6 | #include "data_stream_assert.h" | ||
| 7 | #include "PGenericSocketManager.h" | ||
| 8 | #include "PZmqBackend.h" | ||
| 9 | |||
| 10 | using Time = std::chrono::steady_clock; | ||
| 11 | using ms = std::chrono::milliseconds; | ||
| 12 | |||
| 13 | typedef PGenericSocketManager<std::string, PZmqBackend, PMockBackend> SocketManager; | ||
| 14 | typedef SocketManager::Backend Backend; | ||
| 15 | typedef SocketManager::Mock Mock; | ||
| 16 | |||
| 17 | /// Check that socket receives nbMessage messages | ||
| 18 | /** @param[out] manager : socket manager to be used | ||
| 19 | * @param nbMessage : number of message to be read | ||
| 20 | */ | ||
| 21 | 1 | void ReceiveMessage(SocketManager &manager, size_t nbMessage) | |
| 22 | { | ||
| 23 | 1 | std::cout << "ReceiveMessage : read message to 'Bob'" << std::endl; | |
| 24 | 1 | size_t nbRecv = 0; | |
| 25 | PRecvStatus::PRecvStatus status; | ||
| 26 | do{ | ||
| 27 | 184 | size_t value(0lu); | |
| 28 |
2/2✓ Branch 0 (7→8) taken 184 times.
✓ Branch 2 (8→9) taken 184 times.
|
184 | status = manager.recvData("Bob", value, PRecvFlag::NON_BLOCK); |
| 29 |
5/5✓ Branch 0 (11→12) taken 184 times.
✓ Branch 2 (12→13) taken 184 times.
✓ Branch 4 (13→14) taken 184 times.
✓ Branch 6 (14→15) taken 184 times.
✓ Branch 8 (15→16) taken 184 times.
|
184 | std::cout << "recv status: " << status << " for message n°" << nbRecv << std::endl; |
| 30 |
2/2✓ Branch 0 (16→17) taken 10 times.
✓ Branch 1 (16→18) taken 174 times.
|
184 | if(status == PRecvStatus::OK){ |
| 31 | 10 | nbRecv++; | |
| 32 | } | ||
| 33 |
1/2✓ Branch 0 (18→19) taken 174 times.
✗ Branch 1 (18→22) not taken.
|
174 | else if(status == PRecvStatus::NO_MESSAGE_RECEIVED){ |
| 34 |
1/1✓ Branch 0 (20→21) taken 174 times.
|
174 | std::this_thread::sleep_for(ms(1)); // Wait and retry |
| 35 | } | ||
| 36 | else{ | ||
| 37 | ✗ | data_stream_assert(false); | |
| 38 | } | ||
| 39 |
2/2✓ Branch 0 (39→5) taken 183 times.
✓ Branch 1 (39→40) taken 1 times.
|
184 | } while (nbRecv<nbMessage); |
| 40 | 1 | } | |
| 41 | |||
| 42 | 1 | int main(int argc, char **argv) | |
| 43 | { | ||
| 44 | |||
| 45 | 1 | PSocketMode::PSocketMode mode = PSocketMode::NO_MOCK; | |
| 46 | 1 | size_t nbMessage(10lu), port(3390); | |
| 47 |
1/1✓ Branch 0 (4→5) taken 1 times.
|
1 | std::string hostName("localhost"); |
| 48 |
1/1✓ Branch 0 (6→7) taken 1 times.
|
1 | SocketManager manager(mode); |
| 49 |
11/14✓ Branch 0 (9→10) taken 1 times.
✓ Branch 2 (12→13) taken 1 times.
✓ Branch 4 (15→16) taken 1 times.
✓ Branch 6 (16→17) taken 1 times.
✓ Branch 8 (19→20) taken 1 times.
✓ Branch 10 (20→21) taken 1 times.
✓ Branch 12 (21→22) taken 1 times.
✓ Branch 14 (24→25) taken 1 times.
✓ Branch 16 (25→26) taken 1 times.
✓ Branch 18 (26→27) taken 1 times.
✗ Branch 20 (30→31) not taken.
✓ Branch 21 (30→32) taken 1 times.
✗ Branch 22 (56→57) not taken.
✗ Branch 23 (56→58) not taken.
|
9 | data_stream_assert(manager.addClientSocket("Bob", PSocketParam{hostName, port}, Backend::client(), "./", Mock::client())); |
| 50 |
1/1✓ Branch 0 (40→41) taken 1 times.
|
1 | ReceiveMessage(manager, nbMessage); |
| 51 | |||
| 52 | 1 | return 0; | |
| 53 | 1 | } | |
| 54 |