From 42aaea6a171f7dec5f0bead1115be0e744c1a820 Mon Sep 17 00:00:00 2001 From: Pentium44 Date: Wed, 9 Jun 2021 16:22:38 -0700 Subject: [PATCH] Bug fixes, working toward full dynamic memory allocation --- Makefile | 2 +- src/inc/network.h | 1 + src/network.c | 47 ++++++++++++++++++++++++++++++++++------------- 3 files changed, 36 insertions(+), 14 deletions(-) diff --git a/Makefile b/Makefile index 4081625..3c05cb0 100755 --- a/Makefile +++ b/Makefile @@ -11,7 +11,7 @@ PREFIX ?= /usr CC ?= gcc #CC ?= tcc #CC ?= musl-tcc -CFLAGS += -O2 -pedantic -g -Wall -Wextra -mcmodel=large +CFLAGS += -O2 -pedantic -g -Wall -Wextra CPPFLAGS += -DVERSION=$(VERSION) -D_FORTIFY_SOURCE=2 #CPPFLAGS += -DVERSION=$(VERSION) LDFLAGS += -lm diff --git a/src/inc/network.h b/src/inc/network.h index 86976e3..99ddb6b 100644 --- a/src/inc/network.h +++ b/src/inc/network.h @@ -5,6 +5,7 @@ View README file supplied with this software for more details */ + //// FOR nethttp functions, slidescript http server #define HTTP_BUFSIZE 4096 // END OF nethttp diff --git a/src/network.c b/src/network.c index f13216e..aa71492 100644 --- a/src/network.c +++ b/src/network.c @@ -7,6 +7,7 @@ #include "inc/deps.h" #include "inc/network.h" +#include "inc/lexer.h" #include "inc/util.h" // Structure of file types for nethttp @@ -43,17 +44,37 @@ struct { /* Serve process function, on connection catch buffer from socket */ char *snet_process_connection(int sockfd) { - char buff[MAX_STRING_BUFSIZE+1]; - int rr, wr; - bzero(buff, MAX_STRING_BUFSIZE); + char *buff = qmalloc(QM_SS, 1024); + char *endbuff = qmalloc(QM_SS, 1024); + int rr, wr, ii; + bzero(buff, 1024); + bzero(endbuff, 1024); + usleep(50000); - // read the message from client and copy it in buffer - rr = read(sockfd, buff, sizeof(buff)); + ii = 1; - if(rr == -1) + // read the message from client and copy it in buffer + while ( (rr = read(sockfd, buff, 1024)) > 0) { - syn_warn("ss:server:client read error"); + if(ii > 1) + { + endbuff = qrealloc(endbuff, (strlen(endbuff) + 1024)); + //printf("%s\n", buff); + memcpy(&endbuff[(1024 * ii) - 1024], buff, rr); + if(rr < 1024) break; + } + else + { + memcpy(endbuff, buff, rr); + if(rr < 1024) break; + } + + if(rr == 1024) + { + ii++; + continue; + } } // if msg contains "Exit" then server exit, meets search, respond. @@ -76,14 +97,14 @@ char *snet_process_connection(int sockfd) gen_random_string(randTokenName, 16); socket_save = fopen(randTokenName, "wb"); - if(strlen(buff) > 0) + if(strlen(endbuff) > 0) { - fprintf(socket_save, "%s", buff); + fprintf(socket_save, "%s", endbuff); printf("ss:server:client buffer saved as '%s'\n", randTokenName); fflush(stdout); } - fclose(socket_save); + fclose(socket_save); free(randTokenName); // Free malloc, i'm done } @@ -205,12 +226,12 @@ void snet_toss(char *address, int port, char *string) while(sockfd != -1) { - char *buf = malloc(131073); - bzero(buf, 131072); + char *buf = malloc(128); + bzero(buf, 128); usleep(500000); - int listener = read(sockfd, buf, 131072); + int listener = read(sockfd, buf, 128); if(listener < 0) {