mirror of
https://github.com/cesanta/mongoose.git
synced 2026-11-25 20:28:27 +00:00
Add initial Zephyr support
This commit is contained in:
1 parent
642befa8d5
commit
7372a05ce5
5 files changed
+51
-8
No files matched your search
+8
-4
@@ -3448,7 +3448,7 @@ static void setsockopts(struct mg_connection *c) {
|
|||||||
if (setsockopt(FD(c), IPPROTO_TCP, TCP_KEEPIDLE, &idle, sizeof(idle)) != 0)
|
if (setsockopt(FD(c), IPPROTO_TCP, TCP_KEEPIDLE, &idle, sizeof(idle)) != 0)
|
||||||
(void) 0;
|
(void) 0;
|
||||||
#endif
|
#endif
|
||||||
#if MG_ARCH != MG_ARCH_WIN32 && !defined(__QNX__)
|
#if MG_ARCH != MG_ARCH_WIN32 && !defined(__QNX__) && MG_ARCH != MG_ARCH_ZEPHYR
|
||||||
{
|
{
|
||||||
int cnt = 3, intvl = 20;
|
int cnt = 3, intvl = 20;
|
||||||
if (setsockopt(FD(c), IPPROTO_TCP, TCP_KEEPCNT, &cnt, sizeof(cnt)) != 0)
|
if (setsockopt(FD(c), IPPROTO_TCP, TCP_KEEPCNT, &cnt, sizeof(cnt)) != 0)
|
||||||
@@ -3712,19 +3712,23 @@ void mg_mgr_poll(struct mg_mgr *mgr, int ms) {
|
|||||||
#define MG_MAX_SSI_DEPTH 5
|
#define MG_MAX_SSI_DEPTH 5
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifndef MG_SSI_BUFSIZ
|
||||||
|
#define MG_SSI_BUFSIZ 1024
|
||||||
|
#endif
|
||||||
|
|
||||||
#if MG_ENABLE_SSI
|
#if MG_ENABLE_SSI
|
||||||
static char *mg_ssi(const char *path, const char *root, int depth) {
|
static char *mg_ssi(const char *path, const char *root, int depth) {
|
||||||
struct mg_iobuf b = {NULL, 0, 0};
|
struct mg_iobuf b = {NULL, 0, 0};
|
||||||
FILE *fp = fopen(path, "rb");
|
FILE *fp = fopen(path, "rb");
|
||||||
if (fp != NULL) {
|
if (fp != NULL) {
|
||||||
char buf[BUFSIZ] = "", arg[sizeof(buf)] = "";
|
char buf[MG_SSI_BUFSIZ] = "", arg[sizeof(buf)] = "";
|
||||||
int ch, intag = 0;
|
int ch, intag = 0;
|
||||||
size_t len = 0, align = MG_IO_SIZE;
|
size_t len = 0, align = MG_IO_SIZE;
|
||||||
while ((ch = fgetc(fp)) != EOF) {
|
while ((ch = fgetc(fp)) != EOF) {
|
||||||
if (intag && ch == '>' && buf[len - 1] == '-' && buf[len - 2] == '-') {
|
if (intag && ch == '>' && buf[len - 1] == '-' && buf[len - 2] == '-') {
|
||||||
buf[len++] = (char) (ch & 0xff);
|
buf[len++] = (char) (ch & 0xff);
|
||||||
if (sscanf(buf, "<!--#include file=\"%[^\"]", arg)) {
|
if (sscanf(buf, "<!--#include file=\"%[^\"]", arg)) {
|
||||||
char tmp[MG_PATH_MAX + BUFSIZ + 10],
|
char tmp[MG_PATH_MAX + MG_SSI_BUFSIZ + 10],
|
||||||
*p = (char *) path + strlen(path), *data;
|
*p = (char *) path + strlen(path), *data;
|
||||||
while (p > path && p[-1] != MG_DIRSEP && p[-1] != '/') p--;
|
while (p > path && p[-1] != MG_DIRSEP && p[-1] != '/') p--;
|
||||||
mg_snprintf(tmp, sizeof(tmp), "%.*s%s", (int) (p - path), path, arg);
|
mg_snprintf(tmp, sizeof(tmp), "%.*s%s", (int) (p - path), path, arg);
|
||||||
@@ -3736,7 +3740,7 @@ static char *mg_ssi(const char *path, const char *root, int depth) {
|
|||||||
MG_ERROR(("%s: file=%s error or too deep", path, arg));
|
MG_ERROR(("%s: file=%s error or too deep", path, arg));
|
||||||
}
|
}
|
||||||
} else if (sscanf(buf, "<!--#include virtual=\"%[^\"]", arg)) {
|
} else if (sscanf(buf, "<!--#include virtual=\"%[^\"]", arg)) {
|
||||||
char tmp[MG_PATH_MAX + BUFSIZ + 10], *data;
|
char tmp[MG_PATH_MAX + MG_SSI_BUFSIZ + 10], *data;
|
||||||
mg_snprintf(tmp, sizeof(tmp), "%s%s", root, arg);
|
mg_snprintf(tmp, sizeof(tmp), "%s%s", root, arg);
|
||||||
if (depth < MG_MAX_SSI_DEPTH &&
|
if (depth < MG_MAX_SSI_DEPTH &&
|
||||||
(data = mg_ssi(tmp, root, depth + 1)) != NULL) {
|
(data = mg_ssi(tmp, root, depth + 1)) != NULL) {
|
||||||
|
|||||||
+31
@@ -36,6 +36,7 @@ extern "C" {
|
|||||||
#define MG_ARCH_FREERTOS_LWIP 6
|
#define MG_ARCH_FREERTOS_LWIP 6
|
||||||
#define MG_ARCH_AZURERTOS 7
|
#define MG_ARCH_AZURERTOS 7
|
||||||
#define MG_ARCH_RTX_LWIP 8
|
#define MG_ARCH_RTX_LWIP 8
|
||||||
|
#define MG_ARCH_ZEPHYR 9
|
||||||
|
|
||||||
#if !defined(MG_ARCH)
|
#if !defined(MG_ARCH)
|
||||||
#if defined(__unix__) || defined(__APPLE__)
|
#if defined(__unix__) || defined(__APPLE__)
|
||||||
@@ -50,6 +51,8 @@ extern "C" {
|
|||||||
#define MG_ARCH MG_ARCH_FREERTOS_TCP
|
#define MG_ARCH MG_ARCH_FREERTOS_TCP
|
||||||
#elif defined(AZURE_RTOS_THREADX)
|
#elif defined(AZURE_RTOS_THREADX)
|
||||||
#define MG_ARCH MG_ARCH_AZURERTOS
|
#define MG_ARCH MG_ARCH_AZURERTOS
|
||||||
|
#elif defined(__ZEPHYR__)
|
||||||
|
#define MG_ARCH MG_ARCH_ZEPHYR
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if !defined(MG_ARCH)
|
#if !defined(MG_ARCH)
|
||||||
@@ -75,6 +78,7 @@ extern "C" {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#if MG_ARCH == MG_ARCH_AZURERTOS
|
#if MG_ARCH == MG_ARCH_AZURERTOS
|
||||||
|
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
@@ -459,6 +463,33 @@ typedef int socklen_t;
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#if MG_ARCH == MG_ARCH_ZEPHYR
|
||||||
|
|
||||||
|
#include <zephyr.h>
|
||||||
|
|
||||||
|
#include <ctype.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
#include <net/socket.h>
|
||||||
|
#include <stdarg.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <time.h>
|
||||||
|
|
||||||
|
#define strerror(x) zsock_gai_strerror(x)
|
||||||
|
#define FD_CLOEXEC 0
|
||||||
|
#define F_SETFD 0
|
||||||
|
|
||||||
|
int rand(void);
|
||||||
|
int sscanf(const char *, const char *, ...);
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#ifndef MG_ENABLE_FATFS
|
#ifndef MG_ENABLE_FATFS
|
||||||
#define MG_ENABLE_FATFS 0
|
#define MG_ENABLE_FATFS 0
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -9,6 +9,7 @@
|
|||||||
#define MG_ARCH_FREERTOS_LWIP 6
|
#define MG_ARCH_FREERTOS_LWIP 6
|
||||||
#define MG_ARCH_AZURERTOS 7
|
#define MG_ARCH_AZURERTOS 7
|
||||||
#define MG_ARCH_RTX_LWIP 8
|
#define MG_ARCH_RTX_LWIP 8
|
||||||
|
#define MG_ARCH_ZEPHYR 9
|
||||||
|
|
||||||
#if !defined(MG_ARCH)
|
#if !defined(MG_ARCH)
|
||||||
#if defined(__unix__) || defined(__APPLE__)
|
#if defined(__unix__) || defined(__APPLE__)
|
||||||
@@ -23,6 +24,8 @@
|
|||||||
#define MG_ARCH MG_ARCH_FREERTOS_TCP
|
#define MG_ARCH MG_ARCH_FREERTOS_TCP
|
||||||
#elif defined(AZURE_RTOS_THREADX)
|
#elif defined(AZURE_RTOS_THREADX)
|
||||||
#define MG_ARCH MG_ARCH_AZURERTOS
|
#define MG_ARCH MG_ARCH_AZURERTOS
|
||||||
|
#elif defined(__ZEPHYR__)
|
||||||
|
#define MG_ARCH MG_ARCH_ZEPHYR
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if !defined(MG_ARCH)
|
#if !defined(MG_ARCH)
|
||||||
@@ -46,3 +49,4 @@
|
|||||||
#include "arch_freertos_tcp.h"
|
#include "arch_freertos_tcp.h"
|
||||||
#include "arch_unix.h"
|
#include "arch_unix.h"
|
||||||
#include "arch_win32.h"
|
#include "arch_win32.h"
|
||||||
|
#include "arch_zephyr.h"
|
||||||
+1
-1
@@ -315,7 +315,7 @@ static void setsockopts(struct mg_connection *c) {
|
|||||||
if (setsockopt(FD(c), IPPROTO_TCP, TCP_KEEPIDLE, &idle, sizeof(idle)) != 0)
|
if (setsockopt(FD(c), IPPROTO_TCP, TCP_KEEPIDLE, &idle, sizeof(idle)) != 0)
|
||||||
(void) 0;
|
(void) 0;
|
||||||
#endif
|
#endif
|
||||||
#if MG_ARCH != MG_ARCH_WIN32 && !defined(__QNX__)
|
#if MG_ARCH != MG_ARCH_WIN32 && !defined(__QNX__) && MG_ARCH != MG_ARCH_ZEPHYR
|
||||||
{
|
{
|
||||||
int cnt = 3, intvl = 20;
|
int cnt = 3, intvl = 20;
|
||||||
if (setsockopt(FD(c), IPPROTO_TCP, TCP_KEEPCNT, &cnt, sizeof(cnt)) != 0)
|
if (setsockopt(FD(c), IPPROTO_TCP, TCP_KEEPCNT, &cnt, sizeof(cnt)) != 0)
|
||||||
|
|||||||
@@ -6,19 +6,23 @@
|
|||||||
#define MG_MAX_SSI_DEPTH 5
|
#define MG_MAX_SSI_DEPTH 5
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifndef MG_SSI_BUFSIZ
|
||||||
|
#define MG_SSI_BUFSIZ 1024
|
||||||
|
#endif
|
||||||
|
|
||||||
#if MG_ENABLE_SSI
|
#if MG_ENABLE_SSI
|
||||||
static char *mg_ssi(const char *path, const char *root, int depth) {
|
static char *mg_ssi(const char *path, const char *root, int depth) {
|
||||||
struct mg_iobuf b = {NULL, 0, 0};
|
struct mg_iobuf b = {NULL, 0, 0};
|
||||||
FILE *fp = fopen(path, "rb");
|
FILE *fp = fopen(path, "rb");
|
||||||
if (fp != NULL) {
|
if (fp != NULL) {
|
||||||
char buf[BUFSIZ] = "", arg[sizeof(buf)] = "";
|
char buf[MG_SSI_BUFSIZ] = "", arg[sizeof(buf)] = "";
|
||||||
int ch, intag = 0;
|
int ch, intag = 0;
|
||||||
size_t len = 0, align = MG_IO_SIZE;
|
size_t len = 0, align = MG_IO_SIZE;
|
||||||
while ((ch = fgetc(fp)) != EOF) {
|
while ((ch = fgetc(fp)) != EOF) {
|
||||||
if (intag && ch == '>' && buf[len - 1] == '-' && buf[len - 2] == '-') {
|
if (intag && ch == '>' && buf[len - 1] == '-' && buf[len - 2] == '-') {
|
||||||
buf[len++] = (char) (ch & 0xff);
|
buf[len++] = (char) (ch & 0xff);
|
||||||
if (sscanf(buf, "<!--#include file=\"%[^\"]", arg)) {
|
if (sscanf(buf, "<!--#include file=\"%[^\"]", arg)) {
|
||||||
char tmp[MG_PATH_MAX + BUFSIZ + 10],
|
char tmp[MG_PATH_MAX + MG_SSI_BUFSIZ + 10],
|
||||||
*p = (char *) path + strlen(path), *data;
|
*p = (char *) path + strlen(path), *data;
|
||||||
while (p > path && p[-1] != MG_DIRSEP && p[-1] != '/') p--;
|
while (p > path && p[-1] != MG_DIRSEP && p[-1] != '/') p--;
|
||||||
mg_snprintf(tmp, sizeof(tmp), "%.*s%s", (int) (p - path), path, arg);
|
mg_snprintf(tmp, sizeof(tmp), "%.*s%s", (int) (p - path), path, arg);
|
||||||
@@ -30,7 +34,7 @@ static char *mg_ssi(const char *path, const char *root, int depth) {
|
|||||||
MG_ERROR(("%s: file=%s error or too deep", path, arg));
|
MG_ERROR(("%s: file=%s error or too deep", path, arg));
|
||||||
}
|
}
|
||||||
} else if (sscanf(buf, "<!--#include virtual=\"%[^\"]", arg)) {
|
} else if (sscanf(buf, "<!--#include virtual=\"%[^\"]", arg)) {
|
||||||
char tmp[MG_PATH_MAX + BUFSIZ + 10], *data;
|
char tmp[MG_PATH_MAX + MG_SSI_BUFSIZ + 10], *data;
|
||||||
mg_snprintf(tmp, sizeof(tmp), "%s%s", root, arg);
|
mg_snprintf(tmp, sizeof(tmp), "%s%s", root, arg);
|
||||||
if (depth < MG_MAX_SSI_DEPTH &&
|
if (depth < MG_MAX_SSI_DEPTH &&
|
||||||
(data = mg_ssi(tmp, root, depth + 1)) != NULL) {
|
(data = mg_ssi(tmp, root, depth + 1)) != NULL) {
|
||||||
|
|||||||
Reference in new issue
Block a user