ksgi

Форк
0
/
test-fcgi-bigfile.c 
115 строк · 2.7 Кб
1
/*	$Id$ */
2
/*
3
 * Copyright (c) 2015 Kristaps Dzonsons <kristaps@bsd.lv>
4
 *
5
 * Permission to use, copy, modify, and distribute this software for any
6
 * purpose with or without fee is hereby granted, provided that the above
7
 * copyright notice and this permission notice appear in all copies.
8
 *
9
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16
 */
17
#include "../config.h"
18

19
#include <stdarg.h>
20
#include <stdint.h>
21
#include <stdlib.h>
22
#include <string.h>
23
#include <unistd.h>
24

25
#include <curl/curl.h>
26

27
#include "../kcgi.h"
28
#include "regress.h"
29

30
static size_t
31
doign(void *ptr, size_t sz, size_t nm, void *arg)
32
{
33

34
	*(size_t *)arg += sz * nm;
35
	return(sz * nm);
36
}
37

38
static int
39
parent(CURL *curl)
40
{
41
	char		*p;
42
	size_t		 i;
43

44
	p = malloc(1024 * 1024 + 5);
45
	strncpy(p, "tag=", 5);
46
	for (i = 0; i < 1024 * 1024; i++)
47
		p[i + 4] = (i % 10) + 65;
48
	p[1024 * 1024 + 4] = '\0';
49

50
	i = 0;
51
	curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, doign);
52
	curl_easy_setopt(curl, CURLOPT_WRITEDATA, &i);
53
	curl_easy_setopt(curl, CURLOPT_POSTFIELDS, p);
54
	curl_easy_setopt(curl, CURLOPT_URL, 
55
		"http://localhost:17123/");
56
	if (CURLE_OK != curl_easy_perform(curl)) {
57
		free(p);
58
		return(0);
59
	}
60
	free(p);
61
	return(i >= 1024 * 1024);
62
}
63

64
static int
65
child(void)
66
{
67
	struct kreq	 r;
68
	const char 	*page = "index";
69
	struct kvalid	 valid = { NULL, "tag" };
70
	size_t		 i;
71
	struct kfcgi	*fcgi;
72
	enum kcgi_err	 er;
73

74
	if (KCGI_OK != khttp_fcgi_init(&fcgi, &valid, 1, &page, 1, 0))
75
		return(0);
76

77
	while (KCGI_OK == (er = khttp_fcgi_parse(fcgi, &r))) {
78
		if (NULL == r.fieldmap[0]) {
79
			khttp_free(&r);
80
			khttp_fcgi_free(fcgi);
81
			return(0);
82
		} else if (1024 * 1024 != r.fieldmap[0]->valsz) {
83
			khttp_free(&r);
84
			khttp_fcgi_free(fcgi);
85
			return(0);
86
		}
87

88
		for (i = 0; i < 1024 * 1024; i++)
89
			if ((unsigned char)r.fieldmap[0]->val[i] != 
90
			    (i % 10) + 65) {
91
				khttp_free(&r);
92
				khttp_fcgi_free(fcgi);
93
				return(0);
94
			}
95

96
		khttp_head(&r, kresps[KRESP_STATUS], 
97
			"%s", khttps[KHTTP_200]);
98
		khttp_head(&r, kresps[KRESP_CONTENT_TYPE], 
99
			"%s", kmimetypes[KMIME_TEXT_HTML]);
100
		khttp_body(&r);
101
		khttp_write(&r, r.fieldmap[0]->val, r.fieldmap[0]->valsz);
102
		khttp_free(&r);
103
	}
104

105
	khttp_free(&r);
106
	khttp_fcgi_free(fcgi);
107
	return(KCGI_HUP == er ? 1 : 0);
108
}
109

110
int
111
main(int argc, char *argv[])
112
{
113

114
	return(regress_fcgi(parent, child) ? EXIT_SUCCESS : EXIT_FAILURE);
115
}
116

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.