fix logs being spammed with newlines after other party ends session

This commit is contained in:
2026-03-18 16:50:58 -05:00
parent bfe1ef98d4
commit 099ec012a2
2 changed files with 27 additions and 11 deletions

View File

@@ -24,10 +24,12 @@ closeClient()
gettimeofday(&end1, NULL);
close(clientSocketDescriptor);
printf("********Session********");
printf("Bytes written: %i\nBytes read: %i\n", bytesWritten, bytesRead);
printf("Elapsed time: %ld\n secs\n", e);
printf("Connection closed...\n");
puts("********Session********");
printf("Bytes written: %i\n", bytesWritten);
printf("Bytes read: %i\n", bytesRead);
printf("Elapsed time: %ld secs\n", e);
puts("Connection closed.");
}
void *
@@ -37,6 +39,7 @@ pollForSever(void *args)
int socketDescriptor = (int)aaa->auxInt;
char msg[1024];
while (1) {
server_message_loop:
memset(&msg, 0, sizeof(msg)); // clear the buffer
bytesRead += recv(socketDescriptor, (char *)&msg, sizeof(msg), 0);
@@ -50,12 +53,18 @@ pollForSever(void *args)
// cout << "Server: " << msg << endl;
// printf("Server: %s\n");
if (msg[0] == '\0')
goto server_message_loop;
writeToFile(logFileName, msg);
if (linesInFile(logFileName) > LOG_LENGTH)
linePos++;
displayFile(logFileName, linePos, LOG_LENGTH);
}
return nullptr;
}
void

View File

@@ -1,3 +1,4 @@
#include <cstdio>
#include <curses.h>
#include <netinet/in.h>
#include <pthread.h>
@@ -40,14 +41,19 @@ pollForClient()
{
char msg[1024];
while (1) {
client_message_loop:
// receive a message from the client (listen)
memset(&msg, 0, sizeof(msg)); // clear the buffer
bytesRead += recv(clientSocketDescriptor, (char *)&msg, sizeof(msg), 0);
writeToFile(logFileName,
msg); // write the client's message to file
if (msg[0] == '\0')
goto client_message_loop;
writeToFile(logFileName, msg);
if (linesInFile(logFileName) > LOG_LENGTH)
linePos++;
displayFile(logFileName, linePos, LOG_LENGTH);
}
@@ -117,8 +123,9 @@ closeServer()
close(serverSocketDescriptor);
/* Don't just die silently */
printf("********Session********\n");
printf("Bytes written: %i\nBytes Read: %i\n", bytesWritten, bytesRead);
printf("Elapsed time: %ld\n secs\n", e);
printf("Connection closed...\n");
puts("********Session********");
printf("Bytes written: %i\n", bytesWritten);
printf("Bytes read: %i\n", bytesRead);
printf("Elapsed time: %ld secs\n", e);
puts("Connection closed.");
}