Commit c484573c authored by Alberto Miranda's avatar Alberto Miranda ♨️
Browse files

Add timeout parameter to waiting functions

Functions norns_wait() and nornsctl_wait() now accept an optional
const struct timespec *timeout (see nanosleep(2)) to allow users
to suspend the calling thread until one of the following occurs:

* A signal is delivered and the task has already completed.
* The specified time interval has already passed.

If timeout is NULL, the functions will suspend the thread for
a predefined amount of time and query the server upon waking up.

Note that since the server does not allow registering listeners at the
moment, the thread will wake only when one of the aforementioned
conditions has occurred, even if the task of interest has already finished.
parent 8fe820ad
Loading
Loading
Loading
Loading
+5 −4
Original line number Diff line number Diff line
@@ -32,9 +32,9 @@
#define NORNS_API_VERSION 10
#endif

#include <sys/types.h>
#include <stdint.h>
#include <assert.h>
#include <stdint.h>     /* For uint32_t et al. */
#include <stdbool.h>    /* For bool */
#include <time.h>       /* For struct timespec */

#include "norns_types.h"
#include "norns_error.h"
@@ -68,7 +68,8 @@ norns_submit(norns_iotask_t* task) __THROW;

/* wait for the completion of the I/O task associated to 'task' */
norns_error_t 
norns_wait(norns_iotask_t* task) __THROW;
norns_wait(norns_iotask_t* task,
           const struct timespec* timeout) __THROW;

/* Try to cancel an asynchronous I/O task associated with task */
norns_error_t 
+5 −4
Original line number Diff line number Diff line
@@ -45,12 +45,13 @@ extern "C" {
#define NORNS_EBADARGS            -2
#define NORNS_EBADREQUEST         -3
#define NORNS_ENOMEM              -4
#define NORNS_ETIMEOUT            -5

/* errors about communication */
#define NORNS_ECONNFAILED         -5
#define NORNS_ERPCSENDFAILED      -6
#define NORNS_ERPCRECVFAILED      -7
#define NORNS_EACCEPTPAUSED       -8
#define NORNS_ECONNFAILED         -6
#define NORNS_ERPCSENDFAILED      -7
#define NORNS_ERPCRECVFAILED      -8
#define NORNS_EACCEPTPAUSED       -9

/* errors about jobs */
#define NORNS_EJOBEXISTS         -10
+0 −2
Original line number Diff line number Diff line
@@ -29,8 +29,6 @@
#define __NORNS_TYPES_H__ 1

#include <sys/types.h>
#include <stdint.h>     /* For uint32_t et al. */
#include <stdbool.h>

#ifdef __cplusplus
extern "C" {
+6 −1
Original line number Diff line number Diff line
@@ -32,6 +32,10 @@
#define NORNSCTL_API_VERSION 10
#endif

#include <stdint.h>     /* For uint32_t et al. */
#include <stdbool.h>    /* For bool */
#include <time.h>       /* For struct timespec */

#include "norns_types.h"
#include "norns_error.h"

@@ -191,7 +195,8 @@ nornsctl_submit(norns_iotask_t* task) __THROW;

/* wait for the completion of the I/O task associated to 'task' */
norns_error_t 
nornsctl_wait(norns_iotask_t* task) __THROW;
nornsctl_wait(norns_iotask_t* task,
              const struct timespec* timeout) __THROW;

/* Try to cancel an asynchronous I/O task associated with task */
norns_error_t 
+1 −0
Original line number Diff line number Diff line
@@ -35,6 +35,7 @@ const char* const norns_errlist[NORNS_ERRMAX + 1] = {
    [ERR_REMAP(NORNS_EBADREQUEST)] = "Bad request",
    [ERR_REMAP(NORNS_EBADARGS)] = "Bad arguments",
    [ERR_REMAP(NORNS_ENOMEM)] = "Cannot allocate memory",
    [ERR_REMAP(NORNS_ETIMEOUT)] = "Timeout exceeded",

    /* communication errors */
    [ERR_REMAP(NORNS_ECONNFAILED)] = "Cannot connect to daemon",
Loading