aboutsummaryrefslogtreecommitdiff
path: root/src/testspdy/test_notls.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/testspdy/test_notls.c')
-rw-r--r--src/testspdy/test_notls.c94
1 files changed, 48 insertions, 46 deletions
diff --git a/src/testspdy/test_notls.c b/src/testspdy/test_notls.c
index 69a6c8db..dc427d3e 100644
--- a/src/testspdy/test_notls.c
+++ b/src/testspdy/test_notls.c
@@ -23,7 +23,7 @@
23 * @author Andrey Uzunov 23 * @author Andrey Uzunov
24 * @author Tatsuhiro Tsujikawa 24 * @author Tatsuhiro Tsujikawa
25 */ 25 */
26 26
27#include "platform.h" 27#include "platform.h"
28#include "microspdy.h" 28#include "microspdy.h"
29#include <sys/wait.h> 29#include <sys/wait.h>
@@ -39,7 +39,7 @@ char *rcvbuf;
39int rcvbuf_c = 0; 39int rcvbuf_c = 0;
40 40
41int session_closed_called = 0; 41int session_closed_called = 0;
42 42
43void 43void
44killchild(int pid, char *message) 44killchild(int pid, char *message)
45{ 45{
@@ -55,7 +55,7 @@ killparent(int pid, char *message)
55 kill(pid, SIGKILL); 55 kill(pid, SIGKILL);
56 _exit(1); 56 _exit(1);
57} 57}
58 58
59 59
60/***** 60/*****
61 * start of code needed to utilize spdylay 61 * start of code needed to utilize spdylay
@@ -201,20 +201,20 @@ static ssize_t send_callback(spdylay_session *session,
201{ 201{
202 (void)session; 202 (void)session;
203 (void)flags; 203 (void)flags;
204 204
205 struct Connection *connection; 205 struct Connection *connection;
206 ssize_t rv; 206 ssize_t rv;
207 connection = (struct Connection*)user_data; 207 connection = (struct Connection*)user_data;
208 connection->want_io = IO_NONE; 208 connection->want_io = IO_NONE;
209 209
210 rv = write(connection->fd, 210 rv = write(connection->fd,
211 data, 211 data,
212 length); 212 length);
213 213
214 if (rv < 0) 214 if (rv < 0)
215 { 215 {
216 switch(errno) 216 switch(errno)
217 { 217 {
218 case EAGAIN: 218 case EAGAIN:
219 #if EAGAIN != EWOULDBLOCK 219 #if EAGAIN != EWOULDBLOCK
220 case EWOULDBLOCK: 220 case EWOULDBLOCK:
@@ -222,7 +222,7 @@ static ssize_t send_callback(spdylay_session *session,
222 connection->want_io = WANT_WRITE; 222 connection->want_io = WANT_WRITE;
223 rv = SPDYLAY_ERR_WOULDBLOCK; 223 rv = SPDYLAY_ERR_WOULDBLOCK;
224 break; 224 break;
225 225
226 default: 226 default:
227 rv = SPDYLAY_ERR_CALLBACK_FAILURE; 227 rv = SPDYLAY_ERR_CALLBACK_FAILURE;
228 } 228 }
@@ -242,20 +242,20 @@ static ssize_t recv_callback(spdylay_session *session,
242{ 242{
243 (void)session; 243 (void)session;
244 (void)flags; 244 (void)flags;
245 245
246 struct Connection *connection; 246 struct Connection *connection;
247 ssize_t rv; 247 ssize_t rv;
248 connection = (struct Connection*)user_data; 248 connection = (struct Connection*)user_data;
249 connection->want_io = IO_NONE; 249 connection->want_io = IO_NONE;
250 250
251 rv = read(connection->fd, 251 rv = read(connection->fd,
252 buf, 252 buf,
253 length); 253 length);
254 254
255 if (rv < 0) 255 if (rv < 0)
256 { 256 {
257 switch(errno) 257 switch(errno)
258 { 258 {
259 case EAGAIN: 259 case EAGAIN:
260 #if EAGAIN != EWOULDBLOCK 260 #if EAGAIN != EWOULDBLOCK
261 case EWOULDBLOCK: 261 case EWOULDBLOCK:
@@ -263,7 +263,7 @@ static ssize_t recv_callback(spdylay_session *session,
263 connection->want_io = WANT_READ; 263 connection->want_io = WANT_READ;
264 rv = SPDYLAY_ERR_WOULDBLOCK; 264 rv = SPDYLAY_ERR_WOULDBLOCK;
265 break; 265 break;
266 266
267 default: 267 default:
268 rv = SPDYLAY_ERR_CALLBACK_FAILURE; 268 rv = SPDYLAY_ERR_CALLBACK_FAILURE;
269 } 269 }
@@ -285,7 +285,7 @@ static void before_ctrl_send_callback(spdylay_session *session,
285 void *user_data) 285 void *user_data)
286{ 286{
287 (void)user_data; 287 (void)user_data;
288 288
289 if(type == SPDYLAY_SYN_STREAM) { 289 if(type == SPDYLAY_SYN_STREAM) {
290 struct Request *req; 290 struct Request *req;
291 int stream_id = frame->syn_stream.stream_id; 291 int stream_id = frame->syn_stream.stream_id;
@@ -302,7 +302,7 @@ static void on_ctrl_send_callback(spdylay_session *session,
302 spdylay_frame *frame, void *user_data) 302 spdylay_frame *frame, void *user_data)
303{ 303{
304 (void)user_data; 304 (void)user_data;
305 305
306 char **nv; 306 char **nv;
307 const char *name = NULL; 307 const char *name = NULL;
308 int32_t stream_id; 308 int32_t stream_id;
@@ -329,7 +329,7 @@ static void on_ctrl_recv_callback(spdylay_session *session,
329 spdylay_frame *frame, void *user_data) 329 spdylay_frame *frame, void *user_data)
330{ 330{
331 (void)user_data; 331 (void)user_data;
332 332
333 struct Request *req; 333 struct Request *req;
334 char **nv; 334 char **nv;
335 const char *name = NULL; 335 const char *name = NULL;
@@ -375,7 +375,7 @@ static void on_stream_close_callback(spdylay_session *session,
375{ 375{
376 (void)status_code; 376 (void)status_code;
377 (void)user_data; 377 (void)user_data;
378 378
379 struct Request *req; 379 struct Request *req;
380 req = spdylay_session_get_stream_user_data(session, stream_id); 380 req = spdylay_session_get_stream_user_data(session, stream_id);
381 if(req) { 381 if(req) {
@@ -400,7 +400,7 @@ static void on_data_chunk_recv_callback(spdylay_session *session, uint8_t flags,
400{ 400{
401 (void)flags; 401 (void)flags;
402 (void)user_data; 402 (void)user_data;
403 403
404 struct Request *req; 404 struct Request *req;
405 req = spdylay_session_get_stream_user_data(session, stream_id); 405 req = spdylay_session_get_stream_user_data(session, stream_id);
406 if(req) { 406 if(req) {
@@ -424,13 +424,13 @@ static void on_data_chunk_recv_callback(spdylay_session *session, uint8_t flags,
424 } else { 424 } else {
425 /* TODO add support gzip */ 425 /* TODO add support gzip */
426 fwrite(data, 1, len, stdout); 426 fwrite(data, 1, len, stdout);
427 427
428 //check if the data is correct 428 //check if the data is correct
429 //if(strcmp(RESPONSE_BODY, data) != 0) 429 //if(strcmp(RESPONSE_BODY, data) != 0)
430 //killparent(parent, "\nreceived data is not the same"); 430 //killparent(parent, "\nreceived data is not the same");
431 if(len + rcvbuf_c > strlen(RESPONSE_BODY)) 431 if(len + rcvbuf_c > strlen(RESPONSE_BODY))
432 killparent(parent, "\nreceived data is not the same"); 432 killparent(parent, "\nreceived data is not the same");
433 433
434 strcpy(rcvbuf + rcvbuf_c,(char*)data); 434 strcpy(rcvbuf + rcvbuf_c,(char*)data);
435 rcvbuf_c+=len; 435 rcvbuf_c+=len;
436 } 436 }
@@ -617,6 +617,8 @@ static void fetch_uri(const struct URI *uri)
617 617
618 /* Establish connection and setup SSL */ 618 /* Establish connection and setup SSL */
619 fd = connect_to(req.host, req.port); 619 fd = connect_to(req.host, req.port);
620 if (-1 == fd)
621 abort ();
620 622
621 connection.fd = fd; 623 connection.fd = fd;
622 connection.want_io = IO_NONE; 624 connection.want_io = IO_NONE;
@@ -746,7 +748,7 @@ static int parse_uri(struct URI *res, const char *uri)
746/***** 748/*****
747 * end of code needed to utilize spdylay 749 * end of code needed to utilize spdylay
748 */ 750 */
749 751
750 752
751/***** 753/*****
752 * start of code needed to utilize microspdy 754 * start of code needed to utilize microspdy
@@ -774,21 +776,21 @@ standard_request_handler(void *cls,
774 (void)method; 776 (void)method;
775 (void)version; 777 (void)version;
776 (void)more; 778 (void)more;
777 779
778 struct SPDY_Response *response=NULL; 780 struct SPDY_Response *response=NULL;
779 781
780 if(strcmp(CLS,cls)!=0) 782 if(strcmp(CLS,cls)!=0)
781 { 783 {
782 killchild(child,"wrong cls"); 784 killchild(child,"wrong cls");
783 } 785 }
784 786
785 response = SPDY_build_response(200,NULL,SPDY_HTTP_VERSION_1_1,NULL,RESPONSE_BODY,strlen(RESPONSE_BODY)); 787 response = SPDY_build_response(200,NULL,SPDY_HTTP_VERSION_1_1,NULL,RESPONSE_BODY,strlen(RESPONSE_BODY));
786 788
787 if(NULL==response){ 789 if(NULL==response){
788 fprintf(stdout,"no response obj\n"); 790 fprintf(stdout,"no response obj\n");
789 exit(3); 791 exit(3);
790 } 792 }
791 793
792 if(SPDY_queue_response(request,response,true,false,NULL,(void*)strdup(path))!=SPDY_YES) 794 if(SPDY_queue_response(request,response,true,false,NULL,(void*)strdup(path))!=SPDY_YES)
793 { 795 {
794 fprintf(stdout,"queue\n"); 796 fprintf(stdout,"queue\n");
@@ -802,12 +804,12 @@ session_closed_handler (void *cls,
802 int by_client) 804 int by_client)
803{ 805{
804 printf("session_closed_handler called\n"); 806 printf("session_closed_handler called\n");
805 807
806 if(strcmp(CLS,cls)!=0) 808 if(strcmp(CLS,cls)!=0)
807 { 809 {
808 killchild(child,"wrong cls"); 810 killchild(child,"wrong cls");
809 } 811 }
810 812
811 if(SPDY_YES != by_client) 813 if(SPDY_YES != by_client)
812 { 814 {
813 //killchild(child,"wrong by_client"); 815 //killchild(child,"wrong by_client");
@@ -817,12 +819,12 @@ session_closed_handler (void *cls,
817 { 819 {
818 printf("session closed by client\n"); 820 printf("session closed by client\n");
819 } 821 }
820 822
821 if(NULL == session) 823 if(NULL == session)
822 { 824 {
823 killchild(child,"session is NULL"); 825 killchild(child,"session is NULL");
824 } 826 }
825 827
826 session_closed_called = 1; 828 session_closed_called = 1;
827} 829}
828 830
@@ -830,7 +832,7 @@ session_closed_handler (void *cls,
830/***** 832/*****
831 * end of code needed to utilize microspdy 833 * end of code needed to utilize microspdy
832 */ 834 */
833 835
834//child process 836//child process
835void 837void
836childproc(int port) 838childproc(int port)
@@ -839,7 +841,7 @@ childproc(int port)
839 struct sigaction act; 841 struct sigaction act;
840 int rv; 842 int rv;
841 char *uristr; 843 char *uristr;
842 844
843 memset(&act, 0, sizeof(struct sigaction)); 845 memset(&act, 0, sizeof(struct sigaction));
844 act.sa_handler = SIG_IGN; 846 act.sa_handler = SIG_IGN;
845 sigaction(SIGPIPE, &act, 0); 847 sigaction(SIGPIPE, &act, 0);
@@ -854,7 +856,7 @@ childproc(int port)
854 killparent(parent,"parse_uri failed"); 856 killparent(parent,"parse_uri failed");
855 } 857 }
856 fetch_uri(&uri); 858 fetch_uri(&uri);
857 859
858 if(strcmp(rcvbuf, RESPONSE_BODY)) 860 if(strcmp(rcvbuf, RESPONSE_BODY))
859 killparent(parent,"received data is different"); 861 killparent(parent,"received data is different");
860} 862}
@@ -872,9 +874,9 @@ parentproc( int port)
872 fd_set except_fd_set; 874 fd_set except_fd_set;
873 int maxfd = -1; 875 int maxfd = -1;
874 struct SPDY_Daemon *daemon; 876 struct SPDY_Daemon *daemon;
875 877
876 SPDY_init(); 878 SPDY_init();
877 879
878 daemon = SPDY_start_daemon(port, 880 daemon = SPDY_start_daemon(port,
879 NULL, 881 NULL,
880 NULL, 882 NULL,
@@ -882,7 +884,7 @@ parentproc( int port)
882 SPDY_DAEMON_OPTION_IO_SUBSYSTEM, SPDY_IO_SUBSYSTEM_RAW, 884 SPDY_DAEMON_OPTION_IO_SUBSYSTEM, SPDY_IO_SUBSYSTEM_RAW,
883 SPDY_DAEMON_OPTION_FLAGS, SPDY_DAEMON_FLAG_NO_DELAY, 885 SPDY_DAEMON_OPTION_FLAGS, SPDY_DAEMON_FLAG_NO_DELAY,
884 SPDY_DAEMON_OPTION_END); 886 SPDY_DAEMON_OPTION_END);
885 887
886 if(NULL==daemon){ 888 if(NULL==daemon){
887 printf("no daemon\n"); 889 printf("no daemon\n");
888 return 1; 890 return 1;
@@ -905,14 +907,14 @@ parentproc( int port)
905 timeout.tv_sec = timeoutlong / 1000; 907 timeout.tv_sec = timeoutlong / 1000;
906 timeout.tv_usec = (timeoutlong % 1000) * 1000; 908 timeout.tv_usec = (timeoutlong % 1000) * 1000;
907 } 909 }
908 910
909 maxfd = SPDY_get_fdset (daemon, 911 maxfd = SPDY_get_fdset (daemon,
910 &read_fd_set, 912 &read_fd_set,
911 &write_fd_set, 913 &write_fd_set,
912 &except_fd_set); 914 &except_fd_set);
913 915
914 ret = select(maxfd+1, &read_fd_set, &write_fd_set, &except_fd_set, &timeout); 916 ret = select(maxfd+1, &read_fd_set, &write_fd_set, &except_fd_set, &timeout);
915 917
916 switch(ret) { 918 switch(ret) {
917 case -1: 919 case -1:
918 printf("select error: %i\n", errno); 920 printf("select error: %i\n", errno);
@@ -934,9 +936,9 @@ parentproc( int port)
934 SPDY_run(daemon); 936 SPDY_run(daemon);
935 937
936 SPDY_stop_daemon(daemon); 938 SPDY_stop_daemon(daemon);
937 939
938 SPDY_deinit(); 940 SPDY_deinit();
939 941
940 return WEXITSTATUS(childstatus); 942 return WEXITSTATUS(childstatus);
941} 943}
942 944
@@ -944,21 +946,21 @@ int main()
944{ 946{
945 int port = get_port(12123); 947 int port = get_port(12123);
946 parent = getpid(); 948 parent = getpid();
947 949
948 child = fork(); 950 child = fork();
949 if (child == -1) 951 if (child == -1)
950 { 952 {
951 fprintf(stderr, "can't fork, error %d\n", errno); 953 fprintf(stderr, "can't fork, error %d\n", errno);
952 exit(EXIT_FAILURE); 954 exit(EXIT_FAILURE);
953 } 955 }
954 956
955 if (child == 0) 957 if (child == 0)
956 { 958 {
957 childproc(port); 959 childproc(port);
958 _exit(0); 960 _exit(0);
959 } 961 }
960 else 962 else
961 { 963 {
962 int ret = parentproc(port); 964 int ret = parentproc(port);
963 if(1 == session_closed_called && 0 == ret) 965 if(1 == session_closed_called && 0 == ret)
964 exit(0); 966 exit(0);