mirror of
https://github.com/fumiama/CMoe-Counter.git
synced 2025-02-15 10:02:36 +01:00
优化一点速度
This commit is contained in:
parent
57e4e4f8b6
commit
1038f10938
23
cmoe.c
23
cmoe.c
@ -9,13 +9,6 @@
|
|||||||
static uint32_t* items_len;
|
static uint32_t* items_len;
|
||||||
static COUNTER counter;
|
static COUNTER counter;
|
||||||
|
|
||||||
static void write2stdo(char* buf, uint32_t size, uint32_t content_len) {
|
|
||||||
content_len += size;
|
|
||||||
fwrite((char*)&content_len, sizeof(uint32_t), 1, stdout);
|
|
||||||
fwrite(buf, size, 1, stdout);
|
|
||||||
fflush(stdout);
|
|
||||||
}
|
|
||||||
|
|
||||||
#define ADD_HERDER(h) {\
|
#define ADD_HERDER(h) {\
|
||||||
strcpy(buf + offset, (h));\
|
strcpy(buf + offset, (h));\
|
||||||
offset += sizeof((h)) - 1;\
|
offset += sizeof((h)) - 1;\
|
||||||
@ -34,12 +27,17 @@ static void headers(uint32_t content_len, const char* content_type) {
|
|||||||
ADD_HERDER_PARAM(CONTENT_TYPE, content_type);
|
ADD_HERDER_PARAM(CONTENT_TYPE, content_type);
|
||||||
ADD_HERDER_PARAM(CONTENT_LEN "\r\n", content_len);
|
ADD_HERDER_PARAM(CONTENT_LEN "\r\n", content_len);
|
||||||
write2stdo(buf, offset, content_len);
|
write2stdo(buf, offset, content_len);
|
||||||
|
content_len += offset;
|
||||||
|
write(1, (char*)&content_len, sizeof(uint32_t));
|
||||||
|
write(1, buf, offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void http_error(const char* type, const char* msg) {
|
static void http_error(const char* type, const char* msg) {
|
||||||
char* str = malloc(strlen(type) + strlen(msg));
|
char* str = malloc(strlen(type) + strlen(msg));
|
||||||
|
uint32_t len = strlen(str);
|
||||||
sprintf(str, type, msg);
|
sprintf(str, type, msg);
|
||||||
write2stdo(str, strlen(str), 0);
|
write(1, (char*)&len, sizeof(uint32_t));
|
||||||
|
write(1, str, len);
|
||||||
free(str);
|
free(str);
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
@ -147,15 +145,14 @@ static void return_count(char* name, char* theme) {
|
|||||||
head = svg_small;
|
head = svg_small;
|
||||||
}
|
}
|
||||||
headers(get_content_len(isbig, len_type, cntstr), "image/svg+xml");
|
headers(get_content_len(isbig, len_type, cntstr), "image/svg+xml");
|
||||||
fwrite(head, sizeof(svg_small)-1, 1, stdout);
|
write(1, head, sizeof(svg_small)-1);
|
||||||
for(int i = 0; i < 10; i++) {
|
for(int i = 0; i < 10; i++) {
|
||||||
printf(img_slot_front, w * i, w, h);
|
printf(img_slot_front, w * i, w, h);
|
||||||
int n = cntstr[i] - '0';
|
int n = cntstr[i] - '0';
|
||||||
fwrite(theme_type[n], len_type[n], 1, stdout);
|
write(1, theme_type[n], len_type[n]);
|
||||||
printf(img_slot_rear);
|
printf(img_slot_rear);
|
||||||
}
|
}
|
||||||
fwrite(svg_tail, sizeof(svg_tail)-1, 1, stdout);
|
write(1, svg_tail, sizeof(svg_tail)-1);
|
||||||
fflush(stdout);
|
|
||||||
}
|
}
|
||||||
free(spb);
|
free(spb);
|
||||||
user_exist = 1;
|
user_exist = 1;
|
||||||
@ -215,7 +212,7 @@ int main(int argc, char **argv) {
|
|||||||
fclose(fp);
|
fclose(fp);
|
||||||
char* msg = "<P>Success.\r\n";
|
char* msg = "<P>Success.\r\n";
|
||||||
headers(strlen(msg), "text/html");
|
headers(strlen(msg), "text/html");
|
||||||
fwrite(msg, strlen(msg), 1, stdout);
|
write(1, msg, strlen(msg));
|
||||||
} else http_error(HTTP500, "Open File Error.");
|
} else http_error(HTTP500, "Open File Error.");
|
||||||
} else http_error(HTTP400, "Name Exist.");
|
} else http_error(HTTP400, "Name Exist.");
|
||||||
} else http_error(HTTP400, "Null Register Token.");
|
} else http_error(HTTP400, "Null Register Token.");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user