Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 30 additions & 14 deletions utils/gnl.hpp
Original file line number Diff line number Diff line change
@@ -1,22 +1,38 @@
#ifndef GNL_HPP
# define GNL_HPP
# include "leaks.hpp"
#include <chrono>

using namespace std::chrono;

//Don't do that at home
#define TEST(x) { \
int status = 0; \
int test = fork();\
if (test == 0) { \
x \
showLeaks(); \
exit(EXIT_SUCCESS); \
} else { \
usleep(TIMEOUT_US); \
if (waitpid(test, &status, WNOHANG) == 0) { \
kill(test, 9); \
cout << FG_RED << "TIMEOUT";\
} \
} \
#define USLEEP_TERM 100
#define TEST(x) {\
int status = 0; \
int test = fork(); \
if (test == 0) \
{\
x \
showLeaks(); \
exit(EXIT_SUCCESS);\
} \
else \
{\
auto a = high_resolution_clock::now(); \
auto b = high_resolution_clock::now(); \
while(duration_cast<microseconds>(b - a).count() < TIMEOUT_US)\
{ \
usleep(USLEEP_TERM); \
if (waitpid(test, &status, WNOHANG) != 0)\
break;\
b = high_resolution_clock::now(); \
} \
if (waitpid(test, &status, WNOHANG) == 0) \
{ \
kill(test, 9); \
cout << FG_RED << "TIMEOUT"; \
}\
}\
}

void gnl(int fd, char const * s);
Expand Down