aboutsummaryrefslogtreecommitdiff
path: root/src/socket.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/socket.cpp')
-rw-r--r--src/socket.cpp41
1 files changed, 11 insertions, 30 deletions
diff --git a/src/socket.cpp b/src/socket.cpp
index 3458b45..1c53ec8 100644
--- a/src/socket.cpp
+++ b/src/socket.cpp
@@ -36,7 +36,7 @@ Bu::Socket::Socket( int nSocket ) :
36 bActive( true ) 36 bActive( true )
37{ 37{
38#ifdef WIN32 38#ifdef WIN32
39 DynamicWinsock32::Winsock2::getInstance(); 39 DynamicWinsock2::Winsock2::getInstance();
40#endif 40#endif
41 setAddress(); 41 setAddress();
42} 42}
@@ -44,10 +44,10 @@ Bu::Socket::Socket( int nSocket ) :
44Bu::Socket::Socket( const Bu::FString &sAddr, int nPort, int nTimeout ) 44Bu::Socket::Socket( const Bu::FString &sAddr, int nPort, int nTimeout )
45{ 45{
46#ifdef WIN32 46#ifdef WIN32
47 DynamicWinsock32::Winsock2::getInstance(); 47 DynamicWinsock2::Winsock2::getInstance();
48#endif 48#endif
49 bActive = false; 49 bActive = false;
50 50
51 /* Create the socket. */ 51 /* Create the socket. */
52 nSocket = DYNLOAD socket( PF_INET, SOCK_STREAM, 0 ); 52 nSocket = DYNLOAD socket( PF_INET, SOCK_STREAM, 0 );
53 53
@@ -88,35 +88,17 @@ Bu::Socket::Socket( const Bu::FString &sAddr, int nPort, int nTimeout )
88 char ibuf[10]; 88 char ibuf[10];
89 sprintf( ibuf, "%d", nPort ); 89 sprintf( ibuf, "%d", nPort );
90 90
91 if( int ret = DYNLOAD getaddrinfo( sAddr.getStr(), ibuf, &aiHints, &pAddr ) 91 int ret;
92 if( ret = DYNLOAD getaddrinfo( sAddr.getStr(), ibuf, &aiHints, &pAddr )
92 != 0 ) 93 != 0 )
93 { 94 {
94 95 #ifdef WIN32
95 struct addrinfo *pCur = pAddr; 96 throw Bu::SocketException("Couldn't resolve hostname %s (%d).\n",
96 while( pCur ) 97 sAddr.getStr(), DYNLOAD WSAGetLastError());
97 { 98 #else
98 printf("Name: %s\n", pCur->ai_canonname );
99 printf(" Flags: %d\n", pCur->ai_flags );
100 printf(" Family: %d\n", pCur->ai_family );
101 printf(" Socktype: %d\n", pCur->ai_socktype );
102 printf(" Protocol: %d\n", pCur->ai_protocol );
103
104 pCur = pCur->ai_next;
105 }
106 throw Bu::SocketException("Couldn't resolve hostname %s (%s).\n", 99 throw Bu::SocketException("Couldn't resolve hostname %s (%s).\n",
107 sAddr.getStr(), gai_strerror(ret)); 100 sAddr.getStr(), DYNLOAD gai_strerror(ret));
108 } 101 #endif
109
110 struct addrinfo *pCur = pAddr;
111 while( pCur )
112 {
113 printf("Name: %s\n", pCur->ai_canonname );
114 printf(" Flags: %d\n", pCur->ai_flags );
115 printf(" Family: %d\n", pCur->ai_family );
116 printf(" Socktype: %d\n", pCur->ai_socktype );
117 printf(" Protocol: %d\n", pCur->ai_protocol );
118
119 pCur = pCur->ai_next;
120 } 102 }
121 103
122 DYNLOAD connect( 104 DYNLOAD connect(
@@ -156,7 +138,6 @@ Bu::Socket::Socket( const Bu::FString &sAddr, int nPort, int nTimeout )
156 throw ExceptionBase("Connection timeout.\n"); 138 throw ExceptionBase("Connection timeout.\n");
157 } 139 }
158 } 140 }
159 setAddress();
160} 141}
161 142
162Bu::Socket::~Socket() 143Bu::Socket::~Socket()