Skip to content

Commit

Permalink
Added write_log commands
Browse files Browse the repository at this point in the history
  • Loading branch information
ncc14003 committed Feb 5, 2020
1 parent 3b5bad7 commit e0a0ecd
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions breadcrumbs/src/comms/AlgorithmServer.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@

#include "AlgorithmServer.hpp"
#include "Logger.h"

//Logger* logger = getLogger();

AlgorithmServer::AlgorithmServer(size_t numClients)
{
Expand All @@ -17,6 +20,7 @@ AlgorithmServer::~AlgorithmServer()

void AlgorithmServer::serverThreadRuntime()
{
Logger* logger = getLogger();
int iResult;
clientThreadsMutex = CreateMutex(NULL, false, NULL);

Expand Down Expand Up @@ -65,6 +69,7 @@ void AlgorithmServer::serverThreadRuntime()

iResult = listen(ListenSocket, SOMAXCONN);
if (iResult == SOCKET_ERROR) {
//write_log("listen failed with error\n", 1, logger->filename, logger);
printf("listen failed with error: %d\n", WSAGetLastError());
closesocket(ListenSocket);
WSACleanup();
Expand All @@ -75,10 +80,17 @@ void AlgorithmServer::serverThreadRuntime()
// Accept a client socket
while (continueThread)
{
Logger* logger = getLogger();
//logger.filename = "log2.txt";
write_log("Listening for clients...\n", 1, logger->filename, logger);
printf("Listening for clients...\n");
ClientSocket = accept(ListenSocket, NULL, NULL);
write_log("Hello new client!\n", 1, logger->filename, logger);
printf("Hello new client!\n");
if (ClientSocket == INVALID_SOCKET) {
write_log("accept failed with error: ", 1, logger->filename, logger);
write_log(std::to_string(WSAGetLastError()), 1, logger->filename, logger);
write_log("\n", 1, logger->filename, logger);
printf("accept failed with error: %d\n", WSAGetLastError());
AcceptFailures++;
if (AcceptFailures >= MAX_ACCEPT_FAILURES)
Expand Down Expand Up @@ -115,6 +127,7 @@ void AlgorithmServer::serverThreadRuntime()
unlockClientThreadsMutex();
}
else {
write_log("Could not acquire mutex to add new client thread\n", 1, logger->filename, logger);
printf("Could not acquire mutex to add new client thread\n");
}
}
Expand All @@ -134,6 +147,7 @@ vector<Attribute>* AlgorithmServer::getAllIncomingAttributes()
Polls DataSyncThreads for new updates
Updates master storage accordingly
*/
Logger* logger = getLogger();
vector<Attribute>* newAttribs = new vector<Attribute>;
if (lockClientThreadsMutex() == STATUS_WAIT_0)
{
Expand All @@ -145,6 +159,7 @@ vector<Attribute>* AlgorithmServer::getAllIncomingAttributes()
unlockClientThreadsMutex();
}
else {
write_log("Could not acquire mutex to add new client thread\n", 1, logger->filename, logger);
printf("Could not acquire mutex to get incoming attributes.\n");
}
return newAttribs;
Expand Down

0 comments on commit e0a0ecd

Please sign in to comment.