preparing http requests
This commit is contained in:
parent
01a7e04793
commit
b30e3e78c9
|
@ -8,13 +8,29 @@
|
||||||
|
|
||||||
static HINTERNET internet = 0;
|
static HINTERNET internet = 0;
|
||||||
|
|
||||||
|
#define REQ_PROGRESS 0
|
||||||
|
#define REQ_DONE 1
|
||||||
|
#define REQ_FREE 2
|
||||||
|
|
||||||
|
struct request {
|
||||||
|
u8 *response;
|
||||||
|
u32 response_length;
|
||||||
|
HINTERNET handle;
|
||||||
|
u8 status;
|
||||||
|
};
|
||||||
|
|
||||||
|
static struct request *requests = 0;
|
||||||
|
static u32 request_count = 0;
|
||||||
|
|
||||||
static void init_internet();
|
static void init_internet();
|
||||||
|
static u32 next_free_request();
|
||||||
|
|
||||||
struct sw_http_request_handle sw_http_request_async(char *url) {
|
struct sw_http_request_handle sw_http_request_async(char *url) {
|
||||||
HINTERNET session, http;
|
HINTERNET session, http;
|
||||||
u16 port;
|
u16 port;
|
||||||
char *proto, *rest;
|
char *proto, *rest;
|
||||||
char *server, *rest2;
|
char *server, *rest2;
|
||||||
|
u32 req;
|
||||||
|
|
||||||
sw_str_split2(url, "://", &proto, &rest);
|
sw_str_split2(url, "://", &proto, &rest);
|
||||||
if(proto == 0) {
|
if(proto == 0) {
|
||||||
|
@ -52,7 +68,10 @@ struct sw_http_request_handle sw_http_request_async(char *url) {
|
||||||
sw_win32_error();
|
sw_win32_error();
|
||||||
}
|
}
|
||||||
|
|
||||||
return (struct sw_http_request_handle){0};
|
req = next_free_request();
|
||||||
|
requests[req].handle = http;
|
||||||
|
|
||||||
|
return (struct sw_http_request_handle){req};
|
||||||
}
|
}
|
||||||
|
|
||||||
static void init_internet() {
|
static void init_internet() {
|
||||||
|
@ -65,3 +84,24 @@ static void init_internet() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static u32 next_free_request() {
|
||||||
|
u32 i;
|
||||||
|
|
||||||
|
for(i = 0; i < request_count; ++i) {
|
||||||
|
if(requests[i].status == REQ_FREE) {
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
request_count += 1;
|
||||||
|
|
||||||
|
requests = realloc(requests, sizeof(struct request) * request_count);
|
||||||
|
|
||||||
|
requests[request_count - 1].handle = 0;
|
||||||
|
requests[request_count - 1].response = 0;
|
||||||
|
requests[request_count - 1].response_length = 0;
|
||||||
|
requests[request_count - 1].status = REQ_PROGRESS;
|
||||||
|
|
||||||
|
return request_count - 1;
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue