#include "tcplistener.h"

using namespace std;
using namespace mbed;

err_t tcp_connection_accept_callback(void *arg, struct tcp_pcb *newpcb, err_t err) {
  TCPListener *listener   = static_cast<TCPListener *>(arg);
  return (listener->accept)(newpcb, err);
}

void TCPListener::bind() {
  if(tcp_bind(this->_pcb, IP_ADDR_ANY, this->_port) == ERR_OK) {
    this->_pcb = tcp_listen(this->_pcb);
    tcp_accept(this->_pcb, tcp_connection_accept_callback);
  }
}
