mirror of
https://github.com/cesanta/mongoose.git
synced 2024-11-24 02:59:01 +08:00
FreeRTOS-Plus-TCP fixes
This commit is contained in:
parent
47e5e984df
commit
dbc2356768
@ -2890,7 +2890,7 @@ static void close_conn(struct mg_connection *c) {
|
||||
|
||||
static void setsockopts(struct mg_connection *c) {
|
||||
#if MG_ARCH == MG_ARCH_FREERTOS_TCP
|
||||
FreeRTOS_FD_SET(c->fd, c->mgr->ss, eSELECT_READ | eSELECT_EXCEPT);
|
||||
(void) c;
|
||||
#else
|
||||
int on = 1;
|
||||
#if !defined(SOL_TCP)
|
||||
@ -2974,7 +2974,7 @@ static void accept_conn(struct mg_mgr *mgr, struct mg_connection *lsn) {
|
||||
SOCKET fd = accept(FD(lsn), &usa.sa, &sa_len);
|
||||
if (fd == INVALID_SOCKET) {
|
||||
LOG(LL_ERROR, ("%lu accept failed, errno %d", lsn->id, MG_SOCK_ERRNO));
|
||||
#if !defined(_WIN32)
|
||||
#if (!defined(_WIN32) && (MG_ARCH != MG_ARCH_FREERTOS_TCP))
|
||||
} else if ((long) fd >= FD_SETSIZE) {
|
||||
LOG(LL_ERROR, ("%ld > %ld", (long) fd, (long) FD_SETSIZE));
|
||||
closesocket(fd);
|
||||
@ -3075,7 +3075,8 @@ static void mg_iotest(struct mg_mgr *mgr, int ms) {
|
||||
#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);
|
||||
if (c->is_closing || c->is_resolving || FD(c) == INVALID_SOCKET) continue;
|
||||
FreeRTOS_FD_SET(c->fd, mgr->ss, eSELECT_READ | eSELECT_EXCEPT);
|
||||
if (c->is_connecting || (c->send.len > 0 && c->is_tls_hs == 0))
|
||||
FreeRTOS_FD_SET(c->fd, mgr->ss, eSELECT_WRITE);
|
||||
}
|
||||
@ -3084,6 +3085,8 @@ static void mg_iotest(struct mg_mgr *mgr, int ms) {
|
||||
EventBits_t bits = FreeRTOS_FD_ISSET(c->fd, mgr->ss);
|
||||
c->is_readable = bits & (eSELECT_READ | eSELECT_EXCEPT) ? 1 : 0;
|
||||
c->is_writable = bits & eSELECT_WRITE ? 1 : 0;
|
||||
FreeRTOS_FD_CLR(c->fd, mgr->ss,
|
||||
eSELECT_READ | eSELECT_EXCEPT | eSELECT_WRITE);
|
||||
}
|
||||
#else
|
||||
struct timeval tv = {ms / 1000, (ms % 1000) * 1000};
|
||||
|
47
mongoose.h
47
mongoose.h
@ -123,7 +123,6 @@
|
||||
|
||||
#include <ctype.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <limits.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdbool.h>
|
||||
@ -131,11 +130,7 @@
|
||||
#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 <FreeRTOS_IP.h>
|
||||
@ -182,29 +177,29 @@ static inline void *mg_calloc(int cnt, size_t size) {
|
||||
#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>
|
||||
#define gmtime_r(a, b) gmtime(a)
|
||||
|
||||
#undef FILE
|
||||
#define FILE FF_FILE
|
||||
#define stat(a, b) ff_stat((a), (b))
|
||||
#define fopen(a, b) ff_fopen((a), (b))
|
||||
#define fclose(a) ff_fclose(a)
|
||||
#define fread(a, b, c, d) ff_fread((a), (b), (c), (d))
|
||||
#define fwrite(a, b, c, d) ff_fwrite((a), (b), (c), (d))
|
||||
#define vfprintf ff_vfprintf
|
||||
#define fprintf ff_fprintf
|
||||
#define remove(a) ff_remove(a)
|
||||
#define rename(a, b) ff_rename((a), (b), 1)
|
||||
#if !defined(__GNUC__)
|
||||
// copied from GCC on ARM; for some reason useconds are signed
|
||||
typedef long suseconds_t;
|
||||
struct timeval {
|
||||
time_t tv_sec;
|
||||
suseconds_t tv_usec;
|
||||
};
|
||||
#endif
|
||||
|
||||
static inline int ff_vfprintf(FF_FILE *fp, const char *fmt, va_list ap) {
|
||||
char *buf = NULL;
|
||||
int n = mg_vasprintf(&buf, 0, fmt, ap);
|
||||
if (buf != NULL) ff_fwrite(buf, 1, n, fp), free(buf);
|
||||
return n;
|
||||
}
|
||||
#endif // MG_ENABLE_FF
|
||||
#ifndef EINPROGRESS
|
||||
#define EINPROGRESS pdFREERTOS_ERRNO_EINPROGRESS
|
||||
#endif
|
||||
#ifndef EWOULDBLOCK
|
||||
#define EWOULDBLOCK pdFREERTOS_ERRNO_EWOULDBLOCK
|
||||
#endif
|
||||
#ifndef EAGAIN
|
||||
#define EAGAIN pdFREERTOS_ERRNO_EAGAIN
|
||||
#endif
|
||||
#ifndef EINTR
|
||||
#define EINTR pdFREERTOS_ERRNO_EINTR
|
||||
#endif
|
||||
|
||||
#endif // MG_ARCH == MG_ARCH_FREERTOS_TCP
|
||||
|
||||
|
@ -4,7 +4,6 @@
|
||||
|
||||
#include <ctype.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <limits.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdbool.h>
|
||||
@ -12,11 +11,7 @@
|
||||
#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 <FreeRTOS_IP.h>
|
||||
@ -63,28 +58,28 @@ static inline void *mg_calloc(int cnt, size_t size) {
|
||||
#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>
|
||||
#define gmtime_r(a, b) gmtime(a)
|
||||
|
||||
#undef FILE
|
||||
#define FILE FF_FILE
|
||||
#define stat(a, b) ff_stat((a), (b))
|
||||
#define fopen(a, b) ff_fopen((a), (b))
|
||||
#define fclose(a) ff_fclose(a)
|
||||
#define fread(a, b, c, d) ff_fread((a), (b), (c), (d))
|
||||
#define fwrite(a, b, c, d) ff_fwrite((a), (b), (c), (d))
|
||||
#define vfprintf ff_vfprintf
|
||||
#define fprintf ff_fprintf
|
||||
#define remove(a) ff_remove(a)
|
||||
#define rename(a, b) ff_rename((a), (b), 1)
|
||||
#if !defined(__GNUC__)
|
||||
// copied from GCC on ARM; for some reason useconds are signed
|
||||
typedef long suseconds_t;
|
||||
struct timeval {
|
||||
time_t tv_sec;
|
||||
suseconds_t tv_usec;
|
||||
};
|
||||
#endif
|
||||
|
||||
static inline int ff_vfprintf(FF_FILE *fp, const char *fmt, va_list ap) {
|
||||
char *buf = NULL;
|
||||
int n = mg_vasprintf(&buf, 0, fmt, ap);
|
||||
if (buf != NULL) ff_fwrite(buf, 1, n, fp), free(buf);
|
||||
return n;
|
||||
}
|
||||
#endif // MG_ENABLE_FF
|
||||
#ifndef EINPROGRESS
|
||||
#define EINPROGRESS pdFREERTOS_ERRNO_EINPROGRESS
|
||||
#endif
|
||||
#ifndef EWOULDBLOCK
|
||||
#define EWOULDBLOCK pdFREERTOS_ERRNO_EWOULDBLOCK
|
||||
#endif
|
||||
#ifndef EAGAIN
|
||||
#define EAGAIN pdFREERTOS_ERRNO_EAGAIN
|
||||
#endif
|
||||
#ifndef EINTR
|
||||
#define EINTR pdFREERTOS_ERRNO_EINTR
|
||||
#endif
|
||||
|
||||
#endif // MG_ARCH == MG_ARCH_FREERTOS_TCP
|
||||
|
@ -306,7 +306,7 @@ static void close_conn(struct mg_connection *c) {
|
||||
|
||||
static void setsockopts(struct mg_connection *c) {
|
||||
#if MG_ARCH == MG_ARCH_FREERTOS_TCP
|
||||
FreeRTOS_FD_SET(c->fd, c->mgr->ss, eSELECT_READ | eSELECT_EXCEPT);
|
||||
(void) c;
|
||||
#else
|
||||
int on = 1;
|
||||
#if !defined(SOL_TCP)
|
||||
@ -390,7 +390,7 @@ static void accept_conn(struct mg_mgr *mgr, struct mg_connection *lsn) {
|
||||
SOCKET fd = accept(FD(lsn), &usa.sa, &sa_len);
|
||||
if (fd == INVALID_SOCKET) {
|
||||
LOG(LL_ERROR, ("%lu accept failed, errno %d", lsn->id, MG_SOCK_ERRNO));
|
||||
#if !defined(_WIN32)
|
||||
#if (!defined(_WIN32) && (MG_ARCH != MG_ARCH_FREERTOS_TCP))
|
||||
} else if ((long) fd >= FD_SETSIZE) {
|
||||
LOG(LL_ERROR, ("%ld > %ld", (long) fd, (long) FD_SETSIZE));
|
||||
closesocket(fd);
|
||||
@ -491,7 +491,8 @@ static void mg_iotest(struct mg_mgr *mgr, int ms) {
|
||||
#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);
|
||||
if (c->is_closing || c->is_resolving || FD(c) == INVALID_SOCKET) continue;
|
||||
FreeRTOS_FD_SET(c->fd, mgr->ss, eSELECT_READ | eSELECT_EXCEPT);
|
||||
if (c->is_connecting || (c->send.len > 0 && c->is_tls_hs == 0))
|
||||
FreeRTOS_FD_SET(c->fd, mgr->ss, eSELECT_WRITE);
|
||||
}
|
||||
@ -500,6 +501,8 @@ static void mg_iotest(struct mg_mgr *mgr, int ms) {
|
||||
EventBits_t bits = FreeRTOS_FD_ISSET(c->fd, mgr->ss);
|
||||
c->is_readable = bits & (eSELECT_READ | eSELECT_EXCEPT) ? 1 : 0;
|
||||
c->is_writable = bits & eSELECT_WRITE ? 1 : 0;
|
||||
FreeRTOS_FD_CLR(c->fd, mgr->ss,
|
||||
eSELECT_READ | eSELECT_EXCEPT | eSELECT_WRITE);
|
||||
}
|
||||
#else
|
||||
struct timeval tv = {ms / 1000, (ms % 1000) * 1000};
|
||||
|
Loading…
Reference in New Issue
Block a user