aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/newview/llasynchostbyname.cpp
diff options
context:
space:
mode:
authorJacek Antonelli2008-08-15 23:44:46 -0500
committerJacek Antonelli2008-08-15 23:44:46 -0500
commit38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4 (patch)
treeadca584755d22ca041a2dbfc35d4eca01f70b32c /linden/indra/newview/llasynchostbyname.cpp
parentREADME.txt (diff)
downloadmeta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.zip
meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.tar.gz
meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.tar.bz2
meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.tar.xz
Second Life viewer sources 1.13.2.12
Diffstat (limited to 'linden/indra/newview/llasynchostbyname.cpp')
-rw-r--r--linden/indra/newview/llasynchostbyname.cpp228
1 files changed, 228 insertions, 0 deletions
diff --git a/linden/indra/newview/llasynchostbyname.cpp b/linden/indra/newview/llasynchostbyname.cpp
new file mode 100644
index 0000000..1d660bd
--- /dev/null
+++ b/linden/indra/newview/llasynchostbyname.cpp
@@ -0,0 +1,228 @@
1/**
2 * @file llasynchostbyname.cpp
3 * @brief Wrapper for Windows asychronous DNS lookup functionality
4 *
5 * Copyright (c) 2003-2007, Linden Research, Inc.
6 *
7 * The source code in this file ("Source Code") is provided by Linden Lab
8 * to you under the terms of the GNU General Public License, version 2.0
9 * ("GPL"), unless you have obtained a separate licensing agreement
10 * ("Other License"), formally executed by you and Linden Lab. Terms of
11 * the GPL can be found in doc/GPL-license.txt in this distribution, or
12 * online at http://secondlife.com/developers/opensource/gplv2
13 *
14 * There are special exceptions to the terms and conditions of the GPL as
15 * it is applied to this Source Code. View the full text of the exception
16 * in the file doc/FLOSS-exception.txt in this software distribution, or
17 * online at http://secondlife.com/developers/opensource/flossexception
18 *
19 * By copying, modifying or distributing this software, you acknowledge
20 * that you have read and understood your obligations described above,
21 * and agree to abide by those obligations.
22 *
23 * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
24 * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
25 * COMPLETENESS OR PERFORMANCE.
26 */
27
28// standard LL includes
29#include "llviewerprecompiledheaders.h"
30
31// self include
32#include "llasynchostbyname.h"
33
34//
35// Globals
36//
37LLAsyncHostByName gAsyncHostByName;
38
39
40//
41// Parallel implementations for Windows/UNIX!
42//
43#if LL_WINDOWS
44
45#include "llviewerwindow.h"
46// Place to register the Windows callback
47extern void (*gAsyncMsgCallback)(const MSG &msg);
48
49
50// member functions
51LLAsyncHostByName::LLAsyncHostByName()
52 :
53 mRequestHandle(0),
54 mCallback(NULL),
55 mUserdata(NULL)
56{
57 gAsyncMsgCallback = LLAsyncHostByName::handleMessageCallback;
58 memset(mOutputBuffer, 0, sizeof( mOutputBuffer ) );
59}
60
61
62LLAsyncHostByName::~LLAsyncHostByName()
63{
64}
65
66
67BOOL LLAsyncHostByName::startRequest( const LLString& domain_name, LLAsyncHostByNameCallback callback, void* userdata )
68{
69 if( isPendingRequest() )
70 {
71 llwarns << "LLAsyncHostByName::startRequest() cancelled existing request." << llendl;
72 cancelPendingRequest();
73 }
74
75 mCallback = callback;
76 mUserdata = userdata;
77 memset(mOutputBuffer, 0, sizeof( mOutputBuffer ) );
78 mDomainName = domain_name;
79
80 mRequestHandle = WSAAsyncGetHostByName(
81 (HWND)gViewerWindow->getPlatformWindow(),
82 LL_WM_HOST_RESOLVED,
83 domain_name.c_str(),
84 mOutputBuffer,
85 sizeof( mOutputBuffer ) );
86
87 if( !mRequestHandle )
88 {
89 llwarns << "LLAsyncHostByName::startRequest() failed: " << WSAGetLastError() << llendl;
90 return FALSE;
91 }
92
93 return TRUE;
94}
95
96
97void LLAsyncHostByName::handleMessage( const MSG& msg )
98{
99 if( (HANDLE)msg.wParam != mRequestHandle )
100 {
101 llwarns << "LL_WM_HOST_RESOLVED received for request we weren't waiting for. Ignored." << llendl;
102 return;
103 }
104 llinfos << "LL_WM_HOST_RESOLVED" << llendl;
105
106 BOOL success = FALSE;
107 U32 ip = 0;
108 S32 error = WSAGETASYNCERROR( msg.lParam );
109 if( error )
110 {
111 if( error == WSANO_DATA)
112 {
113 llwarns << "Unknown host" << llendl;
114 }
115 else
116 {
117 llwarns << "Resolve host error" << WSAGetLastError () << llendl;
118 }
119 }
120 else
121 {
122 HOSTENT* he = (HOSTENT*) mOutputBuffer;
123 char** addr_list = he->h_addr_list;
124 if (!addr_list)
125 {
126 llwarns << "Bad HOSTENT in LLAsyncHostByName" << llendl;
127 return;
128 }
129 char* first_addr = addr_list[0];
130 if (!first_addr)
131 {
132 llwarns << "Bad address in HOSTENT in LLAsyncHostByName" << llendl;
133 return;
134 }
135 ip = *(U32*)first_addr;
136 success = TRUE;
137 }
138
139 if( mCallback )
140 {
141 mCallback( success, mDomainName, ip, mUserdata );
142 }
143 mCallback = NULL;
144 mUserdata = NULL;
145 mRequestHandle = 0;
146 mDomainName.clear();
147}
148
149
150BOOL LLAsyncHostByName::cancelPendingRequest()
151{
152 if( mCallback )
153 {
154 mCallback( FALSE, mDomainName, 0, mUserdata );
155 }
156 mUserdata = NULL;
157 mCallback = NULL;
158
159 if( mRequestHandle )
160 {
161 S32 ret = WSACancelAsyncRequest( mRequestHandle );
162 if( SOCKET_ERROR == ret )
163 {
164 llwarns << "LLAsyncHostByName::cancelPendingRequest() failed: " << WSAGetLastError() << llendl;
165 return FALSE;
166 }
167 memset(mOutputBuffer, 0, sizeof( mOutputBuffer ) );
168 mRequestHandle = 0;
169 return TRUE;
170 }
171
172 return FALSE;
173}
174
175
176// static
177void LLAsyncHostByName::handleMessageCallback(const MSG& msg)
178{
179 gAsyncHostByName.handleMessage(msg);
180}
181
182
183#else // !LL_WINDOWS
184
185
186#include <netdb.h>
187#include <sys/socket.h>
188#include <netinet/in.h>
189
190
191// member functions
192LLAsyncHostByName::LLAsyncHostByName()
193{
194}
195
196
197LLAsyncHostByName::~LLAsyncHostByName()
198{
199}
200
201
202BOOL LLAsyncHostByName::startRequest( const LLString& domain_name, LLAsyncHostByNameCallback callback, void* userdata )
203{
204 struct hostent *response;
205 U32 ip;
206 BOOL result = FALSE;
207
208 response = gethostbyname(domain_name.c_str());
209
210 if(response != NULL)
211 {
212 if(response->h_addrtype == AF_INET)
213 {
214 ip = ((struct in_addr*)response->h_addr_list[0])->s_addr;
215 result = TRUE;
216 (*callback)(result, domain_name, ip, userdata);
217 }
218 }
219 return result;
220}
221
222
223BOOL LLAsyncHostByName::cancelPendingRequest()
224{
225 // Since this implementation is synchronous, there's nothing to do here.
226 return TRUE;
227}
228#endif // !LL_WINDOWS