From: Rudolf Polzer Date: Wed, 17 Aug 2011 19:16:45 +0000 (+0200) Subject: prevent early urllib slot reuse X-Git-Tag: xonotic-v0.5.0~128 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=5cbc215b56667c60a55a3b757306936058ed99ff;p=xonotic%2Fxonotic-data.pk3dir.git prevent early urllib slot reuse --- diff --git a/qcsrc/common/urllib.qc b/qcsrc/common/urllib.qc index f4103ea69..7898e9206 100644 --- a/qcsrc/common/urllib.qc +++ b/qcsrc/common/urllib.qc @@ -14,6 +14,7 @@ #define MIN_URL_ID 128 #define NUM_URL_ID 64 entity url_fromid[NUM_URL_ID]; +float autocvar__urllib_nextslot; float url_URI_Get_Callback(float id, float status, string data) { @@ -96,13 +97,19 @@ void url_fopen(string url, float mode, url_ready_func rdy, entity pass) case FILE_READ: // read data only - for(i = 0; i < NUM_URL_ID; ++i) + for(i = autocvar__urllib_nextslot; i < NUM_URL_ID; ++i) if(url_fromid[i] == world) break; if(i >= NUM_URL_ID) { - rdy(world, pass, URL_READY_ERROR); - return; + for(i = 0; i < autocvar__urllib_nextslot; ++i) + if(url_fromid[i] == world) + break; + if(i >= autocvar__urllib_nextslot) + { + rdy(world, pass, URL_READY_ERROR); + return; + } } e = spawn(); @@ -122,6 +129,7 @@ void url_fopen(string url, float mode, url_ready_func rdy, entity pass) e.url_ready_pass = pass; e.url_id = i; url_fromid[i] = e; + cvar_set("_urllib_nextslot", ftos(mod(i + 1, NUM_URL_ID))); break; } } @@ -155,16 +163,22 @@ void url_fclose(entity e, url_ready_func rdy, entity pass) { if(e.url_wbuf >= 0) { - for(i = 0; i < NUM_URL_ID; ++i) + for(i = autocvar__urllib_nextslot; i < NUM_URL_ID; ++i) if(url_fromid[i] == world) break; if(i >= NUM_URL_ID) { - buf_del(e.url_wbuf); - rdy(e, pass, URL_READY_ERROR); - strunzone(e.url_url); - remove(e); - return; + for(i = 0; i < autocvar__urllib_nextslot; ++i) + if(url_fromid[i] == world) + break; + if(i >= autocvar__urllib_nextslot) + { + buf_del(e.url_wbuf); + rdy(e, pass, URL_READY_ERROR); + strunzone(e.url_url); + remove(e); + return; + } } if(!uri_postbuf(e.url_url, e.url_id + MIN_URL_ID, "text/plain", "\n", e.url_wbuf)) @@ -182,6 +196,7 @@ void url_fclose(entity e, url_ready_func rdy, entity pass) e.url_ready_pass = pass; e.url_id = i; url_fromid[i] = e; + cvar_set("_urllib_nextslot", ftos(mod(i + 1, NUM_URL_ID))); } else {