Added independent output thread.
This commit is contained in:
parent
258fd49653
commit
751a734016
|
@ -108,4 +108,6 @@ SilverMUDServer
|
||||||
SilverMUDClient
|
SilverMUDClient
|
||||||
config.h
|
config.h
|
||||||
config.h.in
|
config.h.in
|
||||||
stamp-h1
|
stamp-h1
|
||||||
|
|
||||||
|
build/
|
|
@ -1,5 +1,7 @@
|
||||||
bin_PROGRAMS = SilverMUDServer SilverMUDClient
|
bin_PROGRAMS = SilverMUDServer SilverMUDClient
|
||||||
dist_doc_DATA = README.org
|
dist_doc_DATA = README.org
|
||||||
|
schemedir = $(pkgdatadir)/scheme
|
||||||
|
dist_scheme_DATA = lisp
|
||||||
SilverMUDServer_CFLAGS = -lgnutls -g $(GUILE_CFLAGS) $(GUILE_LIBS)
|
SilverMUDServer_CFLAGS = -lgnutls -g $(GUILE_CFLAGS) $(GUILE_LIBS)
|
||||||
SilverMUDClient_CFLAGS = -lgnutls -g -lncurses $(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])
|
AM_INIT_AUTOMAKE([-Wall -Werror foreign subdir-objects])
|
||||||
AC_PROG_CC
|
AC_PROG_CC
|
||||||
AC_CONFIG_HEADERS([source/config.h])
|
AC_CONFIG_HEADERS([source/config.h])
|
||||||
AC_CONFIG_FILES([
|
AC_CONFIG_FILES([Makefile])
|
||||||
Makefile
|
|
||||||
])
|
|
||||||
PKG_CHECK_MODULES([GUILE], [guile-3.0])
|
PKG_CHECK_MODULES([GUILE], [guile-3.0])
|
||||||
AC_OUTPUT
|
AC_OUTPUT
|
||||||
|
|
|
@ -205,6 +205,10 @@ int main (int argc, char ** argv)
|
||||||
scm_c_define_gsubr("push-output-message", 6, 0, 0, &push_output_message);
|
scm_c_define_gsubr("push-output-message", 6, 0, 0, &push_output_message);
|
||||||
scm_c_define("*globalPlayerList*", scm_from_pointer(globalPlayerList, NULL));
|
scm_c_define("*globalPlayerList*", scm_from_pointer(globalPlayerList, NULL));
|
||||||
scm_c_define("*globalOutputQueue*", scm_from_pointer(globalOutputQueue, 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:
|
// Start a REPL thread:
|
||||||
//pthread_t schemeREPLThread;
|
//pthread_t schemeREPLThread;
|
||||||
|
@ -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:
|
// Wait for all other threads to terminate:
|
||||||
|
|
|
@ -6,8 +6,39 @@
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
|
#include "player-data.h"
|
||||||
#include "output-queue.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()
|
struct OutputQueue * const createOutputQueue()
|
||||||
{
|
{
|
||||||
// Allocate a new queue:
|
// Allocate a new queue:
|
||||||
|
|
|
@ -28,6 +28,8 @@ struct OutputQueue
|
||||||
struct OutputMessage * front, * back;
|
struct OutputMessage * front, * back;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
void * outputThreadHandler(void * outputQueue);
|
||||||
|
|
||||||
struct OutputQueue * const createOutputQueue();
|
struct OutputQueue * const createOutputQueue();
|
||||||
|
|
||||||
size_t pushOutputMessage(struct OutputQueue * const queue,
|
size_t pushOutputMessage(struct OutputQueue * const queue,
|
||||||
|
|
Loading…
Reference in New Issue