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