summaryrefslogtreecommitdiff
path: root/src/socket.cpp
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2007-07-15 07:18:21 +0000
committerMike Buland <eichlan@xagasoft.com>2007-07-15 07:18:21 +0000
commitd7ea32daa44c9e0cc4ac00a69168b4e1d182082b (patch)
tree342b2f5f2735f61fa60102b1683d6ea6b6c8bd32 /src/socket.cpp
parent2741e16c129e8c70bad2cb47e5a97083dd4d3c85 (diff)
downloadlibbu++-d7ea32daa44c9e0cc4ac00a69168b4e1d182082b.tar.gz
libbu++-d7ea32daa44c9e0cc4ac00a69168b4e1d182082b.tar.bz2
libbu++-d7ea32daa44c9e0cc4ac00a69168b4e1d182082b.tar.xz
libbu++-d7ea32daa44c9e0cc4ac00a69168b4e1d182082b.zip
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.
Diffstat (limited to 'src/socket.cpp')
-rw-r--r--src/socket.cpp11
1 files changed, 8 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 ) :
20 nSocket( nSocket ), 20 nSocket( nSocket ),
21 bActive( true ) 21 bActive( true )
22{ 22{
23 setAddress();
23} 24}
24 25
25Bu::Socket::Socket( const Bu::FString &sAddr, int nPort, int nTimeout ) 26Bu::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 )
93 close(); 94 close();
94 throw ExceptionBase("Connection timeout.\n"); 95 throw ExceptionBase("Connection timeout.\n");
95 } 96 }
96
97 } 97 }
98 setAddress();
98} 99}
99 100
100Bu::Socket::~Socket() 101Bu::Socket::~Socket()
@@ -297,7 +298,7 @@ bool Bu::Socket::isOpen()
297 return bActive; 298 return bActive;
298} 299}
299 300
300Bu::FString Bu::Socket::getAddress() const 301void Bu::Socket::setAddress()
301{ 302{
302 struct sockaddr_in addr; 303 struct sockaddr_in addr;
303 socklen_t len = sizeof(addr); 304 socklen_t len = sizeof(addr);
@@ -305,7 +306,11 @@ Bu::FString Bu::Socket::getAddress() const
305 getsockname( nSocket, (sockaddr *)(&addr), &len ); 306 getsockname( nSocket, (sockaddr *)(&addr), &len );
306 char buf[150]; 307 char buf[150];
307 sprintf( buf, "%s", inet_ntoa( addr.sin_addr ) ); 308 sprintf( buf, "%s", inet_ntoa( addr.sin_addr ) );
309 sAddress = buf;
310}
308 311
309 return buf; 312Bu::FString Bu::Socket::getAddress() const
313{
314 return sAddress;
310} 315}
311 316