| 447 | } |
| 448 | |
| 449 | err_t TcpConnection::internalOnReceive(pbuf* p, err_t err) |
| 450 | { |
| 451 | sleep = 0; |
| 452 | |
| 453 | if(err != ERR_OK /*&& err != ERR_CLSD && err != ERR_RST*/) { |
| 454 | debug_tcp_d("receive ERROR %d", err); |
| 455 | /* exit and free resources, for unknown reason */ |
| 456 | if(p != nullptr) { |
| 457 | /* Inform TCP that we have taken the data. */ |
| 458 | tcp_recved(tcp, p->tot_len); |
| 459 | pbuf_free(p); |
| 460 | } |
| 461 | closeTcpConnection(tcp); // ?? |
| 462 | tcp = nullptr; |
| 463 | onError(err); |
| 464 | //close(); |
| 465 | return err == ERR_ABRT ? ERR_ABRT : ERR_OK; |
| 466 | } |
| 467 | |
| 468 | //if (tcp != nullptr && tcp->state == ESTABLISHED) // If active |
| 469 | /* We have taken the data. */ |
| 470 | if(p != nullptr) { |
| 471 | tcp_recved(tcp, p->tot_len); |
| 472 | } else { |
| 473 | debug_tcp_d("receive: pbuf is NULL"); |
| 474 | } |
| 475 | |
| 476 | if(ssl != nullptr && p != nullptr) { |
| 477 | bool isConnecting = !ssl->isConnected(); |
| 478 | |
| 479 | Ssl::InputBuffer input(p); |
| 480 | |
| 481 | pbuf pbufOut = {}; |
| 482 | while(input.available() > 0) { |
| 483 | uint8_t* output; |
| 484 | int len = ssl->read(input, output); |
| 485 | if(len < 0) { |
| 486 | close(); |
| 487 | closeTcpConnection(tcp); |
| 488 | return ERR_ABRT; |
| 489 | } |
| 490 | |
| 491 | if(isConnecting && ssl->isConnected()) { |
| 492 | err = onConnected(ERR_OK); |
| 493 | } else if(len != 0) { |
| 494 | // Proceed with received decrypted data |
| 495 | pbufOut.payload = output; |
| 496 | pbufOut.tot_len = len; |
| 497 | pbufOut.len = len; |
| 498 | err = onReceive(&pbufOut); |
| 499 | } |
| 500 | |
| 501 | if(err < 0) { |
| 502 | break; |
| 503 | } |
| 504 | } |
| 505 | |
| 506 | } else { |
no test coverage detected