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

Private Member Functions

void accept_connections () FL_NO_EXCEPT
 
void cleanup_stale_connections () FL_NO_EXCEPT
 
void close_client (size_t index) FL_NO_EXCEPT
 
optional< RouteHandler > find_handler (const string &method, const string &path) const FL_NO_EXCEPT
 
void onExit () FL_NO_EXCEPT override
 
size_t process_requests () FL_NO_EXCEPT
 
optional< Request > read_request (ClientConnection &client) FL_NO_EXCEPT
 
bool send_response (int client_fd, const Response &response) FL_NO_EXCEPT
 
bool setup_listen_socket (int port) FL_NO_EXCEPT
 

Private Attributes

fl::unique_ptr< ServerAsyncRunner > mAsyncRunner
 
vector< ClientConnection > mClientSockets
 
string mLastError
 
int mListenSocket = -1
 
int mPort = 0
 
vector< RouteEntry > mRoutes
 
bool mRunning = false
 

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