diff options
author | Mike Buland <eichlan@xagasoft.com> | 2007-07-15 07:18:21 +0000 |
---|---|---|
committer | Mike Buland <eichlan@xagasoft.com> | 2007-07-15 07:18:21 +0000 |
commit | d7ea32daa44c9e0cc4ac00a69168b4e1d182082b (patch) | |
tree | 342b2f5f2735f61fa60102b1683d6ea6b6c8bd32 /src | |
parent | 2741e16c129e8c70bad2cb47e5a97083dd4d3c85 (diff) | |
download | libbu++-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 '')
-rw-r--r-- | src/socket.cpp | 11 | ||||
-rw-r--r-- | 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 ) : | |||
20 | nSocket( nSocket ), | 20 | nSocket( nSocket ), |
21 | bActive( true ) | 21 | bActive( true ) |
22 | { | 22 | { |
23 | setAddress(); | ||
23 | } | 24 | } |
24 | 25 | ||
25 | Bu::Socket::Socket( const Bu::FString &sAddr, int nPort, int nTimeout ) | 26 | 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 ) | |||
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 | ||
100 | Bu::Socket::~Socket() | 101 | Bu::Socket::~Socket() |
@@ -297,7 +298,7 @@ bool Bu::Socket::isOpen() | |||
297 | return bActive; | 298 | return bActive; |
298 | } | 299 | } |
299 | 300 | ||
300 | Bu::FString Bu::Socket::getAddress() const | 301 | void 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; | 312 | Bu::FString Bu::Socket::getAddress() const |
313 | { | ||
314 | return sAddress; | ||
310 | } | 315 | } |
311 | 316 | ||
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 | |||
47 | Bu::FString getAddress() const; | 47 | Bu::FString getAddress() const; |
48 | 48 | ||
49 | private: | 49 | private: |
50 | void setAddress(); | ||
51 | |||
50 | int nSocket; | 52 | int nSocket; |
51 | bool bActive; | 53 | bool bActive; |
52 | FString sReadBuf; | 54 | FString sReadBuf; |
55 | FString sAddress; | ||
53 | }; | 56 | }; |
54 | } | 57 | } |
55 | 58 | ||