MCPcopy Create free account
hub / github.com/assaultcube/AC / resolverwait

Function resolverwait

source/src/serverbrowser.cpp:147–193  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

145extern bool isdedicated;
146
147bool resolverwait(const char *name, ENetAddress *address)
148{
149 if(isdedicated) return enet_address_set_host(address, name) >= 0;
150
151 if(resolverthreads.empty()) resolverinit();
152
153 defformatstring(text)("resolving %s... (esc to abort)", name);
154 show_out_of_renderloop_progress(0, text);
155
156 SDL_LockMutex(resolvermutex);
157 resolverqueries.add(name);
158 SDL_CondSignal(querycond);
159 int starttime = SDL_GetTicks(), timeout = 0;
160 bool resolved = false;
161 for(;;)
162 {
163 SDL_CondWaitTimeout(resultcond, resolvermutex, 250);
164 loopv(resolverresults) if(resolverresults[i].query == name)
165 {
166 address->host = resolverresults[i].address.host;
167 resolverresults.remove(i);
168 resolved = true;
169 break;
170 }
171 if(resolved) break;
172
173 timeout = SDL_GetTicks() - starttime;
174 show_out_of_renderloop_progress(min(float(timeout)/RESOLVERLIMIT, 1.0f), text);
175 SDL_Event event;
176 while(SDL_PollEvent(&event))
177 {
178 if(event.type == SDL_KEYDOWN && event.key.keysym.sym == SDLK_ESCAPE) timeout = RESOLVERLIMIT + 1;
179 }
180
181 if(timeout > RESOLVERLIMIT) break;
182 }
183 if(!resolved && timeout > RESOLVERLIMIT)
184 {
185 loopv(resolverthreads)
186 {
187 resolverthread &rt = resolverthreads[i];
188 if(rt.query == name) { resolverstop(rt); break; }
189 }
190 }
191 SDL_UnlockMutex(resolvermutex);
192 return resolved;
193}
194
195SDL_Thread *connthread = NULL;
196SDL_mutex *connmutex = NULL;

Callers

nothing calls this directly

Calls 8

resolverinitFunction · 0.85
minFunction · 0.85
loopvFunction · 0.70
enet_address_set_hostFunction · 0.50
emptyMethod · 0.45
addMethod · 0.45
removeMethod · 0.45

Tested by

no test coverage detected