Prusa MINI Firmware overview
lwsapi.h File Reference
#include "lwip/err.h"

Go to the source code of this file.

Functions

err_t lwsapi_init (void)
 Init (start) the LwIP WSAPI server. More...
 

Function Documentation

◆ lwsapi_init()

err_t lwsapi_init ( void  )

Init (start) the LwIP WSAPI server.

Start LwIP WSAPI http server, which means set TCP priority for new protocol control block, bind on TCP port and set callback for accepting new connection.

413  {
414  lwsapi_dbg("lwsapi: start\n");
415  struct tcp_pcb *pcb;
416  err_t err;
417 
418  pcb = tcp_new_ip_type(IPADDR_TYPE_ANY);
419  if (pcb == nullptr) {
420  return ERR_MEM;
421  }
422 
423  tcp_setprio(pcb, TCP_PRIO_MIN);
424  err = tcp_bind(pcb, IP_ANY_TYPE, LIGHT_WSAPI_PORT);
425  if (err != ERR_OK) {
426  lwsapi_error("lwsapi: tcp_bind failed: %d", err);
427  return err;
428  }
429 
430  pcb = tcp_listen(pcb);
431  if (pcb == nullptr) {
432  lwsapi_error("lwsapi: tcp_listen failed");
433  return ERR_CLSD;
434  }
435 
436  tcp_accept(pcb, lwsapi_accept);
437  return ERR_OK;
438 }
Here is the call graph for this function:
Here is the caller graph for this function:
lwsapi_accept
static err_t lwsapi_accept(void *arg, struct tcp_pcb *pcb, err_t err)
tcp_accept callback defined in LwIP
Definition: lwsapi.cpp:387
IP_ANY_TYPE
#define IP_ANY_TYPE
Definition: ip_addr.h:400
LIGHT_WSAPI_PORT
#define LIGHT_WSAPI_PORT
Definition: lwsapi.cpp:10
lwsapi_error
#define lwsapi_error
Definition: lwsapi_app.hpp:42
ERR_MEM
Definition: err.h:65
ERR_CLSD
Definition: err.h:94
lwsapi_dbg
#define lwsapi_dbg
Definition: lwsapi_app.hpp:41
ERR_OK
Definition: err.h:63
err_t
s8_t err_t
Definition: err.h:57
IPADDR_TYPE_ANY
Definition: ip_addr.h:60