diff options
author | Alexander Mohr <alexander.m.mohr@mercedes-benz.com> | 2023-05-17 08:43:33 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-05-17 08:43:33 +0200 |
commit | 6005b92b34b3e3ffe43c59be544acd4688a3354c (patch) | |
tree | 29eb0bb87296c3f2b5fc82025ce326630a4eb25a /src/shared/dlt_user_shared.c | |
parent | cfc2c86bfec130fb8a95ff0c2553d5c1dd1bd3c1 (diff) | |
download | DLT-daemon-6005b92b34b3e3ffe43c59be544acd4688a3354c.tar.gz |
dlt_user_shared: Add timeout to writev (#385)
This timeout is necessary to prevent
blocking writev indefinitely.
Without the timeout dlt-daemon, may block
indefinitely when an app id is re-used
very frequently.
In that case dlt-daemon won't accept anymore
new connections and further communication
in any way is not possible anymore.
Signed-off-by: Alexander Mohr <alexander.m.mohr@mercedes-benz.com>
Diffstat (limited to 'src/shared/dlt_user_shared.c')
-rw-r--r-- | src/shared/dlt_user_shared.c | 47 |
1 files changed, 46 insertions, 1 deletions
diff --git a/src/shared/dlt_user_shared.c b/src/shared/dlt_user_shared.c index 90b2623..c6bc496 100644 --- a/src/shared/dlt_user_shared.c +++ b/src/shared/dlt_user_shared.c @@ -71,6 +71,7 @@ #include <errno.h> #include <sys/uio.h> /* writev() */ +#include <sys/time.h> /* timeval */ #include "dlt_user_shared.h" #include "dlt_user_shared_cfg.h" @@ -125,6 +126,28 @@ DltReturnValue dlt_user_log_out2(int handle, void *ptr1, size_t len1, void *ptr2 return DLT_RETURN_OK; } +DltReturnValue dlt_user_log_out2_with_timeout(int handle, void *ptr1, size_t len1, void *ptr2, size_t len2) +{ + if (handle < 0) + /* Invalid handle */ + return DLT_RETURN_ERROR; + + fd_set fds; + FD_ZERO(&fds); + FD_SET(handle, &fds); + + struct timeval tv = { DLT_WRITEV_TIMEOUT_SEC, DLT_WRITEV_TIMEOUT_USEC }; + if (select(handle+1, NULL, &fds, NULL, &tv) < 0) { + return DLT_RETURN_ERROR; + } + + if (FD_ISSET(handle, &fds)) { + return dlt_user_log_out2(handle, ptr1, len1, ptr2, len2); + } else { + return DLT_RETURN_ERROR; + } +} + DltReturnValue dlt_user_log_out3(int handle, void *ptr1, size_t len1, void *ptr2, size_t len2, void *ptr3, size_t len3) { struct iovec iov[3]; @@ -175,4 +198,26 @@ DltReturnValue dlt_user_log_out3(int handle, void *ptr1, size_t len1, void *ptr2 } return DLT_RETURN_OK; -}
\ No newline at end of file +} + +DltReturnValue dlt_user_log_out3_with_timeout(int handle, void *ptr1, size_t len1, void *ptr2, size_t len2, void *ptr3, size_t len3) +{ + if (handle < 0) + /* Invalid handle */ + return DLT_RETURN_ERROR; + + fd_set fds; + FD_ZERO(&fds); + FD_SET(handle, &fds); + + struct timeval tv = { DLT_WRITEV_TIMEOUT_SEC, DLT_WRITEV_TIMEOUT_USEC }; + if (select(handle+1, NULL, &fds, NULL, &tv) < 0) { + return DLT_RETURN_ERROR; + } + + if (FD_ISSET(handle, &fds)) { + return dlt_user_log_out3(handle, ptr1, len1, ptr2, len2, ptr3, len3); + } else { + return DLT_RETURN_ERROR; + } +} |