Skip to content

Commit

Permalink
Close port on any error inside xcic_scom_port_exchange
Browse files Browse the repository at this point in the history
  • Loading branch information
darkwrat committed Aug 30, 2020
1 parent c733561 commit 685e32b
Showing 1 changed file with 12 additions and 15 deletions.
27 changes: 12 additions & 15 deletions xcic.c
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ int xcic_scom_read_property(lua_State *L, struct xcic_port *xp,
return 0;

except:
return -1; // caller must invoke `lua_error
return -1; // caller must invoke `lua_error`
}

int xcic_port_write_parameter_property(lua_State *L)
Expand Down Expand Up @@ -394,7 +394,7 @@ int xcic_scom_write_property(lua_State *L, struct xcic_port *xp,
return 0;

except:
return -1; // caller must invoke `lua_error
return -1; // caller must invoke `lua_error`
}

int xcic_port_read_message(lua_State *L)
Expand Down Expand Up @@ -457,10 +457,8 @@ int xcic_scom_port_exchange(lua_State *L, struct xcic_port *xp,

ibuf_reset(ibuf);

if (!ibuf_alloc(ibuf, SCOM_FRAME_HEADER_SIZE)) {
xcic_intl_port_close(xp);
if (!ibuf_alloc(ibuf, SCOM_FRAME_HEADER_SIZE))
xcic_lua_except(L, "alloc failed");
}

scom_initialize_frame(frame, ibuf->rpos, ibuf_used(ibuf));

Expand All @@ -474,10 +472,8 @@ int xcic_scom_port_exchange(lua_State *L, struct xcic_port *xp,
* empty */
ssize_t rlen = scom_read_le16(&frame->buffer[10]) + 2;

if (!ibuf_alloc(ibuf, rlen)) {
xcic_intl_port_close(xp);
if (!ibuf_alloc(ibuf, rlen))
xcic_lua_except(L, "alloc failed");
}

frame->buffer = ibuf->rpos;
frame->buffer_size = ibuf_used(ibuf);
Expand All @@ -501,6 +497,7 @@ int xcic_scom_port_exchange(lua_State *L, struct xcic_port *xp,
return 0;

except:
xcic_intl_port_close(xp);
box_latch_unlock(xp->latch);

return -1; // caller must invoke `lua_error`
Expand Down Expand Up @@ -558,7 +555,7 @@ int xcic_scom_encode_read_property(lua_State *L, struct ibuf *ibuf,
return 0;

except:
return -1; // caller must invoke `lua_error
return -1; // caller must invoke `lua_error`
}

int xcic_scom_encode_write_property(lua_State *L, struct ibuf *ibuf,
Expand Down Expand Up @@ -588,7 +585,7 @@ int xcic_scom_encode_write_property(lua_State *L, struct ibuf *ibuf,
return 0;

except:
return -1; // caller must invoke `lua_error
return -1; // caller must invoke `lua_error`
}

int xcic_scom_encode_request_frame(lua_State *L, struct ibuf *ibuf,
Expand All @@ -610,7 +607,7 @@ int xcic_scom_encode_request_frame(lua_State *L, struct ibuf *ibuf,
return 0;

except:
return -1; // caller must invoke `lua_error
return -1; // caller must invoke `lua_error`
}

int xcic_scom_decode_frame_header(lua_State *L, scom_frame_t *frame)
Expand All @@ -625,7 +622,7 @@ int xcic_scom_decode_frame_header(lua_State *L, scom_frame_t *frame)
return 0;

except:
return -1; // caller must invoke `lua_error
return -1; // caller must invoke `lua_error`
}

int xcic_scom_decode_frame_data(lua_State *L, scom_frame_t *frame)
Expand All @@ -640,7 +637,7 @@ int xcic_scom_decode_frame_data(lua_State *L, scom_frame_t *frame)
return 0;

except:
return -1; // caller must invoke `lua_error
return -1; // caller must invoke `lua_error`
}

int xcic_scom_decode_read_property(lua_State *L, scom_property_t *property)
Expand All @@ -656,7 +653,7 @@ int xcic_scom_decode_read_property(lua_State *L, scom_property_t *property)
return 0;

except:
return -1; // caller must invoke `lua_error
return -1; // caller must invoke `lua_error`
}

int xcic_scom_decode_write_property(lua_State *L, scom_property_t *property)
Expand All @@ -672,7 +669,7 @@ int xcic_scom_decode_write_property(lua_State *L, scom_property_t *property)
return 0;

except:
return -1; // caller must invoke `lua_error
return -1; // caller must invoke `lua_error`
}

char *xcic_scom_strerror(scom_error_t error)
Expand Down

0 comments on commit 685e32b

Please sign in to comment.