summaryrefslogtreecommitdiff
path: root/lib/server
diff options
context:
space:
mode:
Diffstat (limited to 'lib/server')
-rwxr-xr-xlib/server/Daemon.cpp14
-rwxr-xr-xlib/server/Protocol.cpp31
-rwxr-xr-xlib/server/SocketStreamTLS.cpp17
3 files changed, 52 insertions, 10 deletions
diff --git a/lib/server/Daemon.cpp b/lib/server/Daemon.cpp
index 31997fb6..1885c6c8 100755
--- a/lib/server/Daemon.cpp
+++ b/lib/server/Daemon.cpp
@@ -141,7 +141,11 @@ int Daemon::Main(const char *DefaultConfigFile, int argc, const char *argv[])
SetupInInitialProcess();
// Set signal handler
- if(::signal(SIGHUP, SignalHandler) == SIG_ERR || ::signal(SIGTERM, SignalHandler) == SIG_ERR)
+ struct sigaction sa;
+ sa.sa_handler = SignalHandler;
+ sa.sa_flags = 0;
+ ::sigemptyset(&sa.sa_mask);
+ if(::sigaction(SIGHUP, &sa, NULL) != 0 || ::sigaction(SIGTERM, &sa, NULL) != 0)
{
THROW_EXCEPTION(ServerException, DaemoniseFailed)
}
@@ -354,8 +358,12 @@ int Daemon::Main(const char *DefaultConfigFile, int argc, const char *argv[])
void Daemon::EnterChild()
{
// Unset signal handlers
- ::signal(SIGHUP, SIG_DFL);
- ::signal(SIGTERM, SIG_DFL);
+ struct sigaction sa;
+ sa.sa_handler = SIG_DFL;
+ sa.sa_flags = 0;
+ ::sigemptyset(&sa.sa_mask);
+ ::sigaction(SIGHUP, &sa, NULL);
+ ::sigaction(SIGTERM, &sa, NULL);
}
diff --git a/lib/server/Protocol.cpp b/lib/server/Protocol.cpp
index ca89bdf1..690c2ec0 100755
--- a/lib/server/Protocol.cpp
+++ b/lib/server/Protocol.cpp
@@ -423,7 +423,14 @@ void Protocol::Read(int64_t &rOut)
READ_START_CHECK
READ_CHECK_BYTES_AVAILABLE(sizeof(int64_t))
- rOut = ntoh64(*((int64_t*)(mpBuffer + mReadOffset)));
+#ifdef PLATFORM_ALIGN_INT
+ int64_t nvalue;
+ memcpy(&nvalue, mpBuffer + mReadOffset, sizeof(int64_t));
+#else
+ int64_t nvalue = *((int64_t*)(mpBuffer + mReadOffset));
+#endif
+ rOut = ntoh64(nvalue);
+
mReadOffset += sizeof(int64_t);
}
@@ -440,7 +447,13 @@ void Protocol::Read(int32_t &rOut)
READ_START_CHECK
READ_CHECK_BYTES_AVAILABLE(sizeof(int32_t))
- rOut = ntohl(*((int32_t*)(mpBuffer + mReadOffset)));
+#ifdef PLATFORM_ALIGN_INT
+ int32_t nvalue;
+ memcpy(&nvalue, mpBuffer + mReadOffset, sizeof(int32_t));
+#else
+ int32_t nvalue = *((int32_t*)(mpBuffer + mReadOffset));
+#endif
+ rOut = ntohl(nvalue);
mReadOffset += sizeof(int32_t);
}
@@ -545,7 +558,12 @@ void Protocol::Write(int64_t Value)
WRITE_START_CHECK
WRITE_ENSURE_BYTES_AVAILABLE(sizeof(int64_t))
- *((int64_t*)(mpBuffer + mWriteOffset)) = hton64(Value);
+ int64_t nvalue = hton64(Value);
+#ifdef PLATFORM_ALIGN_INT
+ memcpy(mpBuffer + mWriteOffset, &nvalue, sizeof(int64_t));
+#else
+ *((int64_t*)(mpBuffer + mWriteOffset)) = nvalue;
+#endif
mWriteOffset += sizeof(int64_t);
}
@@ -563,7 +581,12 @@ void Protocol::Write(int32_t Value)
WRITE_START_CHECK
WRITE_ENSURE_BYTES_AVAILABLE(sizeof(int32_t))
- *((int32_t*)(mpBuffer + mWriteOffset)) = htonl(Value);
+ int32_t nvalue = htonl(Value);
+#ifdef PLATFORM_ALIGN_INT
+ memcpy(mpBuffer + mWriteOffset, &nvalue, sizeof(int32_t));
+#else
+ *((int32_t*)(mpBuffer + mWriteOffset)) = nvalue;
+#endif
mWriteOffset += sizeof(int32_t);
}
diff --git a/lib/server/SocketStreamTLS.cpp b/lib/server/SocketStreamTLS.cpp
index 63ac7bb5..7d82f82c 100755
--- a/lib/server/SocketStreamTLS.cpp
+++ b/lib/server/SocketStreamTLS.cpp
@@ -14,7 +14,7 @@
#include <openssl/bio.h>
#include <poll.h>
#include <errno.h>
-#include <sys/ioctl.h>
+#include <fcntl.h>
#include "SocketStreamTLS.h"
#include "SSLLib.h"
@@ -132,12 +132,23 @@ void SocketStreamTLS::Handshake(const TLSContext &rContext, bool IsServer)
}
// Make the socket non-blocking so timeouts on Read work
- int nonblocking = true;
- if(::ioctl(socket, FIONBIO, &nonblocking) == -1)
+ // This is more portable than using ioctl with FIONBIO
+ int statusFlags = 0;
+ if(::fcntl(socket, F_GETFL, &statusFlags) < 0
+ || ::fcntl(socket, F_SETFL, statusFlags | O_NONBLOCK) == -1)
{
THROW_EXCEPTION(ServerException, SocketSetNonBlockingFailed)
}
+ // FIXME: This is less portable than the above. However, it MAY be needed
+ // for cygwin, which has/had bugs with fcntl
+ //
+ // int nonblocking = true;
+ // if(::ioctl(socket, FIONBIO, &nonblocking) == -1)
+ // {
+ // THROW_EXCEPTION(ServerException, SocketSetNonBlockingFailed)
+ // }
+
// Set the two to know about each other
::SSL_set_bio(mpSSL, mpBIO, mpBIO);