From 5cbc215b56667c60a55a3b757306936058ed99ff Mon Sep 17 00:00:00 2001 From: Rudolf Polzer Date: Wed, 17 Aug 2011 21:16:45 +0200 Subject: [PATCH] prevent early urllib slot reuse --- qcsrc/common/urllib.qc | 33 ++++++++++++++++++++++++--------- 1 file changed, 24 insertions(+), 9 deletions(-) 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 { -- 2.39.2