W3_Library_Init();
struct W3* w3 = W3_Create("http", argv[1], 80);
if(w3 != NULL){
+ W3_Set_Read_Size(w3, 1024);
W3_Set_Method(w3, argv[3] == NULL ? "GET" : argv[3]);
W3_Set_Path(w3, argv[2]);
W3_On(w3, "status", (void*)status);
w3->headers = NULL;
w3->size = 0;
w3->data = NULL;
+ w3->readsize = 512;
w3->protocol = __W3_Strdup(protocol);
if(strcmp(protocol, "file") != 0){
w3->hostname = __W3_Strdup(hostname);
return w3;
}
+void W3_Set_Read_Size(struct W3* w3, size_t size){
+ w3->readsize = size;
+}
+
void W3_Set_Method(struct W3* w3, const char* method){
if(w3->method != NULL) free(w3->method);
w3->method = __W3_Strdup(method);
void(*func)(struct W3*, int) = (void(*)(struct W3*, int))funcptr;
func(w3, LIBW3_FILE_FOUND);
}
- char* buf = malloc(512);
+ char* buf = malloc(w3->readsize);
while(true){
- int len = fread(buf, 1, 512, f);
+ int len = fread(buf, 1, w3->readsize, f);
void* funcptr = __W3_Get_Event(w3, "data");
if(funcptr != NULL){
void(*func)(struct W3*, char*, size_t) = (void(*)(struct W3*, char*, size_t))funcptr;
if(w3->data != NULL){
__W3_Auto_Write(w3, w3->data, w3->size);
}
- char* buf = malloc(512);
+ char* buf = malloc(w3->readsize);
char* statusbuf = malloc(1);
statusbuf[0] = 0;
char* headerbuf = malloc(1);
headerbuf[0] = 0;
int phase = 0;
while(true){
- int l = __W3_Auto_Read(w3, buf, 512);
+ int l = __W3_Auto_Read(w3, buf, w3->readsize);
if(l <= 0) break;
int i;
for(i = 0; i < l; i++){
#include "W3Version.h"
struct W3 {
- int sock; /* Socket */
- char* protocol; /* As you can read from its name */
- char* method; /* Used in HTTP */
- char* path; /* As you can read from its name */
- char* hostname; /* As you can read from its name */
- char** headers; /* As you can read from its name */
- void** events; /* As you can read from its name */
- int status; /* As you can read from its name */
- char* data; /* As you can read from its name */
- size_t size; /* Size of the data */
+ int sock; /* Socket */
+ char* protocol; /* As you can read from its name */
+ char* method; /* Used in HTTP */
+ char* path; /* As you can read from its name */
+ char* hostname; /* As you can read from its name */
+ char** headers; /* As you can read from its name */
+ void** events; /* As you can read from its name */
+ int status; /* As you can read from its name */
+ char* data; /* As you can read from its name */
+ size_t size; /* Size of the data */
+ size_t readsize; /* Read buffer size, default is 512 */
#ifdef SSL_SUPPORT
- void* ssl; /* Actually SSL*, NULL if no SSL */
- void* ssl_ctx; /* Actually SSL_CTX* */
+ void* ssl; /* Actually SSL*, NULL if no SSL */
+ void* ssl_ctx; /* Actually SSL_CTX* */
#endif
};
void W3_Free(struct W3* w3); /* Free the struct */
void W3_On(struct W3* w3, const char* eventname, void* func); /* Set Handlers */
void W3_Set_Data(struct W3* w3, char* data, size_t size); /* Send the data - LibW3 won't free the data */
+void W3_Set_Read_Size(struct W3* w3, size_t size); /* Change the read buffer size */
#ifdef __cplusplus
}
extern "C" {
#endif
-#define LIBW3_VERSION "1.2" \
+#define LIBW3_VERSION "1.2A" \
SUFFIX
#ifdef __cplusplus