int32_t AsyncClient::_recv(tcp_pcb* pcb, pbuf* pb, int8_t err) {
  if(pb == 0){
    //os_printf("pb-null\n");
    return _close();
  }

  _rx_last_packet = millis();
    //use callback (onData defined)
    while(pb != NULL){
      if(pb->next == NULL){
        if(_recv_cb)
          _recv_cb(_recv_cb_arg, this, pb->payload, pb->len);
        tcp_recved(pcb, pb->len);
        pbuf_free(pb);
        pb = NULL;
      } else {
        pbuf *b = pb;
        pb = pbuf_dechain(b);
        if(_recv_cb)
          _recv_cb(_recv_cb_arg, this, b->payload, b->len);
        tcp_recved(pcb, b->len);
        pbuf_free(b);
      }
    }
  return ERR_OK;
}
Beispiel #2
0
int8_t AsyncClient::_recv(tcp_pcb* pcb, pbuf* pb, int8_t err) {
    if(pb == NULL){
        return _close();
    }

    while(pb != NULL){
        _rx_last_packet = millis();
        //we should not ack before we assimilate the data
        //log_i("%u", pb->len);
        //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);
    }
    return ERR_OK;
}