Skip to content
This repository has been archived by the owner on May 16, 2019. It is now read-only.

Waitforack needsfree issues fix #26

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ struct xbee_buf {
struct xbee_sbuf {
xsys_sem sem;
size_t len;
int waitForAck;
unsigned char data[1];
};

Expand Down
26 changes: 12 additions & 14 deletions tx.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>

#include "internal.h"
#include "tx.h"
Expand Down Expand Up @@ -103,13 +104,12 @@ xbee_err xbee_tx(struct xbee *xbee, int *restart, void *arg) {

if ((ret = info->ioFunc(xbee, info->ioArg, buf)) != XBEE_ENONE) {
xbee_log(1, "tx() returned %d... buffer was lost", ret);
continue;
}

if (xbee_ll_ext_item(needsFree, buf) == XBEE_ENONE) {
free(buf);
if (buf->waitForAck) {
xsys_sem_post(&buf->sem);
} else {
xsys_sem_post(&buf->sem);
free(buf);
}
}

Expand Down Expand Up @@ -144,6 +144,8 @@ xbee_err xbee_txHandler(struct xbee_con *con, const unsigned char *buf, int len,

if (!oBuf) return XBEE_EUNKNOWN;

oBuf->waitForAck = waitForAck;

if (waitForAck) xsys_sem_init(&oBuf->sem);

con->info.countTx++;
Expand All @@ -161,18 +163,14 @@ xbee_err xbee_txHandler(struct xbee_con *con, const unsigned char *buf, int len,
see xbee_tx() - this helps to keep the timeout value correct */
ret = xsys_sem_wait(&oBuf->sem);

/* perform this atomically */
xbee_ll_lock(needsFree);
xsys_sem_destroy(&oBuf->sem);
if (ret != 0) {
xbee_log(25, "[%p] Unable to wait for transfer to occur... The conType timeout may not be sufficient.", con);
_xbee_ll_add_tail(needsFree, oBuf, 0);
} else {
free(oBuf);
xbee_log(25, "[%p] Wait for transfer to occur returned with errno %d... The conType timeout may not be sufficient.", con, errno);
}
xbee_ll_unlock(needsFree);
} else {
xbee_ll_add_tail(needsFree, oBuf);

xsys_sem_destroy(&oBuf->sem);

free(oBuf);

}

return XBEE_ENONE;
Expand Down