Skip to content

Commit

Permalink
Add send/receive sanity checks
Browse files Browse the repository at this point in the history
  • Loading branch information
lundmar committed Mar 10, 2018
1 parent c2b476c commit b5dd325
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/lxi.c
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,12 @@ EXPORT int lxi_send(int device, char *message, int length, int timeout)
{
int bytes_sent;

if (device < 0)
return LXI_ERROR;

if (session[device].connected == false)
return LXI_ERROR;

// Send
bytes_sent = session[device].send(session[device].data, message, length, timeout);
if (bytes_sent < 0)
Expand All @@ -169,6 +175,12 @@ EXPORT int lxi_receive(int device, char *message, int length, int timeout)
{
int bytes_received;

if (device < 0)
return LXI_ERROR;

if (session[device].connected == false)
return LXI_ERROR;

// Receive
bytes_received = session[device].receive(session[device].data, message, length, timeout);
if (bytes_received < 0)
Expand Down

0 comments on commit b5dd325

Please sign in to comment.