aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/socket.cpp11
-rw-r--r--src/socket.h3
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
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
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