Bug fixes, working toward full dynamic memory allocation
This commit is contained in:
parent
34cdecdb57
commit
42aaea6a17
2
Makefile
2
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
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user