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

Merge branch '29-task-descriptors-are-never-released' into 'master'

Resolve "Task descriptors are never released"

Closes #29

See merge request !13
parents db83cc35 e14e29a6
Loading
Loading
Loading
Loading
Loading
+5 −4
Original line number Diff line number Diff line
@@ -73,10 +73,11 @@ extern "C" {
#define NORNS_ETASKSPENDING      -43

/* task status */
#define NORNS_EPENDING          -100
#define NORNS_EINPROGRESS       -101
#define NORNS_EFINISHED         -102
#define NORNS_EFINISHEDWERROR   -103
#define NORNS_EUNDEFINED        -100
#define NORNS_EPENDING          -101
#define NORNS_EINPROGRESS       -102
#define NORNS_EFINISHED         -103
#define NORNS_EFINISHEDWERROR   -104

/* errors resources */
#define NORNS_ERESOURCEEXISTS   -110
+9 −8
Original line number Diff line number Diff line
@@ -123,14 +123,6 @@ typedef enum {
    NORNS_IOTASK_REMOVE = 0x3
} norns_op_t;

/* Descriptor for an I/O task */
typedef struct {
    norns_tid_t         t_id;   /* task identifier */
    norns_op_t          t_op;   /* operation to be performed */
    norns_resource_t    t_src;  /* source resource */
    norns_resource_t    t_dst;  /* destination resource */
} norns_iotask_t;

/* I/O task status descriptor */
typedef struct {
    norns_status_t st_status;     /* task current status */
@@ -140,7 +132,16 @@ typedef struct {
    size_t         st_total;      /* total bytes in task */
} norns_stat_t;

/* Descriptor for an I/O task */
typedef struct {
    norns_tid_t         t_id;   /* task identifier */
    norns_op_t          t_op;   /* operation to be performed */
    norns_resource_t    t_src;  /* source resource */
    norns_resource_t    t_dst;  /* destination resource */

    /* Internal members */
    norns_stat_t        __t_status; /* cached task status */
} norns_iotask_t;

/* Additional administrative types */
typedef enum {
+12 −0
Original line number Diff line number Diff line
@@ -215,6 +215,14 @@ norns_error(norns_iotask_t* task, norns_stat_t* stats) {
        return NORNS_EBADARGS;
    }

    // we might already have the task status cached in the task descriptor if
    // the user called norns_wait() and the task completed
    if(task->__t_status.st_status == NORNS_EFINISHED ||
       task->__t_status.st_status == NORNS_EFINISHEDWERROR) {
        *stats = task->__t_status;
        return NORNS_SUCCESS;
    }

    return send_status_request(task, stats);
}

@@ -251,6 +259,10 @@ norns_wait(norns_iotask_t* task,

        if(stats.st_status == NORNS_EFINISHED || 
           stats.st_status == NORNS_EFINISHEDWERROR) {
            // given that the task finished, we can save its completion status 
            // so that future calls to norns_error() can retrieve it without
            // having to contact the server
            task->__t_status = stats;
            return NORNS_SUCCESS;
        }

+12 −0
Original line number Diff line number Diff line
@@ -402,6 +402,14 @@ nornsctl_error(norns_iotask_t* task,
        return NORNS_EBADARGS;
    }

    // we might already have the task status cached in the task descriptor if
    // the user called norns_wait() and the task completed
    if(task->__t_status.st_status == NORNS_EFINISHED ||
       task->__t_status.st_status == NORNS_EFINISHEDWERROR) {
        *stats = task->__t_status;
        return NORNS_SUCCESS;
    }

    return send_status_request(task, stats);
}

@@ -437,6 +445,10 @@ nornsctl_wait(norns_iotask_t* task,

        if(stats.st_status == NORNS_EFINISHED || 
           stats.st_status == NORNS_EFINISHEDWERROR) {
            // given that the task finished, we can save its completion status 
            // so that future calls to nornsctl_error() can retrieve it without
            // having to contact the server
            task->__t_status = stats;
            return NORNS_SUCCESS;
        }

+2 −0
Original line number Diff line number Diff line
@@ -75,6 +75,8 @@ norns::rpc::Response_Type encode(norns::api::response_type type) {
    using norns::io::task_status;

    switch(status) {
        case task_status::undefined:
            return NORNS_EUNDEFINED;
        case task_status::pending:
            return NORNS_EPENDING;
        case task_status::running:
Loading