ksgi

Форк
0
/
test-fcgi-ping-double.c 
119 строк · 2.7 Кб
1
/*	$Id$ */
2
/*
3
 * Copyright (c) 2018 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 <unistd.h>
23

24
#include <curl/curl.h>
25

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

29
static int
30
parent1(CURL *curl)
31
{
32

33
	curl_easy_setopt(curl, CURLOPT_URL, 
34
		"http://localhost:17123/index1.html");
35
	return CURLE_OK == curl_easy_perform(curl);
36
}
37

38
static int
39
parent2(CURL *curl)
40
{
41

42
	curl_easy_setopt(curl, CURLOPT_URL, 
43
		"http://localhost:17123/index2.html");
44
	return CURLE_OK == curl_easy_perform(curl);
45
}
46

47
static int
48
child1(void)
49
{
50
	struct kreq	 r;
51
	const char 	*page[] = { "index1", "index2" };
52
	struct kfcgi	*fcgi;
53
	enum kcgi_err	 er;
54

55
	if ( ! khttp_fcgi_test())
56
		return 0;
57
	if (KCGI_OK != khttp_fcgi_init(&fcgi, NULL, 0, page, 2, 1))
58
		return 0;
59

60
	while (KCGI_OK == (er = khttp_fcgi_parse(fcgi, &r))) {
61
		if (0 != r.page) {
62
			khttp_free(&r);
63
			khttp_fcgi_free(fcgi);
64
			return 0;
65
		}
66
		khttp_head(&r, kresps[KRESP_STATUS], 
67
			"%s", khttps[KHTTP_200]);
68
		khttp_head(&r, kresps[KRESP_CONTENT_TYPE], 
69
			"%s", kmimetypes[KMIME_TEXT_HTML]);
70
		khttp_body(&r);
71
		khttp_free(&r);
72
	}
73

74
	khttp_free(&r);
75
	khttp_fcgi_free(fcgi);
76
	return KCGI_HUP == er ? 1 : 0;
77
}
78

79
static int
80
child2(void)
81
{
82
	struct kreq	 r;
83
	const char 	*page[] = { "index1", "index2" };
84
	struct kfcgi	*fcgi;
85
	enum kcgi_err	 er;
86

87
	if ( ! khttp_fcgi_test())
88
		return 0;
89
	if (KCGI_OK != khttp_fcgi_init(&fcgi, NULL, 0, page, 2, 0))
90
		return 0;
91

92
	while (KCGI_OK == (er = khttp_fcgi_parse(fcgi, &r))) {
93
		if (1 != r.page) {
94
			khttp_free(&r);
95
			khttp_fcgi_free(fcgi);
96
			return 0;
97
		}
98
		khttp_head(&r, kresps[KRESP_STATUS], 
99
			"%s", khttps[KHTTP_200]);
100
		khttp_head(&r, kresps[KRESP_CONTENT_TYPE], 
101
			"%s", kmimetypes[KMIME_TEXT_HTML]);
102
		khttp_body(&r);
103
		khttp_free(&r);
104
	}
105

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

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

115
	if ( ! regress_fcgi(parent1, child1))
116
		return EXIT_FAILURE;
117
	return regress_fcgi(parent2, child2) ? 
118
		EXIT_SUCCESS : EXIT_FAILURE;
119
}
120

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

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

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

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