Add option to handle pbufs instead of buffers

This commit is contained in:
me-no-dev
2018-01-27 12:30:24 +01:00
parent 4dbbf10609
commit 75e2b15377
2 changed files with 35 additions and 10 deletions
+26 -7
View File
@@ -352,6 +352,8 @@ AsyncClient::AsyncClient(tcp_pcb* pcb)
, _error_cb_arg(0)
, _recv_cb(0)
, _recv_cb_arg(0)
, _pb_cb(0)
, _pb_cb_arg(0)
, _timeout_cb(0)
, _timeout_cb_arg(0)
, _pcb_busy(false)
@@ -504,15 +506,19 @@ int8_t AsyncClient::_recv(tcp_pcb* pcb, pbuf* pb, int8_t err) {
//Serial.write((const uint8_t *)pb->payload, pb->len);
_ack_pcb = true;
pbuf *b = pb;
if(_recv_cb)
_recv_cb(_recv_cb_arg, this, b->payload, b->len);
if(!_ack_pcb)
_rx_ack_len += b->len;
else
_tcp_recved(pcb, b->len);
pb = b->next;
b->next = NULL;
pbuf_free(b);
if(_pb_cb){
_pb_cb(_pb_cb_arg, this, b);
} else {
if(_recv_cb)
_recv_cb(_recv_cb_arg, this, b->payload, b->len);
if(!_ack_pcb)
_rx_ack_len += b->len;
else
_tcp_recved(pcb, b->len);
pbuf_free(b);
}
}
return ERR_OK;
}
@@ -814,6 +820,14 @@ bool AsyncClient::canSend(){
return space() > 0;
}
void AsyncClient::ackPacket(struct pbuf * pb){
if(!pb){
return;
}
_tcp_recved(_pcb, pb->len);
pbuf_free(pb);
}
// Callback Setters
@@ -842,6 +856,11 @@ void AsyncClient::onData(AcDataHandler cb, void* arg){
_recv_cb_arg = arg;
}
void AsyncClient::onPacket(AcPacketHandler cb, void* arg){
_pb_cb = cb;
_pb_cb_arg = arg;
}
void AsyncClient::onTimeout(AcTimeoutHandler cb, void* arg){
_timeout_cb = cb;
_timeout_cb_arg = arg;