| 113 | }; |
| 114 | |
| 115 | int main(int argc, char** argv) { |
| 116 | bool use_tcp = false; |
| 117 | |
| 118 | std::string tcp_enable("--tcp"); |
| 119 | std::string udp_enable("--udp"); |
| 120 | |
| 121 | int i = 1; |
| 122 | while (i < argc) { |
| 123 | if (tcp_enable == argv[i]) { |
| 124 | use_tcp = true; |
| 125 | } else if (udp_enable == argv[i]) { |
| 126 | use_tcp = false; |
| 127 | } |
| 128 | i++; |
| 129 | } |
| 130 | |
| 131 | #ifndef VSOMEIP_ENABLE_SIGNAL_HANDLING |
| 132 | #if defined(__linux__) || defined(__QNX__) |
| 133 | sigset_t its_signals; |
| 134 | sigemptyset(&its_signals); |
| 135 | sigaddset(&its_signals, SIGINT); |
| 136 | sigaddset(&its_signals, SIGTERM); |
| 137 | pthread_sigmask(SIG_BLOCK, &its_signals, nullptr); |
| 138 | #endif |
| 139 | #endif |
| 140 | |
| 141 | client_sample its_sample(use_tcp); |
| 142 | if (its_sample.init()) { |
| 143 | #ifndef VSOMEIP_ENABLE_SIGNAL_HANDLING |
| 144 | #if defined(__linux__) || defined(__QNX__) |
| 145 | std::thread signal_watcher([&its_sample]() { |
| 146 | sigset_t its_wait_set; |
| 147 | sigemptyset(&its_wait_set); |
| 148 | sigaddset(&its_wait_set, SIGINT); |
| 149 | sigaddset(&its_wait_set, SIGTERM); |
| 150 | |
| 151 | int its_signal = 0; |
| 152 | while (sigwait(&its_wait_set, &its_signal) == 0) { |
| 153 | if (its_signal == SIGINT || its_signal == SIGTERM) { |
| 154 | its_sample.stop(); |
| 155 | return; |
| 156 | } |
| 157 | } |
| 158 | }); |
| 159 | #endif |
| 160 | #endif |
| 161 | its_sample.start(); |
| 162 | #ifdef VSOMEIP_ENABLE_SIGNAL_HANDLING |
| 163 | its_sample.stop(); |
| 164 | #endif |
| 165 | #ifndef VSOMEIP_ENABLE_SIGNAL_HANDLING |
| 166 | #if defined(__linux__) || defined(__QNX__) |
| 167 | if (signal_watcher.joinable()) { |
| 168 | signal_watcher.join(); |
| 169 | } |
| 170 | #endif |
| 171 | #endif |
| 172 | return 0; |