diff options
author | Chris Wilson <chris+github@qwirx.com> | 2011-12-13 00:43:41 +0000 |
---|---|---|
committer | Chris Wilson <chris+github@qwirx.com> | 2011-12-13 00:43:41 +0000 |
commit | dea24ce69f88e2e28dce35aacaba83c90adb6cff (patch) | |
tree | 0453cb9860330a2d33b12c2c2a4eaf9cf0c988c4 /lib/server | |
parent | 20a8c39aa25d454a3fa142f125003ad242d73ea0 (diff) |
Add remote host and port to post-login login message, requested by Pete Jalajas.
Diffstat (limited to 'lib/server')
-rw-r--r-- | lib/server/ServerStream.h | 23 | ||||
-rw-r--r-- | lib/server/Socket.cpp | 38 |
2 files changed, 32 insertions, 29 deletions
diff --git a/lib/server/ServerStream.h b/lib/server/ServerStream.h index e49dbcbe..0adee6f2 100644 --- a/lib/server/ServerStream.h +++ b/lib/server/ServerStream.h @@ -48,6 +48,15 @@ private: ServerStream(const ServerStream &rToCopy) { } + + std::string mConnectionDetails; + +protected: + const std::string& GetConnectionDetails() + { + return mConnectionDetails; + } + public: virtual const char *DaemonName() const @@ -122,6 +131,10 @@ public: protected: virtual void NotifyListenerIsReady() { } + virtual void LogConnectionDetails(std::string details) + { + BOX_NOTICE("Handling incoming connection from " << details); + } public: virtual void Run2(bool &rChildExit) @@ -237,8 +250,9 @@ public: { // Get the incoming connection // (with zero wait time) - std::string logMessage; - std::auto_ptr<StreamType> connection(psocket->Accept(0, &logMessage)); + std::auto_ptr<StreamType> connection( + psocket->Accept(0, + &mConnectionDetails)); // Was there one (there should be...) if(connection.get()) @@ -264,6 +278,7 @@ public: // Set up daemon EnterChild(); SetProcessTitle("transaction"); + LogConnectionDetails(mConnectionDetails); // Memory leak test the forked process #ifdef BOX_MEMORY_LEAK_TESTING @@ -281,7 +296,9 @@ public: } // Log it - BOX_NOTICE("Message from child process " << pid << ": " << logMessage); + BOX_TRACE("Forked child process " << pid << + "to handle connection from " << + mConnectionDetails); } else { diff --git a/lib/server/Socket.cpp b/lib/server/Socket.cpp index 4a83bdb0..f2a4996b 100644 --- a/lib/server/Socket.cpp +++ b/lib/server/Socket.cpp @@ -123,27 +123,8 @@ void Socket::NameLookupToSockAddr(SocketAllAddr &addr, int &sockDomain, // -------------------------------------------------------------------------- void Socket::LogIncomingConnection(const struct sockaddr *addr, socklen_t addrlen) { - if(addr == NULL) {THROW_EXCEPTION(CommonException, BadArguments)} - - switch(addr->sa_family) - { - case AF_UNIX: - BOX_INFO("Incoming connection from local (UNIX socket)"); - break; - - case AF_INET: - { - sockaddr_in *a = (sockaddr_in*)addr; - BOX_INFO("Incoming connection from " << - inet_ntoa(a->sin_addr) << " port " << - ntohs(a->sin_port)); - } - break; - - default: - BOX_WARNING("Incoming connection of unknown type"); - break; - } + BOX_INFO("Incoming connection from " << + IncomingConnectionLogMessage(addr, addrlen)); } // -------------------------------------------------------------------------- @@ -161,20 +142,25 @@ std::string Socket::IncomingConnectionLogMessage(const struct sockaddr *addr, so switch(addr->sa_family) { case AF_UNIX: - return std::string("Incoming connection from local (UNIX socket)"); + return std::string("local (UNIX socket)"); break; case AF_INET: { - char msg[256]; // more than enough sockaddr_in *a = (sockaddr_in*)addr; - sprintf(msg, "Incoming connection from %s port %d", inet_ntoa(a->sin_addr), ntohs(a->sin_port)); - return std::string(msg); + std::ostringstream oss; + oss << inet_ntoa(a->sin_addr) << " port " << + ntohs(a->sin_port); + return oss.str(); } break; default: - return std::string("Incoming connection of unknown type"); + { + std::ostringstream oss; + oss << "unknown socket type " << addr->sa_family; + return oss.str(); + } break; } |