diff --git a/main.cpp b/main.cpp index ced744d..f6d0895 100644 --- a/main.cpp +++ b/main.cpp @@ -94,7 +94,7 @@ int main(int argc, char *argv[]) MKLOGSTMT(LOG_INFO, fprintf(stderr, "%s %s %s %s %s %s %s %s\n", me, shm_name, shm_size_str, cmd_slot_str, res_slot_str, evt_slot_str, alive_slot_str, alive_ack_slot_str)); - MKLOGSTMT(LOG_INFO, fprintf(stderr, "%s %s %lld %d %d %d %d %d\n", me, shm_name, shm_size, + MKLOGSTMT(LOG_INFO, fprintf(stderr, "%s %s %d %d %d %d %d %d\n", me, shm_name, static_cast(shm_size), cmd_slot, res_slot, evt_slot, alive_slot, alive_ack_slot)); if (!(shm_size > 0 && cmd_slot > 0 && res_slot > 0 && evt_slot > 0 && alive_slot > 0 && alive_ack_slot > 0)) { diff --git a/rktwebview.cpp b/rktwebview.cpp index 114a917..6621dec 100644 --- a/rktwebview.cpp +++ b/rktwebview.cpp @@ -165,7 +165,10 @@ bool runRktWebview(Handle_t *handler) } return r; #else - char *argv[] = { rkt_webview_prg_path, const_cast(handler->name.c_str()), shm_size_str, command_slot, command_result_slot, event_slot, nullptr }; + char *argv[] = { rkt_webview_prg_path, const_cast(handler->name.c_str()), shm_size_str, + command_slot, command_result_slot, event_slot, + alive_slot, alive_ack_slot, + nullptr }; struct passwd *pw = getpwuid(getuid()); const char *homedir = pw->pw_dir; diff --git a/rktwebview_test.cpp b/rktwebview_test.cpp index ff7e2c5..1e08b31 100644 --- a/rktwebview_test.cpp +++ b/rktwebview_test.cpp @@ -62,7 +62,8 @@ int main(int argc, char *argv[]) #ifdef _WIN32 Sleep(30000); #else - sleep(10); + sleep(30 + ); #endif d = rkt_webview_info(); rkt_webview_free_data(d); diff --git a/shm.cpp b/shm.cpp index 7ca975b..9c8642e 100644 --- a/shm.cpp +++ b/shm.cpp @@ -256,6 +256,8 @@ public: #include #include #include +#include +#include class ShmApi : public ShmApiBase @@ -338,22 +340,41 @@ public: } }; +#define TIME_NS_IN_MSEC 1000000ULL + class ShmSemApi { private: sem_t *_sem; char *_name; bool _owner; + private: + void makeSemTimeoutTime(struct timespec *ts, int ms) { + clock_gettime(CLOCK_REALTIME, ts); + ts->tv_sec += ms / 1000; + ts->tv_nsec += (ms % 1000) * TIME_NS_IN_MSEC; + if (ts->tv_nsec >= 1000000000L) { + ts->tv_sec++; + ts->tv_nsec = ts->tv_nsec - 1000000000L; + } + } + public: void post() { sem_post(_sem); } - void wait() { - int r = sem_wait(_sem); + bool wait(int ms) { + struct timespec ts; + makeSemTimeoutTime(&ts, ms); + int r = sem_timedwait(_sem, &ts); if (r != 0) { - ERROR2("sem_wait error: %d, %s\n", errno, strerror(errno)); + if (errno != ETIMEDOUT) { + ERROR2("sem_wait error: %d, %s\n", errno, strerror(errno)); + } + return false; } + return true; } bool trywait() { @@ -365,6 +386,11 @@ class ShmSemApi { return (r == 0); } + public: + void takeOwnership() { + _owner = true; + } + public: ShmSemApi(const char *n, bool owner) { _name = strdup(n);