commit 8c24a9bd241bec111c863b047a2df0962c255d0f
parent a4030d4473d4237aa9dad30d7812cd1c9e764dba
Author: Christian Grothoff <christian@grothoff.org>
Date: Sat, 20 Dec 2014 00:30:53 +0000
-check RVals
Diffstat:
4 files changed, 101 insertions(+), 89 deletions(-)
diff --git a/src/testspdy/test_new_connection.c b/src/testspdy/test_new_connection.c
@@ -23,9 +23,9 @@
* @author Andrey Uzunov
* @author Tatsuhiro Tsujikawa
*/
-
+
//TODO child exits with ret val 1 sometimes
-
+
#include "platform.h"
#include "microspdy.h"
#include <sys/wait.h>
@@ -45,7 +45,7 @@ int
spdylay_printf(const char *format, ...)
{
(void)format;
-
+
return 0;
}
@@ -54,10 +54,10 @@ spdylay_fprintf(FILE *stream, const char *format, ...)
{
(void)stream;
(void)format;
-
+
return 0;
}
-
+
void
killchild(int pid, char *message)
{
@@ -73,7 +73,7 @@ killparent(int pid, char *message)
kill(pid, SIGKILL);
_exit(2);
}
-
+
/*****
* start of code needed to utilize spdylay
@@ -222,7 +222,7 @@ static ssize_t send_callback(spdylay_session *session,
{
(void)session;
(void)flags;
-
+
struct Connection *connection;
ssize_t rv;
connection = (struct Connection*)user_data;
@@ -254,7 +254,7 @@ static ssize_t recv_callback(spdylay_session *session,
{
(void)session;
(void)flags;
-
+
struct Connection *connection;
ssize_t rv;
connection = (struct Connection*)user_data;
@@ -288,7 +288,7 @@ static void before_ctrl_send_callback(spdylay_session *session,
void *user_data)
{
(void)user_data;
-
+
if(type == SPDYLAY_SYN_STREAM) {
struct Request *req;
int stream_id = frame->syn_stream.stream_id;
@@ -305,7 +305,7 @@ static void on_ctrl_send_callback(spdylay_session *session,
spdylay_frame *frame, void *user_data)
{
(void)user_data;
-
+
char **nv;
const char *name = NULL;
int32_t stream_id;
@@ -332,7 +332,7 @@ static void on_ctrl_recv_callback(spdylay_session *session,
spdylay_frame *frame, void *user_data)
{
(void)user_data;
-
+
struct Request *req;
char **nv;
const char *name = NULL;
@@ -402,7 +402,7 @@ static void on_data_chunk_recv_callback(spdylay_session *session, uint8_t flags,
{
(void)user_data;
(void)flags;
-
+
struct Request *req;
req = spdylay_session_get_stream_user_data(session, stream_id);
if(req) {
@@ -426,7 +426,7 @@ static void on_data_chunk_recv_callback(spdylay_session *session, uint8_t flags,
} else {
/* TODO add support gzip */
fwrite(data, 1, len, stdout);
-
+
//check if the data is correct
if(strcmp(RESPONSE_BODY, (char *)data) != 0)
killparent(parent, "\nreceived data is not the same");
@@ -464,7 +464,7 @@ static int select_next_proto_cb(SSL* ssl,
void *arg)
{
(void)ssl;
-
+
int rv;
uint16_t *spdy_proto_version;
/* spdylay_select_next_protocol() selects SPDY protocol version the
@@ -667,6 +667,8 @@ static void fetch_uri(const struct URI *uri)
/* 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));
@@ -811,32 +813,32 @@ static int parse_uri(struct URI *res, const char *uri)
/*****
* end of code needed to utilize spdylay
*/
-
+
/*****
* start of code needed to utilize microspdy
*/
-
+
void
new_session_callback (void *cls,
struct SPDY_Session * session)
{
char ipstr[1024];
-
+
struct sockaddr *addr;
- socklen_t addr_len = SPDY_get_remote_addr(session, &addr);
-
+ socklen_t addr_len = SPDY_get_remote_addr(session, &addr);
+
if(!addr_len)
{
printf("SPDY_get_remote_addr");
abort();
}
-
+
if(strcmp(CLS,cls)!=0)
{
killchild(child,"wrong cls");
}
-
+
if(AF_INET == addr->sa_family)
{
struct sockaddr_in * addr4 = (struct sockaddr_in *) addr;
@@ -845,7 +847,7 @@ new_session_callback (void *cls,
killchild(child,"inet_ntop");
}
printf("New connection from: %s:%i\n", ipstr, ntohs(addr4->sin_port));
-
+
loop = 0;
}
#if HAVE_INET6
@@ -857,7 +859,7 @@ new_session_callback (void *cls,
killchild(child,"inet_ntop");
}
printf("New connection from: %s:%i\n", ipstr, ntohs(addr6->sin6_port));
-
+
loop = 0;
}
#endif
@@ -870,7 +872,7 @@ new_session_callback (void *cls,
/*****
* end of code needed to utilize microspdy
*/
-
+
//child process
void
childproc(int parent)
@@ -879,7 +881,7 @@ childproc(int parent)
struct sigaction act;
int rv;
char *uristr;
-
+
memset(&act, 0, sizeof(struct sigaction));
act.sa_handler = SIG_IGN;
sigaction(SIGPIPE, &act, 0);
@@ -909,14 +911,14 @@ parentproc(int child)
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",
&new_session_callback,NULL,NULL,NULL,CLS,SPDY_DAEMON_OPTION_END);
-
+
if(NULL==daemon){
printf("no daemon\n");
return 1;
@@ -939,14 +941,14 @@ parentproc(int child)
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);
@@ -964,18 +966,18 @@ parentproc(int child)
while(loop && waitpid(child,&childstatus,WNOHANG) != child);
SPDY_stop_daemon(daemon);
-
+
SPDY_deinit();
-
+
if(loop)
return WEXITSTATUS(childstatus);
if(waitpid(child,&childstatus,WNOHANG) == child)
return WEXITSTATUS(childstatus);
-
+
kill(child,SIGKILL);
-
- waitpid(child,&childstatus,0);
-
+
+ waitpid(child,&childstatus,0);
+
return 0;
}
@@ -983,21 +985,21 @@ int main()
{
port = get_port(14123);
parent = getpid();
-
+
child = fork();
if (child == -1)
- {
+ {
fprintf(stderr, "can't fork, error %d\n", errno);
exit(EXIT_FAILURE);
}
-
+
if (child == 0)
{
childproc(parent);
_exit(0);
}
else
- {
+ {
int ret = parentproc(child);
exit(ret);
}
diff --git a/src/testspdy/test_notls.c b/src/testspdy/test_notls.c
@@ -23,7 +23,7 @@
* @author Andrey Uzunov
* @author Tatsuhiro Tsujikawa
*/
-
+
#include "platform.h"
#include "microspdy.h"
#include <sys/wait.h>
@@ -39,7 +39,7 @@ char *rcvbuf;
int rcvbuf_c = 0;
int session_closed_called = 0;
-
+
void
killchild(int pid, char *message)
{
@@ -55,7 +55,7 @@ killparent(int pid, char *message)
kill(pid, SIGKILL);
_exit(1);
}
-
+
/*****
* start of code needed to utilize spdylay
@@ -201,20 +201,20 @@ static ssize_t send_callback(spdylay_session *session,
{
(void)session;
(void)flags;
-
+
struct Connection *connection;
ssize_t rv;
connection = (struct Connection*)user_data;
connection->want_io = IO_NONE;
- rv = write(connection->fd,
+ rv = write(connection->fd,
data,
length);
-
+
if (rv < 0)
{
switch(errno)
- {
+ {
case EAGAIN:
#if EAGAIN != EWOULDBLOCK
case EWOULDBLOCK:
@@ -222,7 +222,7 @@ static ssize_t send_callback(spdylay_session *session,
connection->want_io = WANT_WRITE;
rv = SPDYLAY_ERR_WOULDBLOCK;
break;
-
+
default:
rv = SPDYLAY_ERR_CALLBACK_FAILURE;
}
@@ -242,20 +242,20 @@ static ssize_t recv_callback(spdylay_session *session,
{
(void)session;
(void)flags;
-
+
struct Connection *connection;
ssize_t rv;
connection = (struct Connection*)user_data;
connection->want_io = IO_NONE;
- rv = read(connection->fd,
+ rv = read(connection->fd,
buf,
length);
-
+
if (rv < 0)
{
switch(errno)
- {
+ {
case EAGAIN:
#if EAGAIN != EWOULDBLOCK
case EWOULDBLOCK:
@@ -263,7 +263,7 @@ static ssize_t recv_callback(spdylay_session *session,
connection->want_io = WANT_READ;
rv = SPDYLAY_ERR_WOULDBLOCK;
break;
-
+
default:
rv = SPDYLAY_ERR_CALLBACK_FAILURE;
}
@@ -285,7 +285,7 @@ static void before_ctrl_send_callback(spdylay_session *session,
void *user_data)
{
(void)user_data;
-
+
if(type == SPDYLAY_SYN_STREAM) {
struct Request *req;
int stream_id = frame->syn_stream.stream_id;
@@ -302,7 +302,7 @@ static void on_ctrl_send_callback(spdylay_session *session,
spdylay_frame *frame, void *user_data)
{
(void)user_data;
-
+
char **nv;
const char *name = NULL;
int32_t stream_id;
@@ -329,7 +329,7 @@ static void on_ctrl_recv_callback(spdylay_session *session,
spdylay_frame *frame, void *user_data)
{
(void)user_data;
-
+
struct Request *req;
char **nv;
const char *name = NULL;
@@ -375,7 +375,7 @@ static void on_stream_close_callback(spdylay_session *session,
{
(void)status_code;
(void)user_data;
-
+
struct Request *req;
req = spdylay_session_get_stream_user_data(session, stream_id);
if(req) {
@@ -400,7 +400,7 @@ static void on_data_chunk_recv_callback(spdylay_session *session, uint8_t flags,
{
(void)flags;
(void)user_data;
-
+
struct Request *req;
req = spdylay_session_get_stream_user_data(session, stream_id);
if(req) {
@@ -424,13 +424,13 @@ static void on_data_chunk_recv_callback(spdylay_session *session, uint8_t flags,
} 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;
}
@@ -617,6 +617,8 @@ static void fetch_uri(const struct URI *uri)
/* Establish connection and setup SSL */
fd = connect_to(req.host, req.port);
+ if (-1 == fd)
+ abort ();
connection.fd = fd;
connection.want_io = IO_NONE;
@@ -746,7 +748,7 @@ static int parse_uri(struct URI *res, const char *uri)
/*****
* end of code needed to utilize spdylay
*/
-
+
/*****
* start of code needed to utilize microspdy
@@ -774,21 +776,21 @@ standard_request_handler(void *cls,
(void)method;
(void)version;
(void)more;
-
+
struct SPDY_Response *response=NULL;
-
+
if(strcmp(CLS,cls)!=0)
{
killchild(child,"wrong cls");
}
-
+
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");
@@ -802,12 +804,12 @@ session_closed_handler (void *cls,
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");
@@ -817,12 +819,12 @@ session_closed_handler (void *cls,
{
printf("session closed by client\n");
}
-
+
if(NULL == session)
{
killchild(child,"session is NULL");
}
-
+
session_closed_called = 1;
}
@@ -830,7 +832,7 @@ session_closed_handler (void *cls,
/*****
* end of code needed to utilize microspdy
*/
-
+
//child process
void
childproc(int port)
@@ -839,7 +841,7 @@ childproc(int port)
struct sigaction act;
int rv;
char *uristr;
-
+
memset(&act, 0, sizeof(struct sigaction));
act.sa_handler = SIG_IGN;
sigaction(SIGPIPE, &act, 0);
@@ -854,7 +856,7 @@ childproc(int port)
killparent(parent,"parse_uri failed");
}
fetch_uri(&uri);
-
+
if(strcmp(rcvbuf, RESPONSE_BODY))
killparent(parent,"received data is different");
}
@@ -872,9 +874,9 @@ parentproc( int port)
fd_set except_fd_set;
int maxfd = -1;
struct SPDY_Daemon *daemon;
-
+
SPDY_init();
-
+
daemon = SPDY_start_daemon(port,
NULL,
NULL,
@@ -882,7 +884,7 @@ parentproc( int port)
SPDY_DAEMON_OPTION_IO_SUBSYSTEM, SPDY_IO_SUBSYSTEM_RAW,
SPDY_DAEMON_OPTION_FLAGS, SPDY_DAEMON_FLAG_NO_DELAY,
SPDY_DAEMON_OPTION_END);
-
+
if(NULL==daemon){
printf("no daemon\n");
return 1;
@@ -905,14 +907,14 @@ parentproc( int port)
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);
@@ -934,9 +936,9 @@ parentproc( int port)
SPDY_run(daemon);
SPDY_stop_daemon(daemon);
-
+
SPDY_deinit();
-
+
return WEXITSTATUS(childstatus);
}
@@ -944,21 +946,21 @@ int main()
{
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);
diff --git a/src/testspdy/test_proxies.c b/src/testspdy/test_proxies.c
@@ -108,6 +108,8 @@ int main()
close(1);
devnull = open("/dev/null", O_WRONLY);
+ if (-1 == devnull)
+ abort();
if (1 != devnull)
{
dup2(devnull, 1);
@@ -131,6 +133,8 @@ int main()
close(1);
devnull = open("/dev/null", O_WRONLY);
+ if (-1 == devnull)
+ abort();
if (1 != devnull)
{
dup2(devnull, 1);
@@ -155,6 +159,8 @@ int main()
close(1);
devnull = open("/dev/null", O_WRONLY);
+ if (-1 == devnull)
+ abort();
if (1 != devnull)
{
dup2(devnull, 1);
diff --git a/src/testspdy/test_session_timeout.c b/src/testspdy/test_session_timeout.c
@@ -270,9 +270,11 @@ static int
childproc()
{
pid_t devnull;
- pid_t out;
+ int out;
out=dup(1);
+ if (-1 == out)
+ abort();
//close(0);
close(1);
close(2);