MG_IO_SIZE=256 on embedded platforms

This commit is contained in:
Sergey Lyubka authored and Sergio R. Caprile committed 2024-08-30 15:52:14 -03:00
1 parent 7923d1e930
commit 641c7d1967
11 files changed
+124 -64

No files matched your search

-4
View File
@@ -25,10 +25,6 @@
#include <FreeRTOS.h>
#include <task.h>
#ifndef MG_IO_SIZE
#define MG_IO_SIZE 512
#endif
#define calloc(a, b) mg_calloc(a, b)
#define free(a) vPortFree(a)
#define malloc(a) pvPortMalloc(a)
+4
View File
@@ -60,4 +60,8 @@
#define MG_ENABLE_POSIX_FS 1
#endif
#ifndef MG_IO_SIZE
#define MG_IO_SIZE 16384
#endif
#endif
+4
View File
@@ -114,4 +114,8 @@ typedef int socklen_t;
#define MG_ENABLE_POSIX_FS 1
#endif
#ifndef MG_IO_SIZE
#define MG_IO_SIZE 16384
#endif
#endif
+1 -1
View File
@@ -82,7 +82,7 @@
#endif
#ifndef MG_IO_SIZE
#define MG_IO_SIZE 2048 // Granularity of the send/recv IO buffer growth
#define MG_IO_SIZE 256 // Granularity of the send/recv IO buffer growth
#endif
#ifndef MG_MAX_RECV_SIZE
+5 -3
View File
@@ -404,7 +404,8 @@ static void mg_tls_encrypt(struct mg_connection *c, const uint8_t *msg,
#if CHACHA20
(void) tag; // tag is only used in aes gcm
{
uint8_t *enc = (uint8_t *) malloc(8192);
size_t maxlen = MG_IO_SIZE > 16384 ? 16384 : MG_IO_SIZE;
uint8_t *enc = (uint8_t *) calloc(1, maxlen + 256 + 1);
if (enc == NULL) {
mg_error(c, "TLS OOM");
return;
@@ -473,7 +474,7 @@ static int mg_tls_recv_record(struct mg_connection *c) {
nonce[11] ^= (uint8_t) ((seq) &255U);
#if CHACHA20
{
uint8_t *dec = (uint8_t *) malloc(msgsz);
uint8_t *dec = (uint8_t *) calloc(1, msgsz);
size_t n;
if (dec == NULL) {
mg_error(c, "TLS OOM");
@@ -1289,7 +1290,7 @@ void mg_tls_init(struct mg_connection *c, const struct mg_tls_opts *opts) {
c->is_client ? MG_TLS_STATE_CLIENT_START : MG_TLS_STATE_SERVER_START;
tls->skip_verification = opts->skip_verification;
tls->send.align = MG_IO_SIZE;
//tls->send.align = MG_IO_SIZE;
c->tls = tls;
c->is_tls = c->is_tls_hs = 1;
@@ -1359,6 +1360,7 @@ long mg_tls_send(struct mg_connection *c, const void *buf, size_t len) {
struct tls_data *tls = (struct tls_data *) c->tls;
long n = MG_IO_WAIT;
if (len > MG_IO_SIZE) len = MG_IO_SIZE;
if (len > 16384) len = 16384;
mg_tls_encrypt(c, (const uint8_t *) buf, len, MG_TLS_APP_DATA);
while (tls->send.len > 0 &&
(n = mg_io_send(c, tls->send.buf, tls->send.len)) > 0) {