mirror of
https://github.com/cesanta/mongoose.git
synced 2026-10-25 12:04:47 +00:00
First stab
This commit is contained in:
1 parent
9173034b96
commit
d6852f5e74
90 files changed
+54758
-122
No files matched your search
+2
-39
@@ -5,54 +5,17 @@
|
||||
#define MG_ARCH_WIN32 2
|
||||
#define MG_ARCH_ESP32 3
|
||||
#define MG_ARCH_ESP8266 4
|
||||
#define MG_ARCH_CC3100 5
|
||||
#define MG_ARCH_CC3200 6
|
||||
#define MG_ARCH_CC3220 7
|
||||
#define MG_ARCH_MSP432 8
|
||||
#define MG_ARCH_TM4C129 9
|
||||
#define MG_ARCH_MBED 10
|
||||
#define MG_ARCH_WINCE 11
|
||||
#define MG_ARCH_NXP_LPC 12
|
||||
#define MG_ARCH_NXP_KINETIS 13
|
||||
#define MG_ARCH_NRF51 14
|
||||
#define MG_ARCH_NRF52 15
|
||||
#define MG_ARCH_PIC32 16
|
||||
#define MG_ARCH_RS14100 17
|
||||
#define MG_ARCH_STM32 18
|
||||
#define MG_ARCH_FREERTOS 19
|
||||
#define MG_ARCH_FREERTOS_TCP 5
|
||||
|
||||
#if !defined(MG_ARCH)
|
||||
#if defined(TARGET_IS_MSP432P4XX) || defined(__MSP432P401R__)
|
||||
#define MG_ARCH MG_ARCH_MSP432
|
||||
#elif defined(cc3200) || defined(TARGET_IS_CC3200)
|
||||
#define MG_ARCH MG_ARCH_CC3200
|
||||
#elif defined(cc3220) || defined(TARGET_IS_CC3220)
|
||||
#define MG_ARCH MG_ARCH_CC3220
|
||||
#elif defined(__unix__) || defined(__APPLE__)
|
||||
#if defined(__unix__) || defined(__APPLE__)
|
||||
#define MG_ARCH MG_ARCH_UNIX
|
||||
#elif defined(WINCE)
|
||||
#define MG_ARCH MG_ARCH_WINCE
|
||||
#elif defined(_WIN32)
|
||||
#define MG_ARCH MG_ARCH_WIN32
|
||||
#elif defined(__MBED__)
|
||||
#define MG_ARCH MG_ARCH_MBED
|
||||
#elif defined(__USE_LPCOPEN)
|
||||
#define MG_ARCH MG_ARCH_NXP_LPC
|
||||
#elif defined(FRDM_K64F) || defined(FREEDOM)
|
||||
#define MG_ARCH MG_ARCH_NXP_KINETIS
|
||||
#elif defined(PIC32)
|
||||
#define MG_ARCH MG_ARCH_PIC32
|
||||
#elif defined(ICACHE_FLASH) || defined(ICACHE_RAM_ATTR)
|
||||
#define MG_ARCH MG_ARCH_ESP8266
|
||||
#elif defined(ESP_PLATFORM)
|
||||
#define MG_ARCH MG_ARCH_ESP32
|
||||
#elif defined(TARGET_IS_TM4C129_RA0) || defined(TARGET_IS_TM4C129_RA1) || \
|
||||
defined(TARGET_IS_TM4C129_RA2)
|
||||
#define MG_ARCH MG_ARCH_TM4C129
|
||||
#elif defined(RS14100)
|
||||
#define MG_ARCH MG_ARCH_RS14100
|
||||
#elif defined(STM32)
|
||||
#define MG_ARCH MG_ARCH_STM32
|
||||
#endif
|
||||
|
||||
#if !defined(MG_ARCH)
|
||||
|
||||
@@ -1,30 +1,31 @@
|
||||
#pragma once
|
||||
|
||||
#if MG_ARCH == MG_ARCH_FREERTOS
|
||||
#if MG_ARCH == MG_ARCH_FREERTOS_TCP
|
||||
|
||||
#include <ctype.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <limits.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/types.h>
|
||||
#include <time.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <FreeRTOS.h>
|
||||
|
||||
#include <task.h>
|
||||
|
||||
#include <FreeRTOS_IP.h>
|
||||
#include <FreeRTOS_Sockets.h>
|
||||
#include <stdbool.h>
|
||||
#include <task.h>
|
||||
|
||||
#define MG_INT64_FMT "%lld"
|
||||
#define MG_DIRSEP '/'
|
||||
|
||||
#define IPPROTO_TCP FREERTOS_IPPROTO_TCP
|
||||
#define IPPROTO_UDP FREERTOS_IPPROTO_UDP
|
||||
#define AF_INET FREERTOS_AF_INET
|
||||
@@ -52,12 +53,11 @@ struct sockaddr {
|
||||
#define closesocket(x) FreeRTOS_closesocket(x)
|
||||
#define gethostbyname(x) FreeRTOS_gethostbyname(x)
|
||||
|
||||
#ifdef MG_ENABLE_FF
|
||||
#include <ff_stdio.h>
|
||||
|
||||
#undef FILE
|
||||
#define FILE FF_FILE
|
||||
//#define SEEK_SET FF_SEEK_SET
|
||||
//#define SEEK_END FF_SEEK_END
|
||||
#define stat(a, b) ff_stat((a), (b))
|
||||
#define fopen(a, b) ff_fopen((a), (b))
|
||||
#define fclose(a) ff_fclose(a)
|
||||
@@ -74,5 +74,6 @@ static inline int ff_vfprintf(FF_FILE *fp, const char *fmt, va_list ap) {
|
||||
if (buf != NULL) ff_fwrite(buf, 1, n, fp), free(buf);
|
||||
return n;
|
||||
}
|
||||
#endif // MG_ENABLE_FF
|
||||
|
||||
#endif
|
||||
#endif // MG_ARCH == MG_ARCH_FREERTOS_TCP
|
||||
+3
-3
@@ -1,6 +1,6 @@
|
||||
#include "http.h"
|
||||
#include "arch.h"
|
||||
#include "base64.h"
|
||||
#include "http.h"
|
||||
#include "log.h"
|
||||
#include "net.h"
|
||||
#include "private.h"
|
||||
@@ -561,7 +561,7 @@ void mg_http_serve_file(struct mg_connection *c, struct mg_http_message *hm,
|
||||
}
|
||||
|
||||
#if MG_ARCH == MG_ARCH_ESP32 || MG_ARCH == MG_ARCH_ESP8266 || \
|
||||
MG_ARCH == MG_ARCH_FREERTOS
|
||||
MG_ARCH == MG_ARCH_FREERTOS_TCP
|
||||
char *realpath(const char *src, char *dst) {
|
||||
int len = strlen(src);
|
||||
if (len > MG_PATH_MAX - 1) len = MG_PATH_MAX - 1;
|
||||
@@ -575,7 +575,7 @@ char *realpath(const char *src, char *dst) {
|
||||
// Allow user to override this function
|
||||
bool mg_is_dir(const char *path) WEAK;
|
||||
bool mg_is_dir(const char *path) {
|
||||
#if MG_ARCH == MG_ARCH_FREERTOS
|
||||
#if MG_ARCH == MG_ARCH_FREERTOS_TCP && defined(MG_ENABLE_FF)
|
||||
struct FF_STAT st;
|
||||
return (ff_stat(path, &st) == 0) && (st.st_mode & FF_IFDIR);
|
||||
#else
|
||||
|
||||
@@ -24,7 +24,7 @@ struct mg_mgr {
|
||||
int dnstimeout; // DNS resolve timeout in milliseconds
|
||||
unsigned long nextid; // Next connection ID
|
||||
void *userdata; // Arbitrary user data pointer
|
||||
#if MG_ARCH == MG_ARCH_FREERTOS
|
||||
#if MG_ARCH == MG_ARCH_FREERTOS_TCP
|
||||
SocketSet_t ss; // NOTE(lsm): referenced from socket struct
|
||||
#endif
|
||||
};
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
void mg_connect_resolved(struct mg_connection *);
|
||||
|
||||
#if MG_ARCH == MG_ARCH_FREERTOS
|
||||
#if MG_ARCH == MG_ARCH_FREERTOS_TCP
|
||||
static inline void *mg_calloc(int cnt, size_t size) {
|
||||
void *p = pvPortMalloc(size);
|
||||
if (p != NULL) memset(p, 0, size);
|
||||
|
||||
+5
-5
@@ -15,7 +15,7 @@
|
||||
#ifndef SO_EXCLUSIVEADDRUSE
|
||||
#define SO_EXCLUSIVEADDRUSE ((int) (~SO_REUSEADDR))
|
||||
#endif
|
||||
#elif MG_ARCH == MG_ARCH_FREERTOS
|
||||
#elif MG_ARCH == MG_ARCH_FREERTOS_TCP
|
||||
#define MG_SOCK_ERRNO errno
|
||||
typedef Socket_t SOCKET;
|
||||
#define INVALID_SOCKET FREERTOS_INVALID_SOCKET
|
||||
@@ -185,7 +185,7 @@ static void mg_set_non_blocking_mode(SOCKET fd) {
|
||||
#if defined(_WIN32) && MG_ENABLE_WINSOCK
|
||||
unsigned long on = 1;
|
||||
ioctlsocket(fd, FIONBIO, &on);
|
||||
#elif MG_ARCH == MG_ARCH_FREERTOS
|
||||
#elif MG_ARCH == MG_ARCH_FREERTOS_TCP
|
||||
const BaseType_t off = 0;
|
||||
setsockopt(fd, 0, FREERTOS_SO_RCVTIMEO, &off, sizeof(off));
|
||||
setsockopt(fd, 0, FREERTOS_SO_SNDTIMEO, &off, sizeof(off));
|
||||
@@ -291,7 +291,7 @@ static void close_conn(struct mg_connection *c) {
|
||||
LOG(LL_DEBUG, ("%lu closed", c->id));
|
||||
if (FD(c) != INVALID_SOCKET) {
|
||||
closesocket(FD(c));
|
||||
#if MG_ARCH == MG_ARCH_FREERTOS
|
||||
#if MG_ARCH == MG_ARCH_FREERTOS_TCP
|
||||
FreeRTOS_FD_CLR(c->fd, c->mgr->ss, eSELECT_ALL);
|
||||
#endif
|
||||
}
|
||||
@@ -303,7 +303,7 @@ static void close_conn(struct mg_connection *c) {
|
||||
}
|
||||
|
||||
static void setsockopts(struct mg_connection *c) {
|
||||
#if MG_ARCH == MG_ARCH_FREERTOS
|
||||
#if MG_ARCH == MG_ARCH_FREERTOS_TCP
|
||||
FreeRTOS_FD_SET(c->fd, c->mgr->ss, eSELECT_READ | eSELECT_EXCEPT);
|
||||
#else
|
||||
int on = 1;
|
||||
@@ -486,7 +486,7 @@ struct mg_connection *mg_listen(struct mg_mgr *mgr, const char *url,
|
||||
}
|
||||
|
||||
static void mg_iotest(struct mg_mgr *mgr, int ms) {
|
||||
#if MG_ARCH == MG_ARCH_FREERTOS
|
||||
#if MG_ARCH == MG_ARCH_FREERTOS_TCP
|
||||
struct mg_connection *c;
|
||||
for (c = mgr->conns; c != NULL; c = c->next) {
|
||||
FreeRTOS_FD_CLR(c->fd, mgr->ss, eSELECT_WRITE);
|
||||
|
||||
+6
-5
@@ -1,5 +1,5 @@
|
||||
#include "config.h"
|
||||
#include "util.h"
|
||||
#include "config.h"
|
||||
|
||||
#if MG_ENABLE_FS
|
||||
int mg_stat(const char *path, mg_stat_t *st) {
|
||||
@@ -24,7 +24,7 @@ FILE *mg_fopen(const char *path, const char *mode) {
|
||||
}
|
||||
|
||||
int64_t mg_file_size(const char *path) {
|
||||
#if MG_ARCH == MG_ARCH_FREERTOS
|
||||
#if MG_ARCH == MG_ARCH_FREERTOS_TCP && defined(MG_ENABLE_FF)
|
||||
struct FF_STAT st;
|
||||
return ff_stat(path, &st) == 0 ? st.st_size : 0;
|
||||
#else
|
||||
@@ -194,8 +194,9 @@ unsigned long mg_unhexn(const char *s, int len) {
|
||||
for (i = 0; i < (unsigned long) len; i++) {
|
||||
int c = s[i];
|
||||
if (i > 0) v <<= 4;
|
||||
v |= (c >= '0' && c <= '9') ? c - '0'
|
||||
: (c >= 'A' && c <= 'F') ? c - '7' : c - 'W';
|
||||
v |= (c >= '0' && c <= '9') ? c - '0'
|
||||
: (c >= 'A' && c <= 'F') ? c - '7'
|
||||
: c - 'W';
|
||||
}
|
||||
return v;
|
||||
}
|
||||
@@ -327,7 +328,7 @@ unsigned long mg_millis(void) {
|
||||
#elif MG_ARCH == MG_ARCH_ESP8266
|
||||
// return system_get_time() / 1000;
|
||||
return xTaskGetTickCount() * portTICK_PERIOD_MS;
|
||||
#elif MG_ARCH == MG_ARCH_FREERTOS
|
||||
#elif MG_ARCH == MG_ARCH_FREERTOS_TCP
|
||||
return xTaskGetTickCount() * portTICK_PERIOD_MS;
|
||||
#else
|
||||
struct timespec ts;
|
||||
|
||||
Reference in new issue
Block a user