#include "httpd-platform.h" #include #include #include #include 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* platHttpServerTaskPosix(void *pvParameters) { platHttpServerTask(pvParameters); return NULL; } //Initialize listening socket, do general initialization httpd_thread_handle_t *httpdPlatStart(struct httpd_options *opts) { struct httpd_thread_handle* handle = httpdPlatMalloc(sizeof(struct httpd_thread_handle)); if (!handle) { return NULL; } pthread_create( &handle->handle, NULL, platHttpServerTaskPosix, (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); }