diff options
author | Martin Ebourne <martin@ebourne.me.uk> | 2005-11-30 23:14:40 +0000 |
---|---|---|
committer | Martin Ebourne <martin@ebourne.me.uk> | 2005-11-30 23:14:40 +0000 |
commit | 01ca97865fa9d6ed1a967e970927265f1c348289 (patch) | |
tree | 5e7e1f70b38b156994c3802ba3e77fbf288fe937 /lib/server | |
parent | 99f8ce096bc5569adbfea1911dbcda24c28d8d8b (diff) |
Merged martin/solaris at r9 to trunk
Diffstat (limited to 'lib/server')
-rwxr-xr-x | lib/server/Daemon.cpp | 14 | ||||
-rwxr-xr-x | lib/server/Protocol.cpp | 31 | ||||
-rwxr-xr-x | lib/server/SocketStreamTLS.cpp | 17 |
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); |