Browse Source

now use libtrio for all io operations.

next
Georg Hopp 12 years ago
parent
commit
151a4ebf00
  1. 5
      configure.ac
  2. 6
      include/cbuf.h
  3. 2
      include/http/message.h
  4. 4
      include/http/parser.h
  5. 4
      include/http/writer.h
  6. 9
      include/logger.h
  7. 43
      include/logger/interface/logger.h
  8. 57
      include/logger/logger.h
  9. 20
      include/server.h
  10. 48
      include/socket.h
  11. 10
      include/stream.h
  12. 44
      include/stream/interface/reader.h
  13. 44
      include/stream/interface/writer.h
  14. 49
      include/stream/stream.h
  15. 11
      src/Makefile.am
  16. 6
      src/cbuf/read.c
  17. 6
      src/http/parser.c
  18. 4
      src/http/parser/parse.c
  19. 2
      src/http/response/asset.c
  20. 14
      src/http/worker.c
  21. 4
      src/http/worker/answer.c
  22. 2
      src/http/worker/process.c
  23. 6
      src/http/writer.c
  24. 6
      src/http/writer/write.c
  25. 9
      src/logger/Makefile.am
  26. 58
      src/logger/interface/i_logger.c
  27. 57
      src/logger/logger.c
  28. 39
      src/logger/stderr.c
  29. 52
      src/logger/syslog.c
  30. 8
      src/server/close_conn.c
  31. 29
      src/server/handle_accept.c
  32. 4
      src/server/poll.c
  33. 10
      src/server/read.c
  34. 4
      src/server/run.c
  35. 21
      src/server/server.c
  36. 9
      src/server/write.c
  37. 9
      src/socket/Makefile.am
  38. 57
      src/socket/accept.c
  39. 54
      src/socket/connect.c
  40. 59
      src/socket/listen.c
  41. 37
      src/socket/nonblock.c
  42. 78
      src/socket/socket.c
  43. 13
      src/stream/Makefile.am
  44. 39
      src/stream/interface/reader.c
  45. 40
      src/stream/interface/writer.c
  46. 120
      src/stream/read.c
  47. 62
      src/stream/stream.c
  48. 124
      src/stream/write.c
  49. 22
      src/taskrambler.c
  50. 12
      tests/mock/mock_worker.c
  51. 2
      tests/socketTest.c

5
configure.ac

@ -8,7 +8,7 @@ AC_INIT([taskrambler],
LT_INIT
AM_INIT_AUTOMAKE
#AM_INIT_AUTOMAKE([subdir-objects])
#AM_SILENT_RULES([yes])
AM_SILENT_RULES([yes])
AC_COPYRIGHT([Copyright © 2013 Georg Hopp])
AC_REVISION([m4_esyscmd_s([git describe --always])])
AC_CONFIG_SRCDIR([src/taskrambler.c])
@ -96,11 +96,8 @@ AC_CONFIG_FILES([Makefile
src/hash/Makefile
src/queue/Makefile
src/http/Makefile
src/logger/Makefile
src/server/Makefile
src/session/Makefile
src/socket/Makefile
src/stream/Makefile
src/tree/Makefile
src/application/Makefile
src/storage/Makefile

6
include/cbuf.h

@ -35,7 +35,7 @@
#include <sys/types.h>
#include "trbase.h"
#include "stream.h"
#include "trio.h"
#define ECBUFOVFL 100
@ -53,8 +53,8 @@ TR_CLASS(Cbuf) {
size_t read;
};
ssize_t cbufRead(Cbuf, Stream);
ssize_t cbufWrite(Cbuf, Stream);
ssize_t cbufRead(Cbuf, TR_Stream);
ssize_t cbufWrite(Cbuf, TR_Stream);
char * cbufGetLine(Cbuf, char **);
char * cbufGetData(Cbuf, size_t);

2
include/http/message.h

@ -25,8 +25,8 @@
#define __HTTP_MESSAGE__
#include "trbase.h"
#include "trio.h"
#include "hash.h"
#include "stream.h"
#include "asset.h"
TR_CLASS(HttpMessage) {

4
include/http/parser.h

@ -25,10 +25,10 @@
#define __HTTP_PARSER_H__
#include "trbase.h"
#include "trio.h"
#include "http/message.h"
#include "queue.h"
#include "cbuf.h"
#include "stream.h"
#define PARSER_MAX_BUF 131072
@ -56,7 +56,7 @@ TR_CLASS(HttpParser) {
HttpMessageState state;
};
ssize_t httpParserParse(void *, Stream);
ssize_t httpParserParse(void *, TR_Stream);
void httpParserRequestVars(HttpParser);
void httpParserHeader(HttpParser, const char *, const char *);
void httpParserNewMessage(HttpParser, const char *, const char * lend);

4
include/http/writer.h

@ -27,9 +27,9 @@
#include <sys/types.h>
#include "trbase.h"
#include "trio.h"
#include "http/message.h"
#include "queue.h"
#include "stream.h"
/*
@ -90,7 +90,7 @@ TR_CLASS(HttpWriter) {
HttpWriterState state;
};
ssize_t httpWriterWrite(void *, Stream);
ssize_t httpWriterWrite(void *, TR_Stream);
#endif // __HTTP_WRITER_H__

9
include/logger.h

@ -1,9 +0,0 @@
#ifndef __LOGGER_H__
#define __LOGGER_H__
#include "logger/logger.h"
#include "logger/interface/logger.h"
#endif // __LOGGER_H__
// vim: set ts=4 sw=4:

43
include/logger/interface/logger.h

@ -1,43 +0,0 @@
/**
* \file
* The logger interface.
*
* \author Georg Hopp
*
* \copyright
* Copyright © 2012 Georg Hopp
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __LOGGER_INTERFACE_LOGGER_H__
#define __LOGGER_INTERFACE_LOGGER_H__
#include <stdarg.h>
#include "trbase.h"
#include "logger.h"
typedef void (* fptr_log)(void *, logger_level, const char * const);
TR_INTERFACE(Logger) {
TR_IFID;
fptr_log log;
};
extern void loggerLog(void *, logger_level, const char * const, ...);
#endif // __LOGGER_INTERFACE_LOGGER_H__
// vim: set ts=4 sw=4:

57
include/logger/logger.h

@ -1,57 +0,0 @@
/**
* \file
* A generic logger class and two extended classes, One that logs to
* stderr and one that logs to the system syslog.
*
* \author Georg Hopp
*
* \copyright
* Copyright © 2012 Georg Hopp
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __LOGGER_LOGGER_H__
#define __LOGGER_LOGGER_H__
#include "trbase.h"
typedef enum logger_level {
LOGGER_DEBUG=0,
LOGGER_INFO,
LOGGER_NOTICE,
LOGGER_WARNING,
LOGGER_ERR,
LOGGER_CRIT,
LOGGER_ALERT,
LOGGER_EMERG
} logger_level;
extern const char * const logger_level_str[];
TR_CLASS(Logger) {
logger_level min_level;
};
TR_CLASS(LoggerStderr) {
TR_EXTENDS(Logger);
};
TR_CLASS(LoggerSyslog) {
TR_EXTENDS(Logger);
};
#endif // __LOGGER_LOGGER_H__
// vim: set ts=4 sw=4:

20
include/server.h

@ -32,22 +32,20 @@
#include <openssl/ssl.h>
#include "trbase.h"
#include "socket.h"
#include "logger.h"
#include "stream.h"
#include "trio.h"
struct conns {
Sock sock;
Stream stream;
void * worker;
TR_Sock sock;
TR_Stream stream;
void * worker;
};
TR_CLASS(Server) {
Logger logger;
Sock sock;
Sock sockSSL;
SSL_CTX * ctx;
void * worker;
TR_Logger logger;
TR_Sock sock;
TR_Sock sockSSL;
SSL_CTX * ctx;
void * worker;
nfds_t nfds;
struct pollfd * fds;

48
include/socket.h

@ -1,48 +0,0 @@
/**
* \file
* Abstraction layer above BSD sockets. Capsules and simplifies connect
* accept and listen.
*
* \author Georg Hopp
*
* \copyright
* Copyright © 2012 Georg Hopp
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __SOCKET_H__
#define __SOCKET_H__
#include <arpa/inet.h> // for in_port_t
#include "trbase.h"
#include "logger.h"
TR_CLASS(Sock) {
Logger log;
in_port_t port;
struct sockaddr_in addr;
int handle;
};
void socketConnect(Sock this, const char * addr, char (*)[16]);
void socketListen(Sock this, int backlog);
Sock socketAccept(Sock this, char (*remoteAddr)[16]);
void socketNonblock(Sock this);
#endif // __SOCKET_H__
// vim: set ts=4 sw=4:

10
include/stream.h

@ -1,10 +0,0 @@
#ifndef __STREAM_H__
#define __STREAM_H__
#include "stream/stream.h"
#include "stream/interface/reader.h"
#include "stream/interface/writer.h"
#endif // __STREAM_H__
// vim: set ts=4 sw=4:

44
include/stream/interface/reader.h

@ -1,44 +0,0 @@
/**
* \file
* Interface whose implementations can read from a stream given as
* a handle.
*
* \author Georg Hopp
*
* \copyright
* Copyright © 2012 Georg Hopp
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __STREAM_INTERFACE_READER_H__
#define __STREAM_INTERFACE_READER_H__
#include <sys/types.h>
#include "trbase.h"
#include "stream/stream.h"
typedef ssize_t (* fptr_streamReaderRead)(void *, Stream);
TR_INTERFACE(StreamReader) {
TR_IFID;
fptr_streamReaderRead read;
};
extern ssize_t streamReaderRead(void *, Stream);
#endif // __STREAM_INTERFACE_READER_H__
// vim: set ts=4 sw=4:

44
include/stream/interface/writer.h

@ -1,44 +0,0 @@
/**
* \file
* Interface whose implementations can write from a stream given as
* a handle.
*
* \author Georg Hopp
*
* \copyright
* Copyright © 2012 Georg Hopp
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __STREAM_INTERFACE_WRITER_H__
#define __STREAM_INTERFACE_WRITER_H__
#include <sys/types.h>
#include "trbase.h"
#include "stream/stream.h"
typedef ssize_t (* fptr_streamWriterWrite)(void *, Stream);
TR_INTERFACE(StreamWriter) {
TR_IFID;
fptr_streamWriterWrite write;
};
extern ssize_t streamWriterWrite(void *, Stream);
#endif // __STREAM_INTERFACE_WRITER_H__
// vim: set ts=4 sw=4:

49
include/stream/stream.h

@ -1,49 +0,0 @@
/**
* \file
*
* \author Georg Hopp
*
* \copyright
* Copyright © 2012 Georg Hopp
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __STREAM_STREAM_H__
#define __STREAM_STREAM_H__
#include <sys/types.h>
#include <openssl/ssl.h>
#include "trbase.h"
typedef enum e_StreamHandleType {
STREAM_FD = 0,
STREAM_SSL
} StreamHandleType;
TR_CLASS(Stream) {
StreamHandleType type;
union {
int fd;
SSL * ssl;
} handle;
};
ssize_t streamRead(Stream, void *, size_t);
ssize_t streamWrite(Stream, void *, size_t);
#endif // __STREAM_STREAM_H__
// vim: set ts=4 sw=4:

11
src/Makefile.am

@ -10,14 +10,11 @@ TRUTILS = utils/http.c \
TRCOMMONLIBS = cbuf/libcbuf.la \
hash/libhash.la \
queue/libqueue.la \
logger/liblogger.la \
tree/libtree.la \
stream/libstream.la
tree/libtree.la
TRHTTPSERVER = http/libhttp.la \
asset/libasset.la \
server/libserver.la \
socket/libsocket.la
server/libserver.la
TR = ./application/.libs/libapplication.a \
./user/.libs/libuser.a \
@ -27,7 +24,7 @@ TR = ./application/.libs/libapplication.a \
./config/.libs/libconfig.a \
./router/.libs/librouter.a
TRLIBS = -ltrbase -ltrhashing -ltrutils -ltrhttpserver -ltrcommon
TRLIBS = -ltrbase -ltrhashing -ltrio -ltrutils -ltrhttpserver -ltrcommon
USEDLIBS = -lrt -lssl -lcrypto -lldap -lgdbm -luuid
AM_CFLAGS += -I../include/
@ -54,5 +51,5 @@ taskrambler_LDFLAGS = -Wl,--export-dynamic \
-Wl,--whole-archive,./application/.libs/libapplication.a,--no-whole-archive
SUBDIRS = asset auth cbuf hash queue http \
logger server session socket stream tree application \
server session tree application \
storage user config router

6
src/cbuf/read.c

@ -24,12 +24,12 @@
#include <unistd.h>
#include <errno.h>
#include "trio.h"
#include "cbuf.h"
#include "stream.h"
ssize_t
cbufRead(Cbuf this, Stream st)
cbufRead(Cbuf this, TR_Stream st)
{
size_t rsize = cbufGetFree(this);
ssize_t rrsize;
@ -39,7 +39,7 @@ cbufRead(Cbuf this, Stream st)
return -1;
}
rrsize = streamRead(st, cbufGetWrite(this), rsize);
rrsize = TR_streamRead(st, cbufGetWrite(this), rsize);
if (0 < rrsize) {
cbufIncWrite(this, rrsize);

6
src/http/parser.c

@ -25,7 +25,7 @@
#include <stdarg.h>
#include "trbase.h"
#include "stream.h"
#include "trio.h"
#include "http/parser.h"
#include "queue.h"
#include "http/request.h"
@ -66,7 +66,7 @@ httpParserDtor(void * _this)
}
TR_INIT_IFACE(TR_Class, httpParserCtor, httpParserDtor, NULL);
TR_INIT_IFACE(StreamReader, httpParserParse);
TR_CREATE_CLASS(HttpParser, NULL, TR_IF(TR_Class), TR_IF(StreamReader));
TR_INIT_IFACE(TR_StreamReader, httpParserParse);
TR_CREATE_CLASS(HttpParser, NULL, TR_IF(TR_Class), TR_IF(TR_StreamReader));
// vim: set ts=4 sw=4:

4
src/http/parser/parse.c

@ -23,8 +23,8 @@
#include <stdlib.h>
#include "trbase.h"
#include "trio.h"
#include "cbuf.h"
#include "stream.h"
#include "queue.h"
#include "http/parser.h"
@ -33,7 +33,7 @@
ssize_t
httpParserParse(void * _this, Stream st)
httpParserParse(void * _this, TR_Stream st)
{
HttpParser this = _this;
int cont = 1;

2
src/http/response/asset.c

@ -42,7 +42,7 @@
#include <sys/types.h>
#include "trbase.h"
#include "stream.h"
#include "trio.h"
#include "http/response.h"
#include "http/message.h"
#include "http/header.h"

14
src/http/worker.c

@ -31,7 +31,7 @@
#include <search.h>
#include "trbase.h"
#include "stream.h"
#include "trio.h"
#include "hash.h"
#include "queue.h"
#include "http/worker.h"
@ -116,8 +116,8 @@ httpWorkerClone(void * _this, void * _base)
this->writer = TR_new(HttpWriter);
}
ssize_t httpWorkerProcess(void *, Stream);
ssize_t httpWorkerWrite(void *, Stream);
ssize_t httpWorkerProcess(void *, TR_Stream);
ssize_t httpWorkerWrite(void *, TR_Stream);
static
void
@ -158,8 +158,8 @@ httpWorkerNotify(void * _this)
}
TR_INIT_IFACE(TR_Class, httpWorkerCtor, httpWorkerDtor, httpWorkerClone);
TR_INIT_IFACE(StreamReader, httpWorkerProcess);
TR_INIT_IFACE(StreamWriter, httpWorkerWrite);
TR_INIT_IFACE(TR_StreamReader, httpWorkerProcess);
TR_INIT_IFACE(TR_StreamWriter, httpWorkerWrite);
TR_INIT_IFACE(
TR_Subject,
httpWorkerAttach,
@ -169,8 +169,8 @@ TR_CREATE_CLASS(
HttpWorker,
NULL,
TR_IF(TR_Class),
TR_IF(StreamReader),
TR_IF(StreamWriter),
TR_IF(TR_StreamReader),
TR_IF(TR_StreamWriter),
TR_IF(TR_Subject));
// vim: set ts=4 sw=4:

4
src/http/worker/answer.c

@ -22,12 +22,12 @@
#include <sys/types.h>
#include "trio.h"
#include "http/worker.h"
#include "http/writer.h"
#include "stream.h"
ssize_t
httpWorkerWrite(HttpWorker this, Stream st)
httpWorkerWrite(HttpWorker this, TR_Stream st)
{
return httpWriterWrite(this->writer, st);
}

2
src/http/worker/process.c

@ -48,7 +48,7 @@ void httpWorkerAddComputedHeader(HttpWorker);
extern Config config;
ssize_t
httpWorkerProcess(HttpWorker this, Stream st)
httpWorkerProcess(HttpWorker this, TR_Stream st)
{
ssize_t requests = httpParserParse(this->parser, st);

6
src/http/writer.c

@ -23,7 +23,7 @@
#include <stdarg.h>
#include "trbase.h"
#include "stream.h"
#include "trio.h"
#include "queue.h"
#include "http/writer.h"
@ -56,7 +56,7 @@ httpWriterDtor(void * _this)
}
TR_INIT_IFACE(TR_Class, httpWriterCtor, httpWriterDtor, NULL);
TR_INIT_IFACE(StreamWriter, httpWriterWrite);
TR_CREATE_CLASS(HttpWriter, NULL, TR_IF(TR_Class), TR_IF(StreamWriter));
TR_INIT_IFACE(TR_StreamWriter, httpWriterWrite);
TR_CREATE_CLASS(HttpWriter, NULL, TR_IF(TR_Class), TR_IF(TR_StreamWriter));
// vim: set ts=4 sw=4:

6
src/http/writer/write.c

@ -26,13 +26,13 @@
#include <trbase.h>
#include "http/message.h"
#include "trio.h"
#include "queue.h"
#include "http/writer.h"
#include "stream.h"
ssize_t
httpWriterWrite(void * _this, Stream st)
httpWriterWrite(void * _this, TR_Stream st)
{
HttpWriter this = _this;
@ -94,7 +94,7 @@ httpWriterWrite(void * _this, Stream st)
to_write = (this->nheader + this->nbody) - this->written;
}
written = streamWrite(st, start, to_write);
written = TR_streamWrite(st, start, to_write);
if (written < 0) {
return written;

9
src/logger/Makefile.am

@ -1,9 +0,0 @@
ACLOCAL_AMFLAGS = -I m4
AUTOMAKE_OPTIONS = subdir-objects
AM_CFLAGS += -I../../include/
noinst_LTLIBRARIES = liblogger.la
liblogger_la_SOURCES = interface/i_logger.c logger.c stderr.c syslog.c
liblogger_la_CFLAGS = $(AM_CFLAGS)

58
src/logger/interface/i_logger.c

@ -1,58 +0,0 @@
/**
* \file
*
* \author Georg Hopp
*
* \copyright
* Copyright © 2012 Georg Hopp
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdlib.h>
#include <stdio.h>
#include <stdarg.h>
#include "logger/logger.h"
#include "logger/interface/logger.h"
#include "trbase.h"
TR_CREATE_INTERFACE(Logger, 1);
void
loggerLog(void * _object, logger_level level, const char * const fmt, ...) {
Logger object = _object;
if (level >= object->min_level) {
char * msg = NULL;
size_t msg_size = 0;
va_list params;
va_start(params, fmt);
msg_size = vsnprintf(NULL, msg_size, fmt, params);
va_end(params);
msg = TR_malloc(msg_size + 1);
va_start(params, fmt);
vsnprintf(msg, msg_size + 1, fmt, params);
va_end(params);
TR_CALL(_object, Logger, log, level, msg);
TR_MEM_FREE(msg);
}
}
// vim: set ts=4 sw=4:

57
src/logger/logger.c

@ -1,57 +0,0 @@
/**
* \file
*
* \author Georg Hopp
*
* \copyright
* Copyright © 2012 Georg Hopp
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdarg.h>
#include "trbase.h"
#include "logger/logger.h"
#include "logger/interface/logger.h"
const
char * const
logger_level_str[] = {
"DEBUG",
"INFO",
"NOTICE",
"WARNING",
"ERR",
"CRIT",
"ALERT",
"EMERG"
};
static
int
loggerCtor(void * _this, va_list * params)
{
Logger this = _this;
this->min_level = va_arg(*params, int);
return 0;
}
static void loggerDtor(void * _this) {}
TR_INIT_IFACE(TR_Class, loggerCtor, loggerDtor, NULL);
TR_CREATE_CLASS(Logger, NULL, TR_IF(TR_Class));
// vim: set ts=4 sw=4:

39
src/logger/stderr.c

@ -1,39 +0,0 @@
/**
* \file
*
* \author Georg Hopp
*
* \copyright
* Copyright © 2012 Georg Hopp
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdio.h>
#include "trbase.h"
#include "logger/logger.h"
#include "logger/interface/logger.h"
static
void
logStderr(void * this, logger_level level, const char * const msg)
{
fprintf(stderr, "[%s] %s\n", logger_level_str[level], msg);
}
TR_INIT_IFACE(Logger, logStderr);
TR_CREATE_CLASS(LoggerStderr, Logger, TR_IF(Logger));
// vim: set ts=4 sw=4:

52
src/logger/syslog.c

@ -1,52 +0,0 @@
/**
* \file
*
* \author Georg Hopp
*
* \copyright
* Copyright © 2012 Georg Hopp
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <syslog.h>
#include "trbase.h"
#include "logger/logger.h"
#include "logger/interface/logger.h"
static
const
int syslog_priority[] = {
LOG_USER | LOG_DEBUG,
LOG_USER | LOG_INFO,
LOG_USER | LOG_NOTICE,
LOG_USER | LOG_WARNING,
LOG_USER | LOG_ERR,
LOG_USER | LOG_CRIT,
LOG_USER | LOG_ALERT,
LOG_USER | LOG_EMERG
};
static
void
logSyslog(void * this, logger_level level, const char * const msg)
{
syslog(syslog_priority[level], "[%s] %s", logger_level_str[level], msg);
}
TR_INIT_IFACE(Logger, logSyslog);
TR_CREATE_CLASS(LoggerSyslog, Logger, TR_IF(Logger));
// vim: set ts=4 sw=4:

8
src/server/close_conn.c

@ -24,19 +24,19 @@
#include <string.h>
#include "trbase.h"
#include "trio.h"
#include "server.h"
#include "stream.h"
void
serverCloseConn(Server this, unsigned int i)
{
int fd = (this->fds)[i].fd;
Stream st = (this->conns[fd]).stream;
int fd = (this->fds)[i].fd;
TR_Stream st = (this->conns[fd]).stream;
TR_delete((this->conns)[fd].sock);
TR_delete((this->conns)[fd].worker);
if (NULL != st && STREAM_SSL == st->type) {
if (NULL != st && TR_STREAM_SSL == st->type) {
SSL_shutdown((st->handle).ssl);
SSL_free((st->handle).ssl);
(st->handle).ssl = NULL;

29
src/server/handle_accept.c

@ -27,31 +27,30 @@
#include <openssl/ssl.h>
#include "trbase.h"
#include "trio.h"
#include "http/worker.h"
#include "server.h"
#include "logger.h"
#include "stream.h"
int
serverHandleAccept(Server this, unsigned int i)
{
char remoteAddr[16] = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0";
Sock acc = NULL;
Stream st;
char remoteAddr[16] = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0";
TR_Sock acc = NULL;
TR_Stream st;
if (this->nfds >= this->max_fds) {
return -1;
}
acc = socketAccept((0 == i)? this->sock : this->sockSSL, &remoteAddr);
acc = TR_socketAccept((0 == i)? this->sock : this->sockSSL, &remoteAddr);
if (NULL != acc && -1 != acc->handle) {
socketNonblock(acc);
TR_socketNonblock(acc);
switch(i) {
case 0:
// no SSL
st = TR_new(Stream, STREAM_FD, acc->handle);
st = TR_new(TR_Stream, TR_STREAM_FD, acc->handle);
break;
case 1:
@ -60,7 +59,7 @@ serverHandleAccept(Server this, unsigned int i)
SSL * ssl = SSL_new(this->ctx);
SSL_set_fd(ssl, acc->handle);
SSL_accept(ssl);
st = TR_new(Stream, STREAM_SSL, ssl);
st = TR_new(TR_Stream, TR_STREAM_SSL, ssl);
}
break;
@ -85,15 +84,15 @@ serverHandleAccept(Server this, unsigned int i)
switch(errno) {
case EAGAIN|EWOULDBLOCK:
case EINTR:
loggerLog(this->logger,
LOGGER_DEBUG,
TR_loggerLog(this->logger,
TR_LOGGER_DEBUG,
"server accept blocks");
return -1;
break;
default:
loggerLog(this->logger,
LOGGER_DEBUG,
TR_loggerLog(this->logger,
TR_LOGGER_DEBUG,
"server accept error");
return -2;
break;
@ -101,8 +100,8 @@ serverHandleAccept(Server this, unsigned int i)
}
if (0 == this->nfds%200) {
loggerLog(this->logger,
LOGGER_DEBUG, "paralel connections: %lu", this->nfds);
TR_loggerLog(this->logger,
TR_LOGGER_DEBUG, "paralel connections: %lu", this->nfds);
}
return acc->handle;

4
src/server/poll.c

@ -24,7 +24,7 @@
#include <errno.h>
#include "server.h"
#include "logger.h"
#include "trio.h"
#include "utils/signalHandling.h"
@ -69,7 +69,7 @@ serverPoll(Server this) {
// DROP THROUGH
case EINTR:
loggerLog(this->logger, LOGGER_CRIT,
TR_loggerLog(this->logger, TR_LOGGER_CRIT,
"poll systemcall failed: [%s] - service terminated",
strerror(errno));
}

10
src/server/read.c

@ -23,9 +23,7 @@
#include <errno.h>
#include "server.h"
#include "logger.h"
#include "stream.h"
#include "trio.h"
ssize_t
serverRead(Server this, unsigned int i)
@ -33,14 +31,14 @@ serverRead(Server this, unsigned int i)
int fd = (this->fds)[i].fd;
if (NULL == (this->conns)[fd].worker) {
loggerLog(
TR_loggerLog(
this->logger,
LOGGER_INFO,
TR_LOGGER_INFO,
"initialization error: NULL reader");
return -2;
}
return streamReaderRead(
return TR_streamReaderRead(
(this->conns)[fd].worker,
(this->conns)[fd].stream);
}

4
src/server/run.c

@ -21,7 +21,7 @@
*/
#include "server.h"
#include "logger.h"
#include "trio.h"
#include "utils/signalHandling.h"
@ -37,7 +37,7 @@ serverRun(Server this)
{
int events = 0;
loggerLog(this->logger, LOGGER_INFO, "service started");
TR_loggerLog(this->logger, TR_LOGGER_INFO, "service started");
while (!doShutdown) //! until error or signal
{

21
src/server/server.c

@ -28,9 +28,8 @@
#include <openssl/err.h>
#include "trbase.h"
#include "trio.h"
#include "server.h"
#include "socket.h"
#include "logger.h"
void serverCloseConn(Server, unsigned int);
@ -53,24 +52,24 @@ serverCtor(void * _this, va_list * params)
}
this->max_fds -= 10;
this->logger = va_arg(* params, Logger);
this->logger = va_arg(* params, TR_Logger);
this->worker = va_arg(* params, void *);
port = va_arg(* params, int);
backlog = va_arg(* params, unsigned int);
loggerLog(this->logger,
LOGGER_INFO,
TR_loggerLog(this->logger,
TR_LOGGER_INFO,
"accept up to %zu connections",
this->max_fds);
this->fds = TR_calloc(sizeof(struct pollfd), this->max_fds);
this->conns = TR_calloc(sizeof(struct conns), this->max_fds);
this->sock = TR_new(Sock, this->logger, port);
socketNonblock(this->sock);
this->sock = TR_new(TR_Sock, this->logger, port);
TR_socketNonblock(this->sock);
this->sockSSL = TR_new(Sock, this->logger, port+1);
socketNonblock(this->sockSSL);
this->sockSSL = TR_new(TR_Sock, this->logger, port+1);
TR_socketNonblock(this->sockSSL);
SSL_library_init();
OpenSSL_add_all_algorithms();
@ -89,8 +88,8 @@ serverCtor(void * _this, va_list * params)
CONFIGDIR "/taskrambler.pem",
SSL_FILETYPE_PEM);
socketListen(this->sock, backlog);
socketListen(this->sockSSL, backlog);
TR_socketListen(this->sock, backlog);
TR_socketListen(this->sockSSL, backlog);
(this->fds)[0].fd = this->sock->handle;
(this->fds)[0].events = POLLIN;

9
src/server/write.c

@ -23,8 +23,7 @@
#include <errno.h>
#include "server.h"
#include "logger.h"
#include "stream.h"
#include "trio.h"
ssize_t
serverWrite(Server this, unsigned int i)
@ -32,14 +31,14 @@ serverWrite(Server this, unsigned int i)
int fd = (this->fds)[i].fd;
if (NULL == (this->conns)[fd].worker) {
loggerLog(
TR_loggerLog(
this->logger,
LOGGER_INFO,
TR_LOGGER_INFO,
"initialization error: NULL worker");
return -2;
}
return streamWriterWrite(
return TR_streamWriterWrite(
(this->conns)[fd].worker,
(this->conns)[fd].stream);
}

9
src/socket/Makefile.am

@ -1,9 +0,0 @@
ACLOCAL_AMFLAGS = -I m4
AUTOMAKE_OPTIONS = subdir-objects
AM_CFLAGS += -I../../include/
noinst_LTLIBRARIES = libsocket.la
libsocket_la_SOURCES = socket.c accept.c connect.c listen.c nonblock.c
libsocket_la_CFLAGS = $(AM_CFLAGS)

57
src/socket/accept.c

@ -1,57 +0,0 @@
/**
* \file
*
* \author Georg Hopp
*
* \copyright
* Copyright © 2012 Georg Hopp
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <errno.h> // for errno
#include <unistd.h>
#include <fcntl.h>
#include "trbase.h"
#include "socket.h"
#include "logger.h"
Sock
socketAccept(Sock this, char (*remoteAddr)[16])
{
Sock sock; // Socket for client
unsigned int len; // Length of client address data structure
// Set the size of the in-out parameter
len = sizeof(this->addr);
sock = TR_new(Sock, this->log, -1);
// Wait for a client to connect
sock->handle = accept(this->handle, (struct sockaddr *) &(sock->addr), &len);
if (-1 == sock->handle) {
loggerLog(this->log, LOGGER_WARNING,
"error accepting connection: %s", strerror(errno));
} else {
strcpy(*remoteAddr, inet_ntoa((sock->addr).sin_addr));
//loggerLog(this->log, LOGGER_INFO,
// "handling client %s\n", inet_ntoa((sock->addr).sin_addr));
}
return sock;
}
// vim: set ts=4 sw=4:

54
src/socket/connect.c

@ -1,54 +0,0 @@
/**
* \file
*
* \author Georg Hopp
*
* \copyright
* Copyright © 2012 Georg Hopp
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdlib.h> // for atoi() and exit()
#include <errno.h> // for errno
#include "socket.h"
#include "logger.h"
void
socketConnect(Sock this, const char * addr, char (*remoteAddr)[16])
{
inet_pton(AF_INET, addr, &((this->addr).sin_addr));
(this->addr).sin_family = AF_INET; // Internet address family
(this->addr).sin_port = htons(this->port); // Local port
if (-1 == connect(
this->handle,
(struct sockaddr*) &(this->addr),
sizeof(this->addr)))
{
loggerLog(this->log, LOGGER_CRIT,
"error connection socket: %s - service terminated",
strerror(errno));
exit(EXIT_FAILURE);
} else {
strcpy(*remoteAddr, inet_ntoa((this->addr).sin_addr));
loggerLog(this->log, LOGGER_INFO,
"handling connection %s\n", inet_ntoa((this->addr).sin_addr));
}
}
// vim: set ts=4 sw=4:

59
src/socket/listen.c

@ -1,59 +0,0 @@
/**
* \file
*
* \author Georg Hopp
*
* \copyright
* Copyright © 2012 Georg Hopp
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdlib.h> // for atoi() and exit()
#include <errno.h> // for errno
#include "socket.h"
#include "logger.h"
void
socketListen(Sock this, int backlog)
{
(this->addr).sin_family = AF_INET; // Internet address family
(this->addr).sin_addr.s_addr = htonl(INADDR_ANY); // Any incoming interface
//(this->addr).sin_addr.s_addr = inet_addr("127.0.0.1"); // Any incoming interface
(this->addr).sin_port = htons(this->port); // Local port
/**
* Bind to the local address
*/
if (-1 == bind(this->handle, (struct sockaddr *) &(this->addr), sizeof(this->addr))) {
loggerLog(this->log, LOGGER_CRIT,
"error binding socket: %s - service terminated",
strerror(errno));
exit(EXIT_FAILURE);
}
/**
* Mark the socket so it will listen for incoming connections
*/
if (-1 == listen(this->handle, backlog)) {
loggerLog(this->log, LOGGER_CRIT,
"error binding socket: %s - service terminated",
strerror(errno));
exit(EXIT_FAILURE);
}
}
// vim: set ts=4 sw=4:

37
src/socket/nonblock.c

@ -1,37 +0,0 @@
/**
* \file
*
* \author Georg Hopp
*
* \copyright
* Copyright © 2012 Georg Hopp
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <errno.h> // for errno
#include <unistd.h>
#include <fcntl.h>
#include "socket.h"
#include "logger.h"
void
socketNonblock(Sock this)
{
int flags = fcntl(this->handle, F_GETFL, 0);
fcntl(this->handle, F_SETFL, flags | O_NONBLOCK);
}
// vim: set ts=4 sw=4:

78
src/socket/socket.c

@ -1,78 +0,0 @@
/**
* \file
*
* \author Georg Hopp
*
* \copyright
* Copyright © 2012 Georg Hopp
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <errno.h>
#include <stdlib.h>
#include <unistd.h>
#include "socket.h"
#include "logger.h"
#include "trbase.h"
static
int
socketCtor(void * _this, va_list * params)
{
Sock this = _this;
int reUse = 1; //! \todo make this configurable
int port;
this->log = va_arg(* params, Logger);
port = va_arg(* params, int);
//! if port is -1 do not initialize the socket. (Used with accept)
if (-1 == port) {
return 0;
} else {
this->port = port;
}
//! Create socket for incoming connections
if (-1 == (this->handle = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP))) {
loggerLog(this->log, LOGGER_CRIT,
"error opening socket: %s - service terminated",
strerror(errno));
return -1;
}
//! Make the socket REUSE a TIME_WAIT socket
setsockopt(this->handle, SOL_SOCKET, SO_REUSEADDR, &reUse, sizeof(reUse));
return 0;
}
static
void
socketDtor(void * _this)
{
Sock this = _this;
if (STDERR_FILENO < this->handle) {
shutdown(this->handle, SHUT_RDWR);
close(this->handle);
}
}
TR_INIT_IFACE(TR_Class, socketCtor, socketDtor, NULL);
TR_CREATE_CLASS(Sock, NULL, TR_IF(TR_Class));
// vim: set ts=4 sw=4:

13
src/stream/Makefile.am

@ -1,13 +0,0 @@
ACLOCAL_AMFLAGS = -I m4
AUTOMAKE_OPTIONS = subdir-objects
STREAM = stream.c read.c write.c
IFACE = interface/reader.c \
interface/writer.c
AM_CFLAGS += -I../../include/
noinst_LTLIBRARIES = libstream.la
libstream_la_SOURCES = $(STREAM) $(IFACE)
libstream_la_CFLAGS = $(AM_CFLAGS)

39
src/stream/interface/reader.c

@ -1,39 +0,0 @@
/**
* \file
*
* \author Georg Hopp
*
* \copyright
* Copyright © 2012 Georg Hopp
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "trbase.h"
#include "stream/stream.h"
#include "stream/interface/reader.h"
TR_CREATE_INTERFACE(StreamReader, 1);
ssize_t
streamReaderRead(void * object, Stream st)
{
ssize_t ret;
TR_RETCALL(object, StreamReader, read, ret, st);
return ret;
}
// vim: set ts=4 sw=4:

40
src/stream/interface/writer.c

@ -1,40 +0,0 @@
/**
* \file
*
* \author Georg Hopp
*
* \copyright
* Copyright © 2012 Georg Hopp
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "trbase.h"
#include "stream/stream.h"
#include "stream/interface/writer.h"
TR_CREATE_INTERFACE(StreamWriter, 1);
ssize_t
streamWriterWrite(void * object, Stream st)
{
ssize_t ret;
TR_RETCALL(object, StreamWriter, write, ret, st);
return ret;
}
// vim: set ts=4 sw=4:

120
src/stream/read.c

@ -1,120 +0,0 @@
/**
* \file
*
* \author Georg Hopp
*
* \copyright
* Copyright © 2012 Georg Hopp
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <openssl/err.h>
#include <openssl/ssl.h>
#include <unistd.h>
#include <errno.h>
#include "stream.h"
#include "logger.h"
extern Logger logger;
ssize_t
streamRead(Stream this, void * buf, size_t count)
{
ssize_t done;
switch(this->type) {
ssize_t _read;
case STREAM_FD:
_read = read((this->handle).fd, buf, count);
if (_read < 0) {
switch (errno) {
case EINTR:
case ENOMEM:
done = 0;
break;
case (EAGAIN|EWOULDBLOCK):
done = -1;
break;
default:
done = -2;
break;
}
} else if (_read == 0) {
done = -2;
} else {
done = _read;
}
break;
case STREAM_SSL:
done = SSL_read((this->handle).ssl, buf, count);
if (0 == done) {
done = -2;
} else if (0 > done) {
switch (SSL_get_error((this->handle).ssl, done)) {
case SSL_ERROR_SYSCALL:
{
switch (errno) {
case EINTR:
case ENOBUFS:
case ENOMEM:
done = 0;
break;
case (EAGAIN|EWOULDBLOCK):
done = -1;
break;
default:
done = -1;
break;
}
}
break;
case SSL_ERROR_SSL:
{
unsigned long err;
while (0 != (err = ERR_get_error())) {
loggerLog(
logger,
LOGGER_DEBUG,
ERR_error_string(err, NULL));
}
}
// DROP THROUGH
case SSL_ERROR_ZERO_RETURN:
done = -2;
break;
}
}
break;
default:
done = -2;
break;
}
return done;
}
// vim: set ts=4 sw=4:

62
src/stream/stream.c

@ -1,62 +0,0 @@
/**
* \file
*
* \author Georg Hopp
*
* \copyright
* Copyright © 2012 Georg Hopp
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdarg.h>
#include <openssl/ssl.h>
#include "trbase.h"
#include "stream/stream.h"
static
int
streamCtor(void * _this, va_list * params)
{
Stream this = _this;
this->type = va_arg(* params, StreamHandleType);
switch(this->type) {
case STREAM_FD:
(this->handle).fd = va_arg(* params, int);
break;
case STREAM_SSL:
(this->handle).ssl = va_arg(* params, SSL*);
break;
default:
return -1;
}
return 0;
}
static
void
streamDtor(void * _this)
{
}
TR_INIT_IFACE(TR_Class, streamCtor, streamDtor, NULL);
TR_CREATE_CLASS(Stream, NULL, TR_IF(TR_Class));
// vim: set ts=4 sw=4:

124
src/stream/write.c

@ -1,124 +0,0 @@
/**
* \file
*
* \author Georg Hopp
*
* \copyright
* Copyright © 2012 Georg Hopp
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <openssl/err.h>
#include <openssl/ssl.h>
#include <unistd.h>
#include <errno.h>
#include "stream.h"
#include "logger.h"
extern Logger logger;
ssize_t
streamWrite(Stream this, void * buf, size_t count)
{
ssize_t done;
switch(this->type) {
ssize_t written;
case STREAM_FD:
written = write((this->handle).fd, buf, count);
if (written < 0) {
switch (errno) {
case EINTR:
case ENOBUFS:
case ENOMEM:
done = 0;
break;
case (EAGAIN|EWOULDBLOCK):
done = -1;
break;
default:
done = -2;
break;
}
} else {
done = written;
}
break;
case STREAM_SSL:
/**
* \todo I got a segfault in this call under unclear
* circumstances. Most likely it has to do with a
* write on a closed connection.
*/
done = SSL_write((this->handle).ssl, buf, count);
if (0 == done) {
done = -2;
} else if (0 > done) {
switch (SSL_get_error((this->handle).ssl, done)) {
case SSL_ERROR_SYSCALL:
{
switch (errno) {
case EINTR:
case ENOBUFS:
case ENOMEM:
done = 0;
break;
case (EAGAIN|EWOULDBLOCK):
done = -1;
break;
default:
done = -2;
break;
}
}
break;
case SSL_ERROR_SSL:
{
unsigned long err;
while (0 != (err = ERR_get_error())) {
loggerLog(
logger,
LOGGER_DEBUG,
ERR_error_string(err, NULL));
}
}
// DROP THROUGH
case SSL_ERROR_ZERO_RETURN:
done = -2;
break;
}
}
break;
default:
done = -2;
break;
}
return done;
}
// vim: set ts=4 sw=4:

22
src/taskrambler.c

@ -38,9 +38,9 @@
#include <trbase.h>
#include <trhash.h>
#include <trio.h>
#include "server.h"
#include "logger.h"
#include "http/worker.h"
#include "auth.h"
#include "application/application.h"
@ -48,8 +48,6 @@
#include "config/config.h"
#include "config/value.h"
#include "logger.h"
#include "utils/signalHandling.h"
#include "utils/mime_type.h"
@ -63,8 +61,8 @@ void nullhandler() {}
void daemonize(void);
Logger logger;
Config config;
TR_Logger logger;
Config config;
int
main()
@ -77,15 +75,15 @@ main()
int shm;
struct randval * value;
logger = TR_new(LoggerSyslog, LOGGER_DEBUG);
logger = TR_new(TR_LoggerSyslog, TR_LOGGER_DEBUG);
config = TR_new(Config, CONFIGDIR "/taskrambler.conf");
if (NULL == config) {
loggerLog(logger, LOGGER_INFO,
TR_loggerLog(logger, TR_LOGGER_INFO,
"unable to load configuration file: %s\n",
CONFIGDIR "/taskrambler.conf");
if (! TR_INSTANCE_OF(LoggerStderr, logger)) {
if (! TR_INSTANCE_OF(TR_LoggerStderr, logger)) {
fprintf(stderr,
"unable to load configuration file: %s\n",
CONFIGDIR "/taskrambler.conf");
@ -255,19 +253,19 @@ main()
if (0 < w) {
if (WIFEXITED(status)) {
loggerLog(logger, LOGGER_INFO,
TR_loggerLog(logger, TR_LOGGER_INFO,
"child exited, status=%d\n",
WEXITSTATUS(status));
} else if (WIFSIGNALED(status)) {
loggerLog(logger, LOGGER_INFO,
TR_loggerLog(logger, TR_LOGGER_INFO,
"killed by signal %d\n",
WTERMSIG(status));
} else if (WIFSTOPPED(status)) {
loggerLog(logger, LOGGER_INFO,
TR_loggerLog(logger, TR_LOGGER_INFO,
"stopped by signal %d\n",
WSTOPSIG(status));
} else if (WIFCONTINUED(status)) {
loggerLog(logger, LOGGER_INFO, "continued\n");
TR_loggerLog(logger, TR_LOGGER_INFO, "continued\n");
}
}
} while (!WIFEXITED(status) && !WIFSIGNALED(status));

12
tests/mock/mock_worker.c

@ -38,7 +38,7 @@ mockWorkerClone(void * _this, void * _base)
static
ssize_t
mockWorkerRead(void * _this, Stream st)
mockWorkerRead(void * _this, TR_Stream st)
{
MockWorker this = _this;
size_t size;
@ -50,19 +50,19 @@ mockWorkerRead(void * _this, Stream st)
static
ssize_t
mockWorkerWrite(void * _this, Stream st)
mockWorkerWrite(void * _this, TR_Stream st)
{
return 0;
}
INIT_IFACE(Class, mockWorkerCtor, mockWorkerDtor, mockWorkerClone);
INIT_IFACE(StreamReader, mockWorkerRead);
INIT_IFACE(StreamWriter, mockWorkerWrite);
INIT_IFACE(TR_StreamReader, mockWorkerRead);
INIT_IFACE(TR_StreamWriter, mockWorkerWrite);
CREATE_CLASS(
MockWorker,
NULL,
IFACE(Class),
IFACE(StreamReader),
IFACE(StreamWriter));
IFACE(TR_StreamReader),
IFACE(TR_StreamWriter));
// vim: set ts=4 sw=4:

2
tests/socketTest.c

@ -5,7 +5,7 @@
#include "runtest.h"
#include "class.h"
#include "socket.h"
#include "logger.h"
#include "trio.h"
#include "mock/mock_logger.h"

Loading…
Cancel
Save