51 changed files with 104 additions and 1330 deletions
-
5configure.ac
-
6include/cbuf.h
-
2include/http/message.h
-
4include/http/parser.h
-
4include/http/writer.h
-
9include/logger.h
-
43include/logger/interface/logger.h
-
57include/logger/logger.h
-
20include/server.h
-
48include/socket.h
-
10include/stream.h
-
44include/stream/interface/reader.h
-
44include/stream/interface/writer.h
-
49include/stream/stream.h
-
11src/Makefile.am
-
6src/cbuf/read.c
-
6src/http/parser.c
-
4src/http/parser/parse.c
-
2src/http/response/asset.c
-
14src/http/worker.c
-
4src/http/worker/answer.c
-
2src/http/worker/process.c
-
6src/http/writer.c
-
6src/http/writer/write.c
-
9src/logger/Makefile.am
-
58src/logger/interface/i_logger.c
-
57src/logger/logger.c
-
39src/logger/stderr.c
-
52src/logger/syslog.c
-
8src/server/close_conn.c
-
29src/server/handle_accept.c
-
4src/server/poll.c
-
10src/server/read.c
-
4src/server/run.c
-
21src/server/server.c
-
9src/server/write.c
-
9src/socket/Makefile.am
-
57src/socket/accept.c
-
54src/socket/connect.c
-
59src/socket/listen.c
-
37src/socket/nonblock.c
-
78src/socket/socket.c
-
13src/stream/Makefile.am
-
39src/stream/interface/reader.c
-
40src/stream/interface/writer.c
-
120src/stream/read.c
-
62src/stream/stream.c
-
124src/stream/write.c
-
22src/taskrambler.c
-
12tests/mock/mock_worker.c
-
2tests/socketTest.c
@ -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: |
|
||||
@ -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: |
|
||||
@ -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: |
|
||||
@ -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: |
|
||||
|
|
||||
@ -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: |
|
||||
@ -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: |
|
||||
@ -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: |
|
||||
@ -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: |
|
||||
@ -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) |
|
||||
@ -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: |
|
||||
@ -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: |
|
||||
@ -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: |
|
||||
@ -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: |
|
||||
@ -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) |
|
||||
@ -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: |
|
||||
@ -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: |
|
||||
@ -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: |
|
||||
@ -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: |
|
||||
@ -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: |
|
||||
@ -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) |
|
||||
@ -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: |
|
||||
@ -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: |
|
||||
@ -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: |
|
||||
@ -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: |
|
||||
@ -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: |
|
||||
Write
Preview
Loading…
Cancel
Save
Reference in new issue