示例#1
0
int main(int argc, char** argv){

    if (argv[1] == NULL) {
        printf("./bug1 [s|l]\n");
        return 0;
    }

    FILE* fp = NULL;
    if (strcmp(argv[1],"s") == 0)
        fp = fopen("small_input.txt","r");
    else if (strcmp(argv[1],"l") == 0)
        fp = fopen("large_input.txt","r");
    else {
        printf("Not a valid argument\n");
        return;
    }
	int fd = fileno(fp);
	static char env[8192];
	static size_t env_len;
	char reqpath[2048];
	const char* errmsg;

	if ((errmsg = http_request_line(fd, reqpath, env, &env_len)))
		printf("http_request_line: %s\n", errmsg);
	fclose(fp);
}
示例#2
0
文件: zookd.c 项目: jaycelq/lab_6.858
static void process_client(int fd)
{
    static char env[8192];  /* static variables are not on the stack */
    static size_t env_len;
    char reqpath[2048];
    const char *errmsg;
    int i;

    /* get the request line */
    if ((errmsg = http_request_line(fd, reqpath, env, &env_len)))
        return http_err(fd, 500, "http_request_line: %s", errmsg);

    for (i = 0; i < nsvcs; ++i)
    {
        if (!regexec(&svcurls[i], reqpath, 0, 0, 0))
        {
            warnx("Forward %s to service %d", reqpath, i + 1);
            break;
        }
    }

    if (i == nsvcs)
        return http_err(fd, 500, "Error dispatching request: %s", reqpath);

    if (sendfd(svcfds[i], env, env_len, fd) <= 0)
        return http_err(fd, 500, "Error forwarding request: %s", reqpath);

    close(fd);
}