diff options
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; + } +} |