Skip to content

Commit 942c8ba

Browse files
committed
Replaced usage of usleep (not available in Visual C++) with C++11's std::this_thread::sleep_for & std::chrono::microseconds.
- disabled build error from warning C4716 because process_request does not return a value and Visual C++ doesn't support [[noreturn]]
1 parent a488568 commit 942c8ba

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

examples/reading_logs_via_rule_message/reading_logs_via_rule_message.h

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,11 @@
1313
*
1414
*/
1515

16-
#include <unistd.h>
17-
1816
#include <string>
1917
#include <memory>
18+
#include <thread>
19+
#include <chrono>
20+
#include <pthread.h>
2021

2122

2223
#define NUM_THREADS 100
@@ -72,6 +73,11 @@ struct data_ms {
7273
modsecurity::RulesSet *rules;
7374
};
7475

76+
#if defined _MSC_VER
77+
#pragma warning(push)
78+
#pragma warning(disable:4716) // avoid error C4716: 'process_request': must return a value, as MSVC C++ compiler doesn't support [[noreturn]]
79+
#pragma warning(disable:4715) // avoid warning c4715: 'process_request' : not all control paths return a value
80+
#endif
7581

7682
[[noreturn]] static void *process_request(void *data) {
7783
struct data_ms *a = (struct data_ms *)data;
@@ -85,7 +91,7 @@ struct data_ms {
8591
modsecTransaction->processConnection(ip, 12345, "127.0.0.1", 80);
8692
modsecTransaction->processURI(request_uri, "GET", "1.1");
8793

88-
usleep(10);
94+
std::this_thread::sleep_for(std::chrono::microseconds(10));
8995
modsecTransaction->addRequestHeader("Host",
9096
"net.tutsplus.com");
9197
modsecTransaction->processRequestHeaders();
@@ -105,6 +111,9 @@ struct data_ms {
105111
pthread_exit(nullptr);
106112
}
107113

114+
#if defined _MSC_VER
115+
#pragma warning(pop)
116+
#endif
108117

109118
class ReadingLogsViaRuleMessage {
110119
public:
@@ -151,7 +160,7 @@ class ReadingLogsViaRuleMessage {
151160
reinterpret_cast<void *>(&dms));
152161
}
153162

154-
usleep(10000);
163+
std::this_thread::sleep_for(std::chrono::microseconds(10000));
155164

156165
for (i=0; i < NUM_THREADS; i++) {
157166
pthread_join(threads[i], &status);

0 commit comments

Comments
 (0)