SpriteHTTPD - embedded HTTP server with read-only filesystem and templating, originally developed for ESP8266, now stand-alone and POSIX compatible.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
spritehttpd/spritehttpd/include/httpd-platform.h

124 lines
2.4 KiB

#pragma once
#include <stdint.h>
#include <stdbool.h>
#include <stddef.h>
#include "httpd-types.h"
// TODO disambiguate by platform?
#define httpd_printf(fmt, ...) printf(fmt, ##__VA_ARGS__)
// (mostly) prototypes for porting
/**
* Lock the server mutex
*/
void httpdPlatLock(void);
/**
* Unlock the server mutex
*/
void httpdPlatUnlock(void);
/**
* Allocate memory.
*
* @attention Do not use directly - call httpdMalloc() instead !
*
* @param len - alloc size
* @return pointer to allocated data or NULL
*/
void *httpdPlatMalloc(size_t len);
/**
* Free allocated data
*
* @attention Do not use directly - call httpdFree() instead !
*
* @param ptr - data pointer
*/
void httpdPlatFree(void *ptr);
/**
* Delay the current thread
*
* @param ms - time in milliseconds
*/
void httpdPlatDelayMs(uint32_t ms);
/**
* Platform-specific way of terminating the current task
*/
void httpdPlatTaskEnd(void);
/**
* Low-level send data to a socket
*
* @param conn - connection struct
* @param buff - bytes to send
* @param len - buffer size
* @return 0 on error. TODO allow partial sending via backlog
*/
int httpdConnSendData(ConnTypePtr conn, const uint8_t *buff, size_t len);
/**
* Disconnect the low-level socket
*
* @param conn - connection struct
*/
void httpdConnDisconnect(ConnTypePtr conn);
/**
* Disable receive timeout on a socket, if it's implemented on this platform.
*
* @param conn - connection struct
*/
void httpdPlatDisableTimeout(ConnTypePtr conn);
/**
* Init platform specific stuff for the http server
*/
void httpdPlatInit(void);
/**
* Start the HTTPD server loop
*
* @param opts - server options
* @return join handle
*/
httpd_thread_handle_t *httpdPlatStart(struct httpd_init_options *opts);
/**
* Wait for the server to end
*
* @param handle - server join handle
*/
void httpdPlatJoin(httpd_thread_handle_t *handle);
/**
* Read from the ESPFS image file.
*
* @param dest destination buffer
* @param offset offset in the filesystem ("address")
* @param len read length
* @return 0 on success
*/
int httpdPlatEspfsRead(void *dest, size_t offset, size_t len);
/**
* Server task function, called by httpdPlatStart inside a thread.
*
* @internal
* @param pvParameters
*/
void httpdServerTask(void *pvParameters);
/**
* Posix format of the server task function.
*
* @internal
* @param pvParameters
* @return
*/
void *httpdServerTaskPosix(void *pvParameters);