Added independent output thread.
This commit is contained in:
parent
258fd49653
commit
751a734016
|
@ -109,3 +109,5 @@ SilverMUDClient
|
|||
config.h
|
||||
config.h.in
|
||||
stamp-h1
|
||||
|
||||
build/
|
|
@ -1,5 +1,7 @@
|
|||
bin_PROGRAMS = SilverMUDServer SilverMUDClient
|
||||
dist_doc_DATA = README.org
|
||||
schemedir = $(pkgdatadir)/scheme
|
||||
dist_scheme_DATA = lisp
|
||||
SilverMUDServer_CFLAGS = -lgnutls -g $(GUILE_CFLAGS) $(GUILE_LIBS)
|
||||
SilverMUDClient_CFLAGS = -lgnutls -g -lncurses $(GUILE_CFLAGS) $(GUILE_LIBS)
|
||||
|
||||
|
|
|
@ -2,8 +2,6 @@ AC_INIT([SilverMUD], [0.0.1], [barra@ocathain.ie])
|
|||
AM_INIT_AUTOMAKE([-Wall -Werror foreign subdir-objects])
|
||||
AC_PROG_CC
|
||||
AC_CONFIG_HEADERS([source/config.h])
|
||||
AC_CONFIG_FILES([
|
||||
Makefile
|
||||
])
|
||||
AC_CONFIG_FILES([Makefile])
|
||||
PKG_CHECK_MODULES([GUILE], [guile-3.0])
|
||||
AC_OUTPUT
|
||||
|
|
|
@ -206,6 +206,10 @@ int main (int argc, char ** argv)
|
|||
scm_c_define("*globalPlayerList*", scm_from_pointer(globalPlayerList, NULL));
|
||||
scm_c_define("*globalOutputQueue*", scm_from_pointer(globalOutputQueue, NULL));
|
||||
|
||||
// Start an output thread:
|
||||
pthread_t outputThread;
|
||||
pthread_create(&outputThread, NULL, outputThreadHandler, (void *)globalOutputQueue);
|
||||
|
||||
// Start a REPL thread:
|
||||
//pthread_t schemeREPLThread;
|
||||
//pthread_create(&schemeREPLThread, NULL, schemeREPLHandler, NULL);
|
||||
|
@ -334,28 +338,6 @@ int main (int argc, char ** argv)
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Output the queue:
|
||||
struct OutputMessage * currentMessage = NULL;
|
||||
while (globalOutputQueue->count != 0)
|
||||
{
|
||||
currentMessage = popOutputMessage(globalOutputQueue);
|
||||
struct PlayerListNode * currentPlayerNode = currentMessage->recepients->head;
|
||||
|
||||
while (currentPlayerNode != NULL)
|
||||
{
|
||||
gnutls_record_send(*currentPlayerNode->player->connection->tlsSession,
|
||||
currentMessage->message, sizeof(struct ServerToClientMessage));
|
||||
currentPlayerNode = currentPlayerNode->next;
|
||||
}
|
||||
|
||||
if (currentMessage->deallocatePlayerList == true)
|
||||
{
|
||||
deallocatePlayerList(¤tMessage->recepients);
|
||||
}
|
||||
|
||||
deallocateOutputMessage(¤tMessage);
|
||||
}
|
||||
}
|
||||
|
||||
// Wait for all other threads to terminate:
|
||||
|
|
|
@ -6,8 +6,39 @@
|
|||
#include <string.h>
|
||||
#include <stdbool.h>
|
||||
#include <pthread.h>
|
||||
#include "player-data.h"
|
||||
#include "output-queue.h"
|
||||
|
||||
// A thread handler for constantly outputting messages from an output queue:
|
||||
void * outputThreadHandler(void * outputQueue)
|
||||
{
|
||||
struct OutputQueue * queue = (struct OutputQueue *)outputQueue;
|
||||
struct OutputMessage * currentMessage = NULL;
|
||||
|
||||
while (true)
|
||||
{
|
||||
currentMessage = popOutputMessage(queue);
|
||||
if (currentMessage != NULL)
|
||||
{
|
||||
struct PlayerListNode * currentPlayerNode = currentMessage->recepients->head;
|
||||
|
||||
while (currentPlayerNode != NULL)
|
||||
{
|
||||
gnutls_record_send(*currentPlayerNode->player->connection->tlsSession,
|
||||
currentMessage->message, sizeof(struct ServerToClientMessage));
|
||||
currentPlayerNode = currentPlayerNode->next;
|
||||
}
|
||||
|
||||
if (currentMessage->deallocatePlayerList == true)
|
||||
{
|
||||
deallocatePlayerList(¤tMessage->recepients);
|
||||
}
|
||||
|
||||
deallocateOutputMessage(¤tMessage);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct OutputQueue * const createOutputQueue()
|
||||
{
|
||||
// Allocate a new queue:
|
||||
|
|
|
@ -28,6 +28,8 @@ struct OutputQueue
|
|||
struct OutputMessage * front, * back;
|
||||
};
|
||||
|
||||
void * outputThreadHandler(void * outputQueue);
|
||||
|
||||
struct OutputQueue * const createOutputQueue();
|
||||
|
||||
size_t pushOutputMessage(struct OutputQueue * const queue,
|
||||
|
|
Loading…
Reference in New Issue