Bug fixes, working toward full dynamic memory allocation

This commit is contained in:
Pentium44 2021-06-09 16:22:38 -07:00
parent 34cdecdb57
commit 42aaea6a17
3 changed files with 36 additions and 14 deletions

View File

@ -11,7 +11,7 @@ PREFIX ?= /usr
CC ?= gcc CC ?= gcc
#CC ?= tcc #CC ?= tcc
#CC ?= musl-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) -D_FORTIFY_SOURCE=2
#CPPFLAGS += -DVERSION=$(VERSION) #CPPFLAGS += -DVERSION=$(VERSION)
LDFLAGS += -lm LDFLAGS += -lm

View File

@ -5,6 +5,7 @@
View README file supplied with this software for more details View README file supplied with this software for more details
*/ */
//// FOR nethttp functions, slidescript http server //// FOR nethttp functions, slidescript http server
#define HTTP_BUFSIZE 4096 #define HTTP_BUFSIZE 4096
// END OF nethttp // END OF nethttp

View File

@ -7,6 +7,7 @@
#include "inc/deps.h" #include "inc/deps.h"
#include "inc/network.h" #include "inc/network.h"
#include "inc/lexer.h"
#include "inc/util.h" #include "inc/util.h"
// Structure of file types for nethttp // Structure of file types for nethttp
@ -43,17 +44,37 @@ struct {
/* Serve process function, on connection catch buffer from socket */ /* Serve process function, on connection catch buffer from socket */
char *snet_process_connection(int sockfd) char *snet_process_connection(int sockfd)
{ {
char buff[MAX_STRING_BUFSIZE+1]; char *buff = qmalloc(QM_SS, 1024);
int rr, wr; char *endbuff = qmalloc(QM_SS, 1024);
bzero(buff, MAX_STRING_BUFSIZE); int rr, wr, ii;
bzero(buff, 1024);
bzero(endbuff, 1024);
usleep(50000); usleep(50000);
// read the message from client and copy it in buffer ii = 1;
rr = read(sockfd, buff, sizeof(buff));
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. // if msg contains "Exit" then server exit, meets search, respond.
@ -76,9 +97,9 @@ char *snet_process_connection(int sockfd)
gen_random_string(randTokenName, 16); gen_random_string(randTokenName, 16);
socket_save = fopen(randTokenName, "wb"); 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); printf("ss:server:client buffer saved as '%s'\n", randTokenName);
fflush(stdout); fflush(stdout);
} }
@ -205,12 +226,12 @@ void snet_toss(char *address, int port, char *string)
while(sockfd != -1) while(sockfd != -1)
{ {
char *buf = malloc(131073); char *buf = malloc(128);
bzero(buf, 131072); bzero(buf, 128);
usleep(500000); usleep(500000);
int listener = read(sockfd, buf, 131072); int listener = read(sockfd, buf, 128);
if(listener < 0) if(listener < 0)
{ {