| 298 | } |
| 299 | |
| 300 | void TcpConnection::initialize(tcp_pcb* pcb) |
| 301 | { |
| 302 | assert(pcb != nullptr); |
| 303 | |
| 304 | tcp = pcb; |
| 305 | sleep = 0; |
| 306 | canSend = true; |
| 307 | |
| 308 | tcp_nagle_disable(tcp); |
| 309 | tcp_arg(tcp, this); |
| 310 | |
| 311 | tcp_sent(tcp, [](void* arg, tcp_pcb*, uint16_t len) -> err_t { |
| 312 | auto con = static_cast<TcpConnection*>(arg); |
| 313 | return (con == nullptr) ? err_t(ERR_OK) : con->internalOnSent(len); |
| 314 | }); |
| 315 | |
| 316 | tcp_recv(tcp, [](void* arg, tcp_pcb* tcp, pbuf* p, err_t err) -> err_t { |
| 317 | auto con = static_cast<TcpConnection*>(arg); |
| 318 | //Serial.println("echo_recv!"); |
| 319 | |
| 320 | if(con == nullptr) { |
| 321 | if(p != nullptr) { |
| 322 | /* Inform TCP that we have taken the data. */ |
| 323 | tcp_recved(tcp, p->tot_len); |
| 324 | pbuf_free(p); |
| 325 | } |
| 326 | closeTcpConnection(tcp); |
| 327 | return ERR_OK; |
| 328 | } else { |
| 329 | return con->internalOnReceive(p, err); |
| 330 | } |
| 331 | }); |
| 332 | |
| 333 | tcp_err(tcp, [](void* arg, err_t err) { |
| 334 | auto con = static_cast<TcpConnection*>(arg); |
| 335 | if(con != nullptr) { |
| 336 | con->internalOnError(err); |
| 337 | } |
| 338 | }); |
| 339 | |
| 340 | tcp_poll(tcp, staticOnPoll, 4); |
| 341 | |
| 342 | #ifdef NETWORK_DEBUG |
| 343 | debug_tcp_d("+connection"); |
| 344 | #endif |
| 345 | } |
| 346 | |
| 347 | void TcpConnection::closeTcpConnection(tcp_pcb* tpcb) |
| 348 | { |
nothing calls this directly
no test coverage detected