mirror of
https://github.com/cesanta/mongoose.git
synced 2026-10-24 11:54:49 +00:00
stm32f7 example starts on real h/w, with plus-TCP driver
This commit is contained in:
1 parent
0f32f50c50
commit
47e5e984df
30 files changed
+3716
-1257
No files matched your search
@@ -16,6 +16,8 @@
|
||||
#define MG_ARCH MG_ARCH_ESP8266
|
||||
#elif defined(ESP_PLATFORM)
|
||||
#define MG_ARCH MG_ARCH_ESP32
|
||||
#elif defined(FREERTOS_IP_H)
|
||||
#define MG_ARCH MG_ARCH_FREERTOS_TCP
|
||||
#endif
|
||||
|
||||
#if !defined(MG_ARCH)
|
||||
|
||||
@@ -26,6 +26,8 @@
|
||||
#define MG_INT64_FMT "%lld"
|
||||
#define MG_DIRSEP '/'
|
||||
|
||||
// Why FreeRTOS-TCP did not implement a clean BSD API, but its own thing
|
||||
// with FreeRTOS_ prefix, is beyond me
|
||||
#define IPPROTO_TCP FREERTOS_IPPROTO_TCP
|
||||
#define IPPROTO_UDP FREERTOS_IPPROTO_UDP
|
||||
#define AF_INET FREERTOS_AF_INET
|
||||
@@ -51,6 +53,17 @@
|
||||
#define closesocket(x) FreeRTOS_closesocket(x)
|
||||
#define gethostbyname(x) FreeRTOS_gethostbyname(x)
|
||||
|
||||
// Re-route calloc/free to the FreeRTOS's functions, don't use stdlib
|
||||
static inline void *mg_calloc(int cnt, size_t size) {
|
||||
void *p = pvPortMalloc(cnt * size);
|
||||
if (p != NULL) memset(p, 0, size);
|
||||
return p;
|
||||
}
|
||||
#define calloc(a, b) mg_calloc((a), (b))
|
||||
#define free(a) vPortFree(a)
|
||||
#define malloc(a) pvPortMalloc(a)
|
||||
|
||||
// Again, why not a clean retarget, but instead this..
|
||||
#ifdef MG_ENABLE_FF
|
||||
#include <ff_stdio.h>
|
||||
|
||||
|
||||
+1
-1
@@ -643,7 +643,7 @@ DIR *opendir(const char *name) {
|
||||
|
||||
if (name == NULL) {
|
||||
SetLastError(ERROR_BAD_ARGUMENTS);
|
||||
} else if ((d = (DIR *) malloc(sizeof(*d))) == NULL) {
|
||||
} else if ((d = (DIR *) calloc(1, sizeof(*d))) == NULL) {
|
||||
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
|
||||
} else {
|
||||
to_wchar(name, wpath, sizeof(wpath) / sizeof(wpath[0]));
|
||||
|
||||
+2
-2
@@ -19,9 +19,9 @@ int mg_iobuf_resize(struct mg_iobuf *io, size_t new_size) {
|
||||
io->buf = NULL;
|
||||
io->len = io->size = 0;
|
||||
} else if (new_size != io->size) {
|
||||
// NOTE(lsm): do not use realloc here. Use malloc/free only, to ease the
|
||||
// NOTE(lsm): do not use realloc here. Use calloc/free only, to ease the
|
||||
// porting to some obscure platforms like FreeRTOS
|
||||
void *p = malloc(new_size);
|
||||
void *p = calloc(1, new_size);
|
||||
if (p != NULL) {
|
||||
size_t len = new_size < io->len ? new_size : io->len;
|
||||
if (len > 0) memcpy(p, io->buf, len);
|
||||
|
||||
@@ -115,7 +115,7 @@ void mg_mgr_free(struct mg_mgr *mgr) {
|
||||
struct mg_connection *c;
|
||||
for (c = mgr->conns; c != NULL; c = c->next) c->is_closing = 1;
|
||||
mg_mgr_poll(mgr, 0);
|
||||
#if MG_ARCH == MG_ARCH_FREERTOS
|
||||
#if MG_ARCH == MG_ARCH_FREERTOS_TCP
|
||||
FreeRTOS_DeleteSocketSet(mgr->ss);
|
||||
#endif
|
||||
LOG(LL_INFO, ("All connections closed"));
|
||||
|
||||
@@ -1,12 +1 @@
|
||||
void mg_connect_resolved(struct mg_connection *);
|
||||
|
||||
#if MG_ARCH == MG_ARCH_FREERTOS_TCP
|
||||
static inline void *mg_calloc(int cnt, size_t size) {
|
||||
void *p = pvPortMalloc(cnt * size);
|
||||
if (p != NULL) memset(p, 0, size);
|
||||
return p;
|
||||
}
|
||||
#define calloc(a, b) mg_calloc((a), (b))
|
||||
#define malloc(a) pvPortMalloc(a)
|
||||
#define free(a) vPortFree(a)
|
||||
#endif
|
||||
+3
-1
@@ -235,11 +235,13 @@ SOCKET mg_open_listener(const char *url) {
|
||||
(type == SOCK_DGRAM || listen(fd, 128) == 0)) {
|
||||
mg_set_non_blocking_mode(fd);
|
||||
} else if (fd != INVALID_SOCKET) {
|
||||
LOG(LL_ERROR, ("Failed to listen on %s, errno %d", url, MG_SOCK_ERRNO));
|
||||
closesocket(fd);
|
||||
fd = INVALID_SOCKET;
|
||||
}
|
||||
}
|
||||
if (fd == INVALID_SOCKET) {
|
||||
LOG(LL_ERROR, ("Failed to listen on %s, errno %d", url, MG_SOCK_ERRNO));
|
||||
}
|
||||
|
||||
return fd;
|
||||
}
|
||||
|
||||
@@ -44,7 +44,7 @@ int mg_vcasecmp(const struct mg_str *str1, const char *str2) {
|
||||
struct mg_str mg_strdup(const struct mg_str s) {
|
||||
struct mg_str r = {NULL, 0};
|
||||
if (s.len > 0 && s.ptr != NULL) {
|
||||
char *sc = (char *) malloc(s.len + 1);
|
||||
char *sc = (char *) calloc(1, s.len + 1);
|
||||
if (sc != NULL) {
|
||||
memcpy(sc, s.ptr, s.len);
|
||||
sc[s.len] = '\0';
|
||||
|
||||
+4
-4
@@ -39,7 +39,7 @@ char *mg_file_read(const char *path, size_t *sizep) {
|
||||
char *data = NULL;
|
||||
size_t size = (size_t) mg_file_size(path);
|
||||
if ((fp = mg_fopen(path, "rb")) != NULL) {
|
||||
data = (char *) malloc(size + 1);
|
||||
data = (char *) calloc(1, size + 1);
|
||||
if (data != NULL) {
|
||||
if (fread(data, 1, size, fp) != size) {
|
||||
free(data);
|
||||
@@ -156,7 +156,7 @@ uint16_t mg_ntohs(uint16_t net) {
|
||||
char *mg_hexdump(const void *buf, size_t len) {
|
||||
const unsigned char *p = (const unsigned char *) buf;
|
||||
size_t i, idx, n = 0, ofs = 0, dlen = len * 5 + 100;
|
||||
char ascii[17] = "", *dst = (char *) malloc(dlen);
|
||||
char ascii[17] = "", *dst = (char *) calloc(1, dlen);
|
||||
if (dst == NULL) return dst;
|
||||
for (i = 0; i < len; i++) {
|
||||
idx = i % 16;
|
||||
@@ -227,7 +227,7 @@ int mg_vasprintf(char **buf, size_t size, const char *fmt, va_list ap) {
|
||||
free(*buf);
|
||||
if (size == 0) size = 5;
|
||||
size *= 2;
|
||||
if ((*buf = (char *) malloc(size)) == NULL) {
|
||||
if ((*buf = (char *) calloc(1, size)) == NULL) {
|
||||
len = -1;
|
||||
break;
|
||||
}
|
||||
@@ -241,7 +241,7 @@ int mg_vasprintf(char **buf, size_t size, const char *fmt, va_list ap) {
|
||||
// LCOV_EXCL_STOP
|
||||
} else if (len >= (int) size) {
|
||||
/// Standard-compliant code path. Allocate a buffer that is large enough
|
||||
if ((*buf = (char *) malloc(len + 1)) == NULL) {
|
||||
if ((*buf = (char *) calloc(1, len + 1)) == NULL) {
|
||||
len = -1; // LCOV_EXCL_LINE
|
||||
} else { // LCOV_EXCL_LINE
|
||||
va_copy(ap_copy, ap);
|
||||
|
||||
Reference in new issue
Block a user