mirror of
https://github.com/fumiama/CMoe-Counter.git
synced 2025-02-10 15:53:03 +01:00
增加长度头
This commit is contained in:
parent
83a003499b
commit
d576d7162a
14
cmoe.c
14
cmoe.c
@ -8,6 +8,13 @@
|
|||||||
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;
|
||||||
@ -24,11 +31,14 @@ static void headers(uint32_t content_len, const char* content_type, int no_cache
|
|||||||
if(no_cache) ADD_HERDER(CACHE_CTRL);
|
if(no_cache) ADD_HERDER(CACHE_CTRL);
|
||||||
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);
|
||||||
fwrite(buf, offset, 1, stdout);
|
write2stdo(buf, offset, content_len);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void http_error(const char* type, const char* msg) {
|
static void http_error(const char* type, const char* msg) {
|
||||||
fprintf(stdout, type, msg);
|
char* str = malloc(strlen(type) + strlen(msg));
|
||||||
|
sprintf(str, type, msg);
|
||||||
|
write2stdo(str, strlen(str), 0);
|
||||||
|
free(str);
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user