mirror of
https://github.com/nzp-team/fteqw.git
synced 2024-11-10 22:51:57 +00:00
Added support for multiple simultaneous downloads.
git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@1493 fc73d0e0-1445-4013-8a0c-d673dee63da5
This commit is contained in:
parent
aeff202074
commit
aec49a7bb0
1 changed files with 28 additions and 9 deletions
|
@ -67,7 +67,7 @@ It doesn't use persistant connections.
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
typedef struct {
|
typedef struct http_con_s {
|
||||||
int sock;
|
int sock;
|
||||||
|
|
||||||
enum {HC_REQUESTING,HC_GETTINGHEADER, HC_GETTING} state;
|
enum {HC_REQUESTING,HC_GETTINGHEADER, HC_GETTING} state;
|
||||||
|
@ -88,6 +88,7 @@ typedef struct {
|
||||||
IWEBFILE *file;
|
IWEBFILE *file;
|
||||||
|
|
||||||
void (*NotifyFunction)(char *localfile, qboolean sucess); //called when failed or succeeded, and only if it got a connection in the first place.
|
void (*NotifyFunction)(char *localfile, qboolean sucess); //called when failed or succeeded, and only if it got a connection in the first place.
|
||||||
|
struct http_con_s *next;
|
||||||
} http_con_t;
|
} http_con_t;
|
||||||
|
|
||||||
static http_con_t *httpcl;
|
static http_con_t *httpcl;
|
||||||
|
@ -216,7 +217,11 @@ static qboolean HTTP_CL_Run(http_con_t *con)
|
||||||
if (!*Location)
|
if (!*Location)
|
||||||
Con_Printf("Server redirected to null location\n");
|
Con_Printf("Server redirected to null location\n");
|
||||||
else
|
else
|
||||||
HTTP_CL_Get(Location, con->filename, con->NotifyFunction);
|
{
|
||||||
|
if (HTTP_CL_Get(Location, con->filename, con->NotifyFunction))
|
||||||
|
con->NotifyFunction = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -363,7 +368,8 @@ static qboolean HTTP_CL_Run(http_con_t *con)
|
||||||
void HTTP_CL_Think(void)
|
void HTTP_CL_Think(void)
|
||||||
{
|
{
|
||||||
http_con_t *con = httpcl;
|
http_con_t *con = httpcl;
|
||||||
if (con)
|
http_con_t *prev = NULL;
|
||||||
|
while (con)
|
||||||
{
|
{
|
||||||
if (!HTTP_CL_Run(con))
|
if (!HTTP_CL_Run(con))
|
||||||
{
|
{
|
||||||
|
@ -373,16 +379,19 @@ void HTTP_CL_Think(void)
|
||||||
if (cls.downloadmethod == DL_HTTP)
|
if (cls.downloadmethod == DL_HTTP)
|
||||||
cls.downloadmethod = DL_NONE;
|
cls.downloadmethod = DL_NONE;
|
||||||
closesocket(con->sock);
|
closesocket(con->sock);
|
||||||
|
|
||||||
|
if (prev)
|
||||||
|
prev->next = con->next;
|
||||||
|
else
|
||||||
|
httpcl = con->next;
|
||||||
|
|
||||||
if (con->buffer)
|
if (con->buffer)
|
||||||
IWebFree(con->buffer);
|
IWebFree(con->buffer);
|
||||||
IWebFree(con);
|
IWebFree(con);
|
||||||
if (con == httpcl)
|
|
||||||
{
|
//I don't fancy fixing this up.
|
||||||
httpcl = NULL;
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
con = NULL;
|
|
||||||
}
|
|
||||||
else if (!cls.downloadmethod)
|
else if (!cls.downloadmethod)
|
||||||
{
|
{
|
||||||
cls.downloadmethod = DL_HTTP;
|
cls.downloadmethod = DL_HTTP;
|
||||||
|
@ -406,9 +415,16 @@ void HTTP_CL_Think(void)
|
||||||
cls.downloadpercent = con->totalreceived*100.0f/con->contentlength;
|
cls.downloadpercent = con->totalreceived*100.0f/con->contentlength;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
prev = con;
|
||||||
|
con = con->next;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//returns true if we start downloading it
|
||||||
|
//returns false if we couldn't connect
|
||||||
|
//note that this return value is actually pretty useless
|
||||||
|
//the NotifyFunction will only ever be called after this has returned true, and won't always suceed.
|
||||||
qboolean HTTP_CL_Get(char *url, char *localfile, void (*NotifyFunction)(char *localfile, qboolean sucess))
|
qboolean HTTP_CL_Get(char *url, char *localfile, void (*NotifyFunction)(char *localfile, qboolean sucess))
|
||||||
{
|
{
|
||||||
unsigned long _true = true;
|
unsigned long _true = true;
|
||||||
|
@ -509,12 +525,15 @@ qboolean HTTP_CL_Get(char *url, char *localfile, void (*NotifyFunction)(char *lo
|
||||||
con->bufferused = strlen(con->buffer);
|
con->bufferused = strlen(con->buffer);
|
||||||
con->contentlength = -1;
|
con->contentlength = -1;
|
||||||
con->NotifyFunction = NotifyFunction;
|
con->NotifyFunction = NotifyFunction;
|
||||||
|
if (!NotifyFunction)
|
||||||
|
Con_Printf("No NotifyFunction\n");
|
||||||
strcpy(con->filename, localfile);
|
strcpy(con->filename, localfile);
|
||||||
|
|
||||||
slash = strchr(con->filename, '?');
|
slash = strchr(con->filename, '?');
|
||||||
if (slash)
|
if (slash)
|
||||||
*slash = '_';
|
*slash = '_';
|
||||||
|
|
||||||
|
con->next = httpcl;
|
||||||
httpcl = con;
|
httpcl = con;
|
||||||
|
|
||||||
HTTP_CL_Think();
|
HTTP_CL_Think();
|
||||||
|
|
Loading…
Reference in a new issue