FastLED 3.9.15
Loading...
Searching...
No Matches
fl::asio::http::Server Class Reference

Detailed Description

HTTP Server class.

Minimal HTTP/1.0 server with non-blocking I/O. Designed for educational purposes and host-based testing.

Platform Support:

  • POSIX (Linux, macOS)
  • Windows (via Winsock)
  • NOT supported on embedded platforms (no networking stack)
Note
Server automatically integrates with FastLED's async system. When the server is running, it will automatically process requests during FastLED.show(), delay(), and async_run() calls. The server also listens for engine shutdown events and cleans up automatically.

Definition at line 167 of file server.h.

#include <server.h>

+ Inheritance diagram for fl::asio::http::Server:
+ Collaboration diagram for fl::asio::http::Server:

Classes

struct  ClientConnection
 
struct  RouteEntry
 
class  ServerAsyncRunner
 

Public Member Functions

 Server () FL_NOEXCEPT
 Constructor.
 
 Server (const Server &) FL_NOEXCEPT=delete
 
 ~Server () FL_NOEXCEPT
 Destructor (stops server if running)
 
void del (const string &path, RouteHandler handler)
 Convenience method for DELETE routes.
 
void get (const string &path, RouteHandler handler)
 Convenience method for GET routes.
 
bool is_running () const
 Check if server is running.
 
string last_error () const
 Get last error message.
 
Serveroperator= (const Server &) FL_NOEXCEPT=delete
 
int port () const
 Get server port.
 
void post (const string &path, RouteHandler handler)
 Convenience method for POST routes.
 
void put (const string &path, RouteHandler handler)
 Convenience method for PUT routes.
 
void route (const string &method, const string &path, RouteHandler handler)
 Register route handler using fl::function.
 
bool start (int port=8080)
 Start server on specified port.
 
void stop ()
 Stop server and close all connections.
 
size_t update ()
 Update server (process pending requests non-blocking)
 
- Public Member Functions inherited from fl::EngineEvents::Listener
 Listener () FL_NOEXCEPT
 
virtual ~Listener () FL_NOEXCEPT
 
virtual void onBeginFrame () FL_NOEXCEPT
 
virtual void onCanvasUiSet (CLEDController *strip, const ScreenMap &screenmap) FL_NOEXCEPT
 
virtual void onEndFrame () FL_NOEXCEPT
 
virtual void onEndShowLeds () FL_NOEXCEPT
 
virtual void onPlatformPreLoop () FL_NOEXCEPT
 
virtual void onPlatformPreLoop2 () FL_NOEXCEPT
 
virtual void onStripAdded (CLEDController *strip, fl::u32 num_leds) FL_NOEXCEPT
 

Private Member Functions

void accept_connections ()
 
void cleanup_stale_connections ()
 
void close_client (size_t index)
 
optional< RouteHandlerfind_handler (const string &method, const string &path) const
 
void onExit () override
 
size_t process_requests ()
 
optional< Requestread_request (ClientConnection &client)
 
bool send_response (int client_fd, const Response &response)
 
bool setup_listen_socket (int port)
 

Private Attributes

fl::unique_ptr< ServerAsyncRunnermAsyncRunner
 
vector< ClientConnectionmClientSockets
 
string mLastError
 
int mListenSocket = -1
 
int mPort = 0
 
vector< RouteEntrymRoutes
 
bool mRunning = false
 

The documentation for this class was generated from the following files: