Skip to content
Snippets Groups Projects

[io.hpp] add blocking functions using timeouts

Merged Florian Fischer requested to merge aj46ezos/emper:add_more_timeouts into master
3 files
+ 240
0
Compare changes
  • Side-by-side
  • Inline
Files
3
+ 99
0
@@ -65,6 +65,28 @@ inline auto recvAndWait(int socket, void *buffer, size_t length, int flags) -> s
@@ -65,6 +65,28 @@ inline auto recvAndWait(int socket, void *buffer, size_t length, int flags) -> s
return future.waitAndSetErrno();
return future.waitAndSetErrno();
}
}
 
/**
 
* @brief Blocking recv mimicking POSIX recv(3) with timeout
 
*
 
* This method must be called from inside the emper runtime because it uses
 
* the worker-local IoContext
 
*
 
* @param socket file descriptor for this operation
 
* @param buffer destination buffer
 
* @param length length of the message in bytes
 
* @param flags type of message reception
 
* @param ts Time to wait before aborting the request
 
 
* @return -1 on error, 0 when receiving from a closed socket, otherwise the received bytes
 
*/
 
inline auto recvAndTryWait(int socket, void *buffer, size_t length, int flags,
 
TimeoutWrapper::Timespec &ts) -> ssize_t {
 
RecvFuture future(socket, buffer, length, flags);
 
TimeoutWrapper wrapper(future, ts);
 
wrapper.submitAndWait();
 
return future.waitAndSetErrno();
 
}
 
/**
/**
* @brief Non-blocking send mimicking POSIX send(3)
* @brief Non-blocking send mimicking POSIX send(3)
*
*
@@ -110,6 +132,31 @@ inline auto sendAndWait(int socket, const void *buffer, size_t length, int flags
@@ -110,6 +132,31 @@ inline auto sendAndWait(int socket, const void *buffer, size_t length, int flags
return future.waitAndSetErrno();
return future.waitAndSetErrno();
}
}
 
/**
 
* @brief Blocking send mimicking POSIX send(3) with timeout
 
*
 
* This method must be called from inside the emper runtime because it uses
 
* the worker-local IoContext
 
*
 
* @param socket file descriptor for this operation
 
* @param buffer source buffer
 
* @param length length of the message in bytes
 
* @param flags type of message transmission
 
* @param ts Time to wait before aborting the request
 
* @param send_all If true return to the user only if all bytes are sent or
 
* sending further bytes is not possible
 
*
 
* @return -1 on error, otherwise the number of sent bytes
 
*/
 
inline auto sendAndTryWait(int socket, const void *buffer, size_t length, int flags,
 
TimeoutWrapper::Timespec &ts, bool send_all = true) -> ssize_t {
 
void *mut_buf = const_cast<void *>(buffer);
 
SendFuture future(socket, mut_buf, length, flags, send_all);
 
TimeoutWrapper wrapper(future, ts);
 
wrapper.submitAndWait();
 
return future.waitAndSetErrno();
 
}
 
/**
/**
* @brief Non-blocking connect mimicking POSIX connect(3)
* @brief Non-blocking connect mimicking POSIX connect(3)
*
*
@@ -253,6 +300,30 @@ inline auto readFileAndWait(int fildes, void *buf, size_t nbyte, off_t offset =
@@ -253,6 +300,30 @@ inline auto readFileAndWait(int fildes, void *buf, size_t nbyte, off_t offset =
return future.waitAndSetErrno();
return future.waitAndSetErrno();
}
}
 
/**
 
* @brief Blocking read for regular files mimicking POSIX recv(3) with timeout
 
*
 
* This method must be called from inside the emper runtime because it uses
 
* the worker-local IoContext
 
*
 
* @param fildes file descriptor to the regular file to be written to
 
* @param buf destination buffer
 
* @param nbyte amount of bytes to read
 
* @param offset offset in the file
 
* @param ts Time to wait before aborting the request
 
* @param read_all If true return only to the user if the buffer is completely
 
* filled or no further data can be read.
 
*
 
* @return -1 on error, 0 when receiving from a closed socket, otherwise the received bytes
 
*/
 
inline auto readFileAndTryWait(int fildes, void *buf, size_t nbyte, TimeoutWrapper::Timespec &ts,
 
off_t offset = -1, bool read_all = false) -> ssize_t {
 
ReadFuture future(fildes, buf, nbyte, offset, read_all);
 
TimeoutWrapper wrapper(future, ts);
 
wrapper.submitAndWait();
 
return future.waitAndSetErrno();
 
}
 
/**
/**
* @brief Non-blocking write for regular files mimicking POSIX write(3)
* @brief Non-blocking write for regular files mimicking POSIX write(3)
*
*
@@ -303,6 +374,34 @@ inline auto writeFileAndWait(int fildes, const void *buf, size_t nbyte, off_t of
@@ -303,6 +374,34 @@ inline auto writeFileAndWait(int fildes, const void *buf, size_t nbyte, off_t of
return future.waitAndSetErrno();
return future.waitAndSetErrno();
}
}
 
/**
 
* @brief Blocking write for regular files mimicking POSIX write(3) with timeout
 
*
 
* Currently only writing to regular files is tested and supported.
 
* Writing to other file types could work but may result in undefined behavior.
 
*
 
* This method must be called from inside the emper runtime because it uses
 
* the worker-local IoContext
 
*
 
* @param fildes file descriptor to the regular file to be written to
 
* @param buf source buffer
 
* @param nbyte amount of bytes to write
 
* @param ts Time to wait before aborting the request
 
* @param offset offset in the file
 
* @param write_all If true return only to the user if all nbyte were written
 
* or no further data can be written.
 
*
 
* @return -1 on error, otherwise the number of bytes written
 
*/
 
inline auto writeFileAndTryWait(int fildes, const void *buf, size_t nbyte,
 
TimeoutWrapper::Timespec &ts, off_t offset = -1,
 
bool write_all = true) -> ssize_t {
 
WriteFuture future(fildes, buf, nbyte, offset, write_all);
 
TimeoutWrapper wrapper(future, ts);
 
wrapper.submitAndWait();
 
return future.waitAndSetErrno();
 
}
 
/**
/**
* @brief Non-blocking writev mimicking POSIX writev(3)
* @brief Non-blocking writev mimicking POSIX writev(3)
*
*
Loading