优化代码结构

This commit is contained in:
源文雨 2022-11-29 13:19:28 +08:00
parent 281cbf876f
commit 8ecab42ea4

10
c302.c
View File

@ -21,15 +21,13 @@ int main(int argc, char **argv) {
http_error(HTTP500, "Argument Count Error.");
return 1;
}
srand(time(NULL));
uint32_t i = rand() % (sizeof(urls)/sizeof(char*));
uint32_t i = time(NULL) % (sizeof(urls)/sizeof(char*));
uint32_t len = sizeof(HTTP302HEAD)-1 + urlsl[i] + 4 + sizeof(CONTENT)-1;
const struct iovec iov[5] = {
const struct iovec iov[4] = {
{(void *)&len, sizeof(uint32_t)},
{HTTP302HEAD, sizeof(HTTP302HEAD)-1},
{(void *)urls[i], urlsl[i]},
{"\r\n\r\n", 4},
{CONTENT, sizeof(CONTENT)-1}
{"\r\n\r\n" CONTENT, 4+sizeof(CONTENT)-1}
};
return writev(1, (const struct iovec *)&iov, 5) != len+sizeof(uint32_t);
return writev(1, (const struct iovec *)&iov, 4) != len+sizeof(uint32_t);
}