summaryrefslogtreecommitdiff
path: root/lib/server
diff options
context:
space:
mode:
authorMartin Ebourne <martin@ebourne.me.uk>2005-12-12 20:50:00 +0000
committerMartin Ebourne <martin@ebourne.me.uk>2005-12-12 20:50:00 +0000
commit3bedf8846f4d7a5cb38276b274662d62a36dcd52 (patch)
tree9d51de8b0f3d06ba6549a5a1958e52f592343140 /lib/server
parent81d8eda2419e7a23088a98cdfc52a305c9ceac0d (diff)
Marged chris/win32/merge/07-win32-fixes at r210 to trunk
Diffstat (limited to 'lib/server')
-rwxr-xr-xlib/server/Daemon.cpp21
-rw-r--r--lib/server/LocalProcessStream.cpp9
-rwxr-xr-xlib/server/SSLLib.cpp2
-rwxr-xr-xlib/server/ServerStream.h7
-rwxr-xr-xlib/server/Socket.cpp6
-rwxr-xr-xlib/server/Socket.h7
-rwxr-xr-xlib/server/SocketListen.h21
-rwxr-xr-xlib/server/SocketStream.cpp24
-rwxr-xr-xlib/server/SocketStream.h10
-rwxr-xr-xlib/server/SocketStreamTLS.cpp12
-rwxr-xr-xlib/server/makeprotocol.pl6
11 files changed, 103 insertions, 22 deletions
diff --git a/lib/server/Daemon.cpp b/lib/server/Daemon.cpp
index ca2df62f..a4dfdaec 100755
--- a/lib/server/Daemon.cpp
+++ b/lib/server/Daemon.cpp
@@ -11,11 +11,14 @@
#include <stdio.h>
#include <unistd.h>
-#include <syslog.h>
#include <signal.h>
#include <string.h>
#include <stdarg.h>
+#ifndef WIN32
+#include <syslog.h>
+#endif
+
#include "Daemon.h"
#include "Configuration.h"
#include "ServerException.h"
@@ -140,6 +143,7 @@ int Daemon::Main(const char *DefaultConfigFile, int argc, const char *argv[])
// Let the derived class have a go at setting up stuff in the initial process
SetupInInitialProcess();
+#ifndef WIN32
// Set signal handler
struct sigaction sa;
sa.sa_handler = SignalHandler;
@@ -219,12 +223,14 @@ int Daemon::Main(const char *DefaultConfigFile, int argc, const char *argv[])
break;
}
}
+#endif // ! WIN32
// open the log
::openlog(DaemonName(), LOG_PID, LOG_LOCAL6);
// Log the start message
::syslog(LOG_INFO, "Starting daemon (config: %s) (version " BOX_VERSION ")", configfile);
+#ifndef WIN32
// Write PID to file
char pid[32];
int pidsize = sprintf(pid, "%d", (int)getpid());
@@ -233,6 +239,7 @@ int Daemon::Main(const char *DefaultConfigFile, int argc, const char *argv[])
::syslog(LOG_ERR, "can't write pid file");
THROW_EXCEPTION(ServerException, DaemoniseFailed)
}
+#endif
// Set up memory leak reporting
#ifdef BOX_MEMORY_LEAK_TESTING
@@ -245,6 +252,7 @@ int Daemon::Main(const char *DefaultConfigFile, int argc, const char *argv[])
if(asDaemon)
{
+#ifndef WIN32
// Close standard streams
::close(0);
::close(1);
@@ -265,8 +273,9 @@ int Daemon::Main(const char *DefaultConfigFile, int argc, const char *argv[])
{
::close(devnull);
}
-
- // And definately don't try and send anything to those file descriptors
+#endif // ! WIN32
+
+ // And definitely don't try and send anything to those file descriptors
// -- this has in the past sent text to something which isn't expecting it.
TRACE_TO_STDOUT(false);
}
@@ -357,6 +366,7 @@ int Daemon::Main(const char *DefaultConfigFile, int argc, const char *argv[])
// --------------------------------------------------------------------------
void Daemon::EnterChild()
{
+#ifndef WIN32
// Unset signal handlers
struct sigaction sa;
sa.sa_handler = SIG_DFL;
@@ -364,6 +374,7 @@ void Daemon::EnterChild()
sigemptyset(&sa.sa_mask); // macro
::sigaction(SIGHUP, &sa, NULL);
::sigaction(SIGTERM, &sa, NULL);
+#endif
}
@@ -377,6 +388,7 @@ void Daemon::EnterChild()
// --------------------------------------------------------------------------
void Daemon::SignalHandler(int sigraised)
{
+#ifndef WIN32
if(spDaemon != 0)
{
switch(sigraised)
@@ -393,6 +405,7 @@ void Daemon::SignalHandler(int sigraised)
break;
}
}
+#endif
}
// --------------------------------------------------------------------------
@@ -534,5 +547,3 @@ void Daemon::SetProcessTitle(const char *format, ...)
#endif // HAVE_SETPROCTITLE
}
-
-
diff --git a/lib/server/LocalProcessStream.cpp b/lib/server/LocalProcessStream.cpp
index f2a97c56..0de7bef4 100644
--- a/lib/server/LocalProcessStream.cpp
+++ b/lib/server/LocalProcessStream.cpp
@@ -9,7 +9,9 @@
#include "Box.h"
+#ifndef WIN32
#include <sys/socket.h>
+#endif
#include <unistd.h>
#include "LocalProcessStream.h"
@@ -36,6 +38,8 @@ std::auto_ptr<IOStream> LocalProcessStream(const char *CommandLine, pid_t &rPidO
// Split up command
std::vector<std::string> command;
SplitString(std::string(CommandLine), ' ', command);
+
+#ifndef WIN32
// Build arguments
char *args[MAX_ARGUMENTS + 4];
{
@@ -94,6 +98,11 @@ std::auto_ptr<IOStream> LocalProcessStream(const char *CommandLine, pid_t &rPidO
// Return the stream object and PID
rPidOut = pid;
return stream;
+#else // WIN32
+ ::syslog(LOG_ERR, "vfork not implemented - LocalProcessStream.cpp");
+ std::auto_ptr<IOStream> stream;
+ return stream;
+#endif // ! WIN32
}
diff --git a/lib/server/SSLLib.cpp b/lib/server/SSLLib.cpp
index 9e98550a..2a5bdbde 100755
--- a/lib/server/SSLLib.cpp
+++ b/lib/server/SSLLib.cpp
@@ -14,7 +14,9 @@
#include <openssl/err.h>
#include <openssl/rand.h>
+#ifndef WIN32
#include <syslog.h>
+#endif
#include "SSLLib.h"
#include "ServerException.h"
diff --git a/lib/server/ServerStream.h b/lib/server/ServerStream.h
index d087a321..8dafccae 100755
--- a/lib/server/ServerStream.h
+++ b/lib/server/ServerStream.h
@@ -10,10 +10,13 @@
#ifndef SERVERSTREAM__H
#define SERVERSTREAM__H
-#include <syslog.h>
#include <stdlib.h>
#include <errno.h>
-#include <sys/wait.h>
+
+#ifndef WIN32
+ #include <syslog.h>
+ #include <sys/wait.h>
+#endif
#include "Daemon.h"
#include "SocketListen.h"
diff --git a/lib/server/Socket.cpp b/lib/server/Socket.cpp
index b2d32345..0343b8bf 100755
--- a/lib/server/Socket.cpp
+++ b/lib/server/Socket.cpp
@@ -11,11 +11,13 @@
#include <unistd.h>
#include <sys/types.h>
+#ifndef WIN32
#include <sys/socket.h>
#include <netdb.h>
#include <syslog.h>
#include <netinet/in.h>
#include <arpa/inet.h>
+#endif
#include <string.h>
#include <stdio.h>
@@ -72,6 +74,7 @@ void Socket::NameLookupToSockAddr(SocketAllAddr &addr, int &sockDomain, int Type
}
break;
+#ifndef WIN32
case TypeUNIX:
sockDomain = AF_UNIX;
{
@@ -89,7 +92,8 @@ void Socket::NameLookupToSockAddr(SocketAllAddr &addr, int &sockDomain, int Type
::strcpy(addr.sa_unix.sun_path, Name);
}
break;
-
+#endif
+
default:
THROW_EXCEPTION(CommonException, BadArguments)
break;
diff --git a/lib/server/Socket.h b/lib/server/Socket.h
index 86a06097..057e4cad 100755
--- a/lib/server/Socket.h
+++ b/lib/server/Socket.h
@@ -10,16 +10,23 @@
#ifndef SOCKET__H
#define SOCKET__H
+#ifdef WIN32
+#include "emu.h"
+typedef int socklen_t;
+#else
#include <sys/socket.h>
#include <netinet/in.h>
#include <sys/un.h>
+#endif
#include <string>
typedef union {
struct sockaddr sa_generic;
struct sockaddr_in sa_inet;
+#ifndef WIN32
struct sockaddr_un sa_unix;
+#endif
} SocketAllAddr;
// --------------------------------------------------------------------------
diff --git a/lib/server/SocketListen.h b/lib/server/SocketListen.h
index 7042011c..d954339a 100755
--- a/lib/server/SocketListen.h
+++ b/lib/server/SocketListen.h
@@ -12,15 +12,20 @@
#include <errno.h>
#include <unistd.h>
-#include <new>
-#include <poll.h>
-#include <memory>
-#include <string>
+
#ifdef HAVE_KQUEUE
#include <sys/event.h>
#include <sys/time.h>
#endif
+#ifndef WIN32
+ #include <poll.h>
+#endif
+
+#include <new>
+#include <memory>
+#include <string>
+
#include "Socket.h"
#include "ServerException.h"
@@ -94,7 +99,11 @@ public:
{
if(mSocketHandle != -1)
{
+#ifdef WIN32
+ if(::closesocket(mSocketHandle) == -1)
+#else
if(::close(mSocketHandle) == -1)
+#endif
{
THROW_EXCEPTION(ServerException, SocketCloseError)
}
@@ -128,8 +137,12 @@ public:
}
// Set an option to allow reuse (useful for -HUP situations!)
+#ifdef WIN32
+ if(::setsockopt(mSocketHandle, SOL_SOCKET, SO_REUSEADDR, "", 0) == -1)
+#else
int option = true;
if(::setsockopt(mSocketHandle, SOL_SOCKET, SO_REUSEADDR, &option, sizeof(option)) == -1)
+#endif
{
THROW_EXCEPTION(ServerException, SocketOpenError)
}
diff --git a/lib/server/SocketStream.cpp b/lib/server/SocketStream.cpp
index 53865ee3..6719fcde 100755
--- a/lib/server/SocketStream.cpp
+++ b/lib/server/SocketStream.cpp
@@ -11,9 +11,12 @@
#include <unistd.h>
#include <sys/types.h>
-#include <poll.h>
#include <errno.h>
+#ifndef WIN32
+#include <poll.h>
+#endif
+
#include "SocketStream.h"
#include "ServerException.h"
#include "CommonException.h"
@@ -140,7 +143,11 @@ void SocketStream::Open(int Type, const char *Name, int Port)
if(::connect(mSocketHandle, &addr.sa_generic, addrLen) == -1)
{
// Dispose of the socket
+#ifdef WIN32
+ ::closesocket(mSocketHandle);
+#else
::close(mSocketHandle);
+#endif
mSocketHandle = -1;
THROW_EXCEPTION(ConnectionException, Conn_SocketConnectError)
}
@@ -191,7 +198,11 @@ int SocketStream::Read(void *pBuffer, int NBytes, int Timeout)
}
}
+#ifdef WIN32
+ int r = ::recv(mSocketHandle, (char*)pBuffer, NBytes, 0);
+#else
int r = ::read(mSocketHandle, pBuffer, NBytes);
+#endif
if(r == -1)
{
if(errno == EINTR)
@@ -236,7 +247,11 @@ void SocketStream::Write(const void *pBuffer, int NBytes)
while(bytesLeft > 0)
{
// Try to send.
+#ifdef WIN32
+ int sent = ::send(mSocketHandle, buffer, bytesLeft, 0);
+#else
int sent = ::write(mSocketHandle, buffer, bytesLeft);
+#endif
if(sent == -1)
{
// Error.
@@ -283,8 +298,11 @@ void SocketStream::Write(const void *pBuffer, int NBytes)
void SocketStream::Close()
{
if(mSocketHandle == -1) {THROW_EXCEPTION(ServerException, BadSocketHandle)}
-
+#ifdef WIN32
+ if(::closesocket(mSocketHandle) == -1)
+#else
if(::close(mSocketHandle) == -1)
+#endif
{
THROW_EXCEPTION(ServerException, SocketCloseError)
}
@@ -354,7 +372,7 @@ bool SocketStream::StreamClosed()
// Created: 2003/08/06
//
// --------------------------------------------------------------------------
-int SocketStream::GetSocketHandle()
+tOSSocketHandle SocketStream::GetSocketHandle()
{
if(mSocketHandle == -1) {THROW_EXCEPTION(ServerException, BadSocketHandle)}
return mSocketHandle;
diff --git a/lib/server/SocketStream.h b/lib/server/SocketStream.h
index 9b16dbfc..5caaacfd 100755
--- a/lib/server/SocketStream.h
+++ b/lib/server/SocketStream.h
@@ -12,6 +12,12 @@
#include "IOStream.h"
+#ifdef WIN32
+ typedef SOCKET tOSSocketHandle;
+#else
+ typedef int tOSSocketHandle;
+#endif
+
// --------------------------------------------------------------------------
//
// Class
@@ -42,12 +48,12 @@ public:
virtual bool GetPeerCredentials(uid_t &rUidOut, gid_t &rGidOut);
protected:
- int GetSocketHandle();
+ tOSSocketHandle GetSocketHandle();
void MarkAsReadClosed() {mReadClosed = true;}
void MarkAsWriteClosed() {mWriteClosed = true;}
private:
- int mSocketHandle;
+ tOSSocketHandle mSocketHandle;
bool mReadClosed;
bool mWriteClosed;
};
diff --git a/lib/server/SocketStreamTLS.cpp b/lib/server/SocketStreamTLS.cpp
index 7d82f82c..39e0ea6c 100755
--- a/lib/server/SocketStreamTLS.cpp
+++ b/lib/server/SocketStreamTLS.cpp
@@ -12,10 +12,13 @@
#define TLS_CLASS_IMPLEMENTATION_CPP
#include <openssl/ssl.h>
#include <openssl/bio.h>
-#include <poll.h>
#include <errno.h>
#include <fcntl.h>
+#ifndef WIN32
+#include <poll.h>
+#endif
+
#include "SocketStreamTLS.h"
#include "SSLLib.h"
#include "ServerException.h"
@@ -120,7 +123,8 @@ void SocketStreamTLS::Handshake(const TLSContext &rContext, bool IsServer)
SSLLib::LogError("Create socket bio");
THROW_EXCEPTION(ServerException, TLSAllocationFailed)
}
- int socket = GetSocketHandle();
+
+ tOSSocketHandle socket = GetSocketHandle();
BIO_set_fd(mpBIO, socket, BIO_NOCLOSE);
// Then the SSL object
@@ -131,6 +135,7 @@ void SocketStreamTLS::Handshake(const TLSContext &rContext, bool IsServer)
THROW_EXCEPTION(ServerException, TLSAllocationFailed)
}
+#ifndef WIN32
// Make the socket non-blocking so timeouts on Read work
// This is more portable than using ioctl with FIONBIO
int statusFlags = 0;
@@ -139,6 +144,7 @@ void SocketStreamTLS::Handshake(const TLSContext &rContext, bool IsServer)
{
THROW_EXCEPTION(ServerException, SocketSetNonBlockingFailed)
}
+#endif
// FIXME: This is less portable than the above. However, it MAY be needed
// for cygwin, which has/had bugs with fcntl
@@ -464,5 +470,3 @@ std::string SocketStreamTLS::GetPeerCommonName()
// Done.
return std::string(commonName);
}
-
-
diff --git a/lib/server/makeprotocol.pl b/lib/server/makeprotocol.pl
index 2a69c59c..71355e62 100755
--- a/lib/server/makeprotocol.pl
+++ b/lib/server/makeprotocol.pl
@@ -182,7 +182,11 @@ __E
if($implement_syslog)
{
- print H qq~#include <syslog.h>\n~;
+ print H <<EOF;
+#ifndef WIN32
+#include <syslog.h>
+#endif
+EOF
}