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/src/port/httpd-posix.c

83 lines
1.6 KiB

#include "httpd-platform.h"
#include "httpd-logging.h"
#include "httpd-heap.h"
#include <pthread.h>
#include <unistd.h>
#include <malloc.h>
#include <string.h>
static pthread_mutex_t Mutex;
static pthread_mutexattr_t MutexAttr;
//Set/clear global httpd lock.
void httpdPlatLock()
{
pthread_mutex_lock(&Mutex);
}
void httpdPlatUnlock()
{
pthread_mutex_unlock(&Mutex);
}
void httpdPlatDelayMs(uint32_t ms)
{
usleep(ms * 1000);
}
void httpdPlatTaskEnd()
{
// Nothing special needed with pthreads
}
void httpdPlatDisableTimeout(ConnTypePtr conn)
{
//Unimplemented
(void) conn;
}
void httpdPlatInit() {
pthread_mutexattr_init(&MutexAttr);
pthread_mutexattr_settype(&MutexAttr, PTHREAD_MUTEX_RECURSIVE);
pthread_mutex_init(&Mutex, &MutexAttr);
}
struct httpd_thread_handle {
pthread_t handle;
// TODO some way to signal shutdown?
};
void* httpdServerTaskPosix(void *pvParameters)
{
httpdServerTask(pvParameters);
return NULL;
}
//Initialize listening socket, do general initialization
httpd_thread_handle_t *httpdPlatStart(struct httpd_init_options *opts)
{
struct httpd_thread_handle* handle = httpdMalloc(sizeof(struct httpd_thread_handle));
if (!handle) {
return NULL;
}
pthread_create(&handle->handle, NULL, httpdServerTaskPosix, (void *) opts);
return handle;
}
void httpdPlatJoin(httpd_thread_handle_t * handle)
{
if (handle) {
pthread_join(handle->handle, NULL);
}
}
void* httpdPlatMalloc(size_t len)
{
return malloc(len);
}
void httpdPlatFree(void *ptr)
{
free(ptr);
}