Commit f366c0b86550e9f790b26b6115af63625b4e1e21

Authored by Georg Hopp
1 parent b4b1c4f1

add testserver and did some fixes not shown by my incomplete tests

  1 +2012-01-18 07:52:07 +0100 Georg Hopp
  2 +
  3 + * add testserver and did some fixes not shown by my incomplete tests (HEAD, master)
  4 +
  5 +2012-01-17 15:40:07 +0100 Georg Hopp
  6 +
  7 + * more notes
  8 +
  9 +2012-01-17 15:04:33 +0100 Georg Hopp
  10 +
  11 + * add some thought
  12 +
  13 +2012-01-17 14:49:49 +0100 Georg Hopp
  14 +
  15 + * changed from select(UNIX) to poll(POSIX)
  16 +
  17 +2012-01-16 18:39:01 +0100 Georg Hopp
  18 +
  19 + * work on server_run
  20 +
  21 +2012-01-16 17:05:57 +0100 Georg Hopp
  22 +
  23 + * move test under docs dir
  24 +
  25 +2012-01-16 17:05:08 +0100 Georg Hopp
  26 +
  27 + * simply copy signal handling code from gameserver project
  28 +
  29 +2012-01-16 16:04:11 +0100 Georg Hopp
  30 +
  31 + * more work on socket handling stuff... @TODO think about renaming it to connection as it only handles TCP sockets
  32 +
  33 +2012-01-16 13:48:05 +0100 Georg Hopp
  34 +
  35 + * add info text about file handle passing and ported more stuff from my old server structure
  36 +
  37 +2012-01-16 08:05:15 +0100 Georg Hopp
  38 +
  39 + * reflect changes in configure.ac
  40 +
  41 +2012-01-13 22:46:45 +0100 Georg Hopp
  42 +
  43 + * add daemonize code from other project. (Might be integrated in a future class but i am not sure right now
  44 +
  45 +2012-01-13 22:16:17 +0100 Georg Hopp
  46 +
  47 + * logger now works and has some basic testing
  48 +
  49 +2012-01-13 22:15:03 +0100 Georg Hopp
  50 +
  51 + * change cclass so that the internal structure is no longer visible by the rest of the code
  52 +
  53 +2012-01-13 16:06:02 +0100 Georg Hopp
  54 +
  55 + * some fixes on first logger tests
  56 +
  57 +2012-01-13 15:54:22 +0100 Georg Hopp
  58 +
  59 + * initial checkin
  60 +
... ...
... ... @@ -7,4 +7,4 @@ ACLOCAL_AMFLAGS = -I m4
7 7 #
8 8 #EXTRA_DIST = base64.h
9 9
10   -SUBDIRS = tests
  10 +SUBDIRS = src tests
... ...
... ... @@ -35,5 +35,5 @@ AC_TYPE_SIZE_T
35 35 #AC_FUNC_MALLOC
36 36 AC_CHECK_FUNCS([memset])
37 37
38   -AC_CONFIG_FILES([Makefile tests/Makefile])
  38 +AC_CONFIG_FILES([Makefile src/Makefile tests/Makefile])
39 39 AC_OUTPUT
... ...
... ... @@ -10,7 +10,15 @@
10 10
11 11 #define POLL_FD_NSIZE 1024
12 12 #define POLL_FD_SIZE (sizeof(struct pollfd) * POLL_FD_NSIZE)
13   -#define POLL_FD_MOVE(idx) (sizeof(struct pollfd) * (POLL_FD_NSIZE-(idx)+1))
  13 +
  14 +#define MOVE_SIZE(size,idx) ((size) * (POLL_FD_NSIZE-((idx)+1)))
  15 +#define CLEAR_CONN(server,idx) \
  16 + memmove(&(((server)->fds)[(idx)]), \
  17 + &(((server)->fds)[(idx)+1]), \
  18 + MOVE_SIZE(sizeof(((server)->fds)[0]),(idx))); \
  19 + memmove(&(((server)->conns)[(idx)]), \
  20 + &(((server)->conns)[(idx)+1]), \
  21 + MOVE_SIZE(sizeof(((server)->conns)[0]),(idx)))
14 22
15 23
16 24 typedef void (*server_read_hook)(const char *);
... ...
  1 +ACLOCAL_AMFLAGS = -I m4
  2 +
  3 +CCLASS = cclass.c
  4 +SOCKET = socket.c socket/accept.c socket/connect.c socket/listen.c
  5 +SERVER = server.c server/run.c server/close_conn.c
  6 +
  7 +bin_PROGRAMS = testserver
  8 +
  9 +testserver_SOURCES = testserver.c $(CCLASS) $(SOCKET) $(SERVER) signalHandling.c logger.c
  10 +testserver_CFLAGS = -Wall -I ../include
... ...
1   -#include "server.h"
  1 +#include <string.h>
2 2
  3 +#include "server.h"
3 4
4 5 void
5 6 server_close_conn(SERVER this, unsigned int i)
6 7 {
7   - memmove(&((this->fds)[i]), &((this->fds)[i+1]), POLL_FD_MOVE(i+1));
8   - this->nfds--;
9 8 delete(&((this->conns)[i].sock));
  9 + CLEAR_CONN(this, i);
  10 + this->nfds--;
10 11 }
11 12
12 13 // vim: set ts=4 sw=4:
... ...
  1 +#include <stdio.h>
  2 +#include <socket.h>
  3 +
  4 +#include "server.h"
  5 +#include "signalHandling.h"
  6 +
  7 +static void
  8 +read_hook(const char * _buffer)
  9 +{
  10 + printf("%s\n", _buffer);
  11 +}
  12 +
  13 +int
  14 +main()
  15 +{
  16 + LOGGER logger = new(LOGGER, NULL);
  17 + SERVER server = new(SERVER, logger, 11212, SOMAXCONN);
  18 +
  19 + server->read_hook = read_hook;
  20 +
  21 + init_signals();
  22 + server_run(server);
  23 +
  24 + delete(&server);
  25 + delete(&logger);
  26 +
  27 + return 0;
  28 +}
  29 +
  30 +// vim: set ts=4 sw=4:
... ...
... ... @@ -7,10 +7,10 @@ check_PROGRAMS = cclassTest loggerTest socketTest serverTest
7 7 COMMON = runtest.c ../src/cclass.c
8 8 CCLASS = $(COMMON) mock/class.c
9 9 LOGGER = $(COMMON) ../src/logger.c
10   -SOCKET = $(LOGGER) ../src/socket.c ../src/socket_listen.c \
11   - ../src/socket_accept.c ../src/socket_connect.c
12   -SERVER = $(SOCKET) ../src/server.c ../src/server_run.c \
13   - ../src/server_close_conn.c ../src/signalHandling.c
  10 +SOCKET = $(LOGGER) ../src/socket.c ../src/socket/listen.c \
  11 + ../src/socket/accept.c ../src/socket/connect.c
  12 +SERVER = $(SOCKET) ../src/server.c ../src/server/run.c \
  13 + ../src/server/close_conn.c ../src/signalHandling.c
14 14
15 15 cclassTest_SOURCES = $(CCLASS) cclassTest.c
16 16 cclassTest_CFLAGS = -Wall -ggdb -O0 -finline-functions -I ../include -I .. -I .
... ...
... ... @@ -2,6 +2,7 @@
2 2 #include <stdlib.h>
3 3 #include <unistd.h>
4 4 #include <signal.h>
  5 +#include <socket.h>
5 6
6 7 #include "runtest.h"
7 8 #include "logger.h"
... ... @@ -10,7 +11,7 @@
10 11 #include "signalHandling.h"
11 12
12 13
13   -#define TEST_PORT 11218
  14 +#define TEST_PORT 11212
14 15 #define TEST_DATA "test"
15 16
16 17
... ... @@ -46,7 +47,7 @@ __setUp()
46 47 logger = new(LOGGER, NULL);
47 48 logger_add(logger, logfnct_mock);
48 49
49   - server = new(SERVER, logger, TEST_PORT);
  50 + server = new(SERVER, logger, TEST_PORT, SOMAXCONN);
50 51
51 52 ASSERT_INSTANCE_OF(SERVER, server);
52 53 ASSERT_INSTANCE_OF(LOGGER, server->logger);
... ...
... ... @@ -8,7 +8,7 @@
8 8 #include "socket.h"
9 9
10 10
11   -#define TEST_PORT 11213
  11 +#define TEST_PORT 11212
12 12
13 13
14 14 int level = -1;
... ...
Please register or login to post a comment