From d7ea32daa44c9e0cc4ac00a69168b4e1d182082b Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Sun, 15 Jul 2007 07:18:21 +0000 Subject: Bu::Socket now cashes a string representation of the IP address so you can access it even after closing a socket to assist with proper accounting. --- src/socket.cpp | 11 ++++++++--- src/socket.h | 3 +++ 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/socket.cpp b/src/socket.cpp index 221d4c2..50ed4e2 100644 --- a/src/socket.cpp +++ b/src/socket.cpp @@ -20,6 +20,7 @@ Bu::Socket::Socket( int nSocket ) : nSocket( nSocket ), bActive( true ) { + setAddress(); } Bu::Socket::Socket( const Bu::FString &sAddr, int nPort, int nTimeout ) @@ -93,8 +94,8 @@ Bu::Socket::Socket( const Bu::FString &sAddr, int nPort, int nTimeout ) close(); throw ExceptionBase("Connection timeout.\n"); } - } + setAddress(); } Bu::Socket::~Socket() @@ -297,7 +298,7 @@ bool Bu::Socket::isOpen() return bActive; } -Bu::FString Bu::Socket::getAddress() const +void Bu::Socket::setAddress() { struct sockaddr_in addr; socklen_t len = sizeof(addr); @@ -305,7 +306,11 @@ Bu::FString Bu::Socket::getAddress() const getsockname( nSocket, (sockaddr *)(&addr), &len ); char buf[150]; sprintf( buf, "%s", inet_ntoa( addr.sin_addr ) ); + sAddress = buf; +} - return buf; +Bu::FString Bu::Socket::getAddress() const +{ + return sAddress; } diff --git a/src/socket.h b/src/socket.h index 9f82456..d0949cc 100644 --- a/src/socket.h +++ b/src/socket.h @@ -47,9 +47,12 @@ namespace Bu Bu::FString getAddress() const; private: + void setAddress(); + int nSocket; bool bActive; FString sReadBuf; + FString sAddress; }; } -- cgit v1.2.3