more error handling sync
authorVolker Birk <vb@pep.foundation>
Sun, 21 Oct 2018 17:54:01 +0200
branchsync
changeset 308995d63a8d69bf
parent 3087 f4a714769872
child 3090 8adef1192b4e
more error handling
src/fsm_common.h
src/message_api.c
src/pEpEngine.h
sync/gen_statemachine.ysl2
     1.1 --- a/src/fsm_common.h	Sun Oct 21 17:10:03 2018 +0200
     1.2 +++ b/src/fsm_common.h	Sun Oct 21 17:54:01 2018 +0200
     1.3 @@ -3,7 +3,7 @@
     1.4  
     1.5  // generate state machine code
     1.6  
     1.7 -// Copyleft (c) 2017, p≡p foundation
     1.8 +// Copyleft (c) 2017-2018, pEp foundation
     1.9  
    1.10  // Written by Volker Birk
    1.11  
    1.12 @@ -23,9 +23,11 @@
    1.13      invalid_event = -3,
    1.14      invalid_condition = -4,
    1.15      invalid_action = -5,
    1.16 +    inhibited_event = -6,
    1.17 +    cannot_send = -7,
    1.18  
    1.19      // out of memory condition
    1.20 -    invalid_out_of_memory = -128,
    1.21 +    out_of_memory = -128,
    1.22  } fsm_error;
    1.23  
    1.24  // common
     2.1 --- a/src/message_api.c	Sun Oct 21 17:10:03 2018 +0200
     2.2 +++ b/src/message_api.c	Sun Oct 21 17:54:01 2018 +0200
     2.3 @@ -471,9 +471,8 @@
     2.4      
     2.5      i = DESIRED_BITS;
     2.6      
     2.7 -    int bitshift = 0;
     2.8 -    
     2.9      while (i > 0) {
    2.10 +        int bitshift = 0;
    2.11          int randval = rand();
    2.12          unsigned long long temp_val = randval & bitmask;
    2.13  
     3.1 --- a/src/pEpEngine.h	Sun Oct 21 17:10:03 2018 +0200
     3.2 +++ b/src/pEpEngine.h	Sun Oct 21 17:54:01 2018 +0200
     3.3 @@ -108,6 +108,7 @@
     3.4      PEP_STATEMACHINE_INVALID_CONDITION              = 0x0984,
     3.5      PEP_STATEMACHINE_INVALID_ACTION                 = 0x0985,
     3.6      PEP_STATEMACHINE_INHIBITED_EVENT                = 0x0986,
     3.7 +    PEP_STATEMACHINE_CANNOT_SEND                    = 0x0987,
     3.8  
     3.9      PEP_COMMIT_FAILED                               = 0xff01,
    3.10      PEP_MESSAGE_CONSUME                             = 0xff02,
     4.1 --- a/sync/gen_statemachine.ysl2	Sun Oct 21 17:10:03 2018 +0200
     4.2 +++ b/sync/gen_statemachine.ysl2	Sun Oct 21 17:54:01 2018 +0200
     4.3 @@ -920,6 +920,12 @@
     4.4  
     4.5          «$fsm/@name»_SERVICE_LOG("send message", "«@name»");
     4.6          status = send_«$protocol/@name»_message(session, «$fsm/@id», «$fsm/@name»__payload_PR_«yml:mixedCase(@name)»);
     4.7 +        if (status == PEP_OUT_OF_MEMORY)
     4.8 +            return out_of_memory;
     4.9 +        if (status) {
    4.10 +            «$fsm/@name»_ERR_LOG_HEX("sending «@name» failed", status);
    4.11 +            return cannot_send;
    4.12 +        }
    4.13          ||
    4.14      }
    4.15  
    4.16 @@ -929,6 +935,8 @@
    4.17  
    4.18          «$fsm/@name»_SERVICE_LOG("do action", "«@name»");
    4.19          status = «@name»(session);
    4.20 +        if (status == PEP_OUT_OF_MEMORY)
    4.21 +            return out_of_memory;
    4.22          if (status) {
    4.23              «$fsm/@name»_ERR_LOG_HEX("executing action «@name»() failed", status);
    4.24              return invalid_action;
    4.25 @@ -941,6 +949,8 @@
    4.26          ||
    4.27  
    4.28          status = «@name»(session, &result);
    4.29 +        if (status == PEP_OUT_OF_MEMORY)
    4.30 +            return out_of_memory;
    4.31          if (status) {
    4.32              «$fsm/@name»_ERR_LOG_HEX("computing condition «@name» failed", status);
    4.33              return invalid_condition;