[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r34716 - libmicrohttpd/src/testspdy
From: |
gnunet |
Subject: |
[GNUnet-SVN] r34716 - libmicrohttpd/src/testspdy |
Date: |
Sat, 20 Dec 2014 01:25:22 +0100 |
Author: grothoff
Date: 2014-12-20 01:25:22 +0100 (Sat, 20 Dec 2014)
New Revision: 34716
Modified:
libmicrohttpd/src/testspdy/test_misc.c
libmicrohttpd/src/testspdy/test_proxies.c
libmicrohttpd/src/testspdy/test_request_response.c
libmicrohttpd/src/testspdy/test_session_timeout.c
Log:
-check RVals
Modified: libmicrohttpd/src/testspdy/test_misc.c
===================================================================
--- libmicrohttpd/src/testspdy/test_misc.c 2014-12-20 00:18:06 UTC (rev
34715)
+++ libmicrohttpd/src/testspdy/test_misc.c 2014-12-20 00:25:22 UTC (rev
34716)
@@ -68,7 +68,7 @@
child = fork();
if (-1 == child)
- {
+ {
fprintf(stderr, "can't fork, error %d\n", errno);
exit(EXIT_FAILURE);
}
@@ -79,6 +79,8 @@
char *uri;
fflush(stdout);
devnull = open("/dev/null", O_WRONLY);
+ if (-1 == devnull)
+ abort ();
if (1 != devnull)
{
dup2(devnull, 1);
@@ -100,7 +102,7 @@
{
(void)status;
(void)streamopened;
-
+
if(strcmp(cls,"/main.css"))
{
session1 = SPDY_get_session_for_request(request);
@@ -109,7 +111,7 @@
printf("SPDY_get_session_for_request failed\n");
killchild();
}
-
+
char *session_cls = strdup(SESSION_CLS);
SPDY_set_cls_to_session(session1,session_cls);
}
@@ -122,7 +124,7 @@
killchild();
}
printf("SPDY_get_session_for_request tested...\n");
-
+
void *session_cls = SPDY_get_cls_from_session(session2);
if(NULL == session_cls || strcmp(session_cls, SESSION_CLS))
{
@@ -131,7 +133,7 @@
}
printf("SPDY_set_cls_to_session tested...\n");
printf("SPDY_get_cls_from_session tested...\n");
-
+
void *request_cls = SPDY_get_cls_from_request(request);
if(NULL == request_cls || strcmp(request_cls, REQUEST_CLS))
{
@@ -141,7 +143,7 @@
printf("SPDY_set_cls_to_request tested...\n");
printf("SPDY_get_cls_from_request tested...\n");
}
-
+
SPDY_destroy_request(request);
SPDY_destroy_response(response);
free(cls);
@@ -168,10 +170,10 @@
(void)method;
(void)version;
(void)more;
-
+
struct SPDY_Response *response=NULL;
char *cls_path = strdup(path);
-
+
if(strcmp(path,"/main.css")==0)
{
char *request_cls = strdup(REQUEST_CLS);
@@ -182,12 +184,12 @@
{
response =
SPDY_build_response(200,NULL,SPDY_HTTP_VERSION_1_1,NULL,HTML,strlen(HTML));
}
-
+
if(NULL==response){
fprintf(stdout,"no response obj\n");
killchild();
}
-
+
if(SPDY_queue_response(request,response,true,false,&response_done_callback,cls_path)!=SPDY_YES)
{
fprintf(stdout,"queue\n");
@@ -197,7 +199,7 @@
int
parentproc()
-{
+{
int childstatus;
unsigned long long timeoutlong=0;
struct timeval timeout;
@@ -207,7 +209,7 @@
fd_set except_fd_set;
int maxfd = -1;
struct SPDY_Daemon *daemon;
-
+
daemon = SPDY_start_daemon(port,
DATA_DIR
"cert-and-key.pem",
DATA_DIR
"cert-and-key.pem",
@@ -219,12 +221,12 @@
SPDY_DAEMON_OPTION_SESSION_TIMEOUT,
1800,
SPDY_DAEMON_OPTION_END);
-
+
if(NULL==daemon){
printf("no daemon\n");
return 1;
}
-
+
create_child();
do
@@ -244,14 +246,14 @@
timeout.tv_sec = timeoutlong / 1000;
timeout.tv_usec = (timeoutlong % 1000) * 1000;
}
-
+
maxfd = SPDY_get_fdset (daemon,
&read_fd_set,
- &write_fd_set,
+ &write_fd_set,
&except_fd_set);
-
+
ret = select(maxfd+1, &read_fd_set, &write_fd_set,
&except_fd_set, &timeout);
-
+
switch(ret) {
case -1:
printf("select error: %i\n", errno);
@@ -268,7 +270,7 @@
while(waitpid(child,&childstatus,WNOHANG) != child);
SPDY_stop_daemon(daemon);
-
+
return WEXITSTATUS(childstatus);
}
@@ -278,10 +280,10 @@
{
port = get_port(13123);
SPDY_init();
-
+
int ret = parentproc();
-
+
SPDY_deinit();
-
+
return ret;
}
Modified: libmicrohttpd/src/testspdy/test_proxies.c
===================================================================
--- libmicrohttpd/src/testspdy/test_proxies.c 2014-12-20 00:18:06 UTC (rev
34715)
+++ libmicrohttpd/src/testspdy/test_proxies.c 2014-12-20 00:25:22 UTC (rev
34716)
@@ -80,7 +80,7 @@
if (child == -1)
{
killchildren();
-
+
killproc(parent,"fork failed\n");
}
@@ -93,7 +93,7 @@
//pid_t child;
int childstatus;
pid_t wpid;
-
+
parent = getpid();
mhd_port = get_port(4000);
spdy2http_port = get_port(4100);
@@ -119,8 +119,8 @@
//killchildren();
_exit(1);
}
-
-
+
+
child_spdy2http = au_fork();
if (child_spdy2http == 0)
{
@@ -144,7 +144,7 @@
//killchildren();
_exit(1);
}
-
+
child_mhd2spdy = au_fork();
if (child_mhd2spdy == 0)
{
@@ -168,7 +168,7 @@
//killchildren();
_exit(1);
}
-
+
child_curl = au_fork();
if (child_curl == 0)
{
@@ -181,12 +181,14 @@
close(1);
devnull = open("/dev/null", O_WRONLY);
+ if (-1 == devnull)
+ abort ();
if (1 != devnull)
{
dup2(devnull, 1);
close(devnull);
}
-
+
asprintf (&cmd, "curl --proxy http://127.0.0.1:%i
http://127.0.0.1:%i/", mhd2spdy_port, mhd_port);
sleep(3);
p = popen(cmd, "r");
@@ -205,7 +207,7 @@
//killchildren();
_exit(1);
}
-
+
do
{
wpid = waitpid(child_mhd,&childstatus,WNOHANG);
@@ -215,7 +217,7 @@
killchildren();
return 1;
}
-
+
wpid = waitpid(child_spdy2http,&childstatus,WNOHANG);
if(wpid == child_spdy2http)
{
@@ -223,7 +225,7 @@
killchildren();
return 1;
}
-
+
wpid = waitpid(child_mhd2spdy,&childstatus,WNOHANG);
if(wpid == child_mhd2spdy)
{
@@ -231,7 +233,7 @@
killchildren();
return 1;
}
-
+
if(waitpid(child_curl,&childstatus,WNOHANG) == child_curl)
{
killchildren();
Modified: libmicrohttpd/src/testspdy/test_request_response.c
===================================================================
--- libmicrohttpd/src/testspdy/test_request_response.c 2014-12-20 00:18:06 UTC
(rev 34715)
+++ libmicrohttpd/src/testspdy/test_request_response.c 2014-12-20 00:25:22 UTC
(rev 34716)
@@ -39,7 +39,7 @@
int rcvbuf_c = 0;
int session_closed_called = 0;
-
+
void
killchild(int pid, char *message)
{
@@ -55,8 +55,8 @@
kill(pid, SIGKILL);
_exit(1);
}
-
+
/*****
* start of code needed to utilize spdylay
*/
@@ -131,6 +131,8 @@
{
char *dst;
dst = malloc(len+1);
+ if (NULL == dst)
+ abort ();
memcpy(dst, s, len);
dst[len] = '\0';
return dst;
@@ -204,7 +206,7 @@
{
(void)session;
(void)flags;
-
+
struct Connection *connection;
ssize_t rv;
connection = (struct Connection*)user_data;
@@ -236,7 +238,7 @@
{
(void)session;
(void)flags;
-
+
struct Connection *connection;
ssize_t rv;
connection = (struct Connection*)user_data;
@@ -270,7 +272,7 @@
void *user_data)
{
(void)user_data;
-
+
if(type == SPDYLAY_SYN_STREAM) {
struct Request *req;
int stream_id = frame->syn_stream.stream_id;
@@ -287,7 +289,7 @@
spdylay_frame *frame, void *user_data)
{
(void)user_data;
-
+
char **nv;
const char *name = NULL;
int32_t stream_id;
@@ -360,7 +362,7 @@
{
(void)user_data;
(void)status_code;
-
+
struct Request *req;
req = spdylay_session_get_stream_user_data(session, stream_id);
if(req) {
@@ -385,7 +387,7 @@
{
(void)user_data;
(void)flags;
-
+
struct Request *req;
req = spdylay_session_get_stream_user_data(session, stream_id);
if(req) {
@@ -409,13 +411,13 @@
} else {
/* TODO add support gzip */
fwrite(data, 1, len, stdout);
-
+
//check if the data is correct
//if(strcmp(RESPONSE_BODY, data) != 0)
//killparent(parent, "\nreceived data is not the same");
if(len + rcvbuf_c > strlen(RESPONSE_BODY))
killparent(parent, "\nreceived data is not the same");
-
+
strcpy(rcvbuf + rcvbuf_c,(char*)data);
rcvbuf_c+=len;
}
@@ -452,7 +454,7 @@
void *arg)
{
(void)ssl;
-
+
int rv;
uint16_t *spdy_proto_version;
/* spdylay_select_next_protocol() selects SPDY protocol version the
@@ -655,6 +657,8 @@
/* Establish connection and setup SSL */
fd = connect_to(req.host, req.port);
+ if (-1 == fd)
+ abort ();
ssl_ctx = SSL_CTX_new(SSLv23_client_method());
if(ssl_ctx == NULL) {
dief("SSL_CTX_new", ERR_error_string(ERR_get_error(), NULL));
@@ -799,8 +803,8 @@
/*****
* end of code needed to utilize spdylay
*/
-
+
/*****
* start of code needed to utilize microspdy
*/
@@ -826,26 +830,26 @@
(void)headers;
(void)method;
(void)version;
-
+
struct SPDY_Response *response=NULL;
-
+
if(strcmp(CLS,cls)!=0)
{
killchild(child,"wrong cls");
}
-
+
if(false != more){
fprintf(stdout,"more has wrong value\n");
exit(5);
}
-
+
response =
SPDY_build_response(200,NULL,SPDY_HTTP_VERSION_1_1,NULL,RESPONSE_BODY,strlen(RESPONSE_BODY));
-
+
if(NULL==response){
fprintf(stdout,"no response obj\n");
exit(3);
}
-
+
if(SPDY_queue_response(request,response,true,false,NULL,(void*)strdup(path))!=SPDY_YES)
{
fprintf(stdout,"queue\n");
@@ -859,12 +863,12 @@
int by_client)
{
printf("session_closed_handler called\n");
-
+
if(strcmp(CLS,cls)!=0)
{
killchild(child,"wrong cls");
}
-
+
if(SPDY_YES != by_client)
{
//killchild(child,"wrong by_client");
@@ -874,12 +878,12 @@
{
printf("session closed by client\n");
}
-
+
if(NULL == session)
{
killchild(child,"session is NULL");
}
-
+
session_closed_called = 1;
}
@@ -887,7 +891,7 @@
/*****
* end of code needed to utilize microspdy
*/
-
+
//child process
void
childproc(int port)
@@ -896,7 +900,7 @@
struct sigaction act;
int rv;
char *uristr;
-
+
memset(&act, 0, sizeof(struct sigaction));
act.sa_handler = SIG_IGN;
sigaction(SIGPIPE, &act, 0);
@@ -913,7 +917,7 @@
killparent(parent,"parse_uri failed");
}
fetch_uri(&uri);
-
+
if(strcmp(rcvbuf, RESPONSE_BODY))
killparent(parent,"received data is different");
}
@@ -931,14 +935,14 @@
fd_set except_fd_set;
int maxfd = -1;
struct SPDY_Daemon *daemon;
-
+
SPDY_init();
-
+
daemon = SPDY_start_daemon(port,
DATA_DIR
"cert-and-key.pem",
DATA_DIR
"cert-and-key.pem",
NULL,&session_closed_handler,&standard_request_handler,NULL,CLS,SPDY_DAEMON_OPTION_END);
-
+
if(NULL==daemon){
printf("no daemon\n");
return 1;
@@ -961,14 +965,14 @@
timeout.tv_sec = timeoutlong / 1000;
timeout.tv_usec = (timeoutlong % 1000) * 1000;
}
-
+
maxfd = SPDY_get_fdset (daemon,
&read_fd_set,
- &write_fd_set,
+ &write_fd_set,
&except_fd_set);
-
+
ret = select(maxfd+1, &read_fd_set, &write_fd_set,
&except_fd_set, &timeout);
-
+
switch(ret) {
case -1:
printf("select error: %i\n", errno);
@@ -990,9 +994,9 @@
SPDY_run(daemon);
SPDY_stop_daemon(daemon);
-
+
SPDY_deinit();
-
+
return WEXITSTATUS(childstatus);
}
@@ -1000,21 +1004,21 @@
{
int port = get_port(12123);
parent = getpid();
-
+
child = fork();
if (child == -1)
- {
+ {
fprintf(stderr, "can't fork, error %d\n", errno);
exit(EXIT_FAILURE);
}
-
+
if (child == 0)
{
childproc(port);
_exit(0);
}
else
- {
+ {
int ret = parentproc(port);
if(1 == session_closed_called && 0 == ret)
exit(0);
Modified: libmicrohttpd/src/testspdy/test_session_timeout.c
===================================================================
--- libmicrohttpd/src/testspdy/test_session_timeout.c 2014-12-20 00:18:06 UTC
(rev 34715)
+++ libmicrohttpd/src/testspdy/test_session_timeout.c 2014-12-20 00:25:22 UTC
(rev 34716)
@@ -283,12 +283,16 @@
close(devnull);
}*/
devnull = open("/dev/null", O_WRONLY);
+ if (-1 == devnull)
+ abort ();
if (1 != devnull)
{
dup2(devnull, 1);
close(devnull);
}
devnull = open("/dev/null", O_WRONLY);
+ if (-1 == devnull)
+ abort ();
if (2 != devnull)
{
dup2(devnull, 2);
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r34716 - libmicrohttpd/src/testspdy,
gnunet <=