HELLO·Android
系统源代码
IT资讯
技术文章
我的收藏
注册
登录
-
我收藏的文章
创建代码块
我的代码块
我的账号
Pie
|
9.0.0_r8
下载
查看原文件
收藏
根目录
external
libmicrohttpd
src
examples
spdy_event_loop.c
/* This file is part of libmicrospdy Copyright Copyright (C) 2012 Andrey Uzunov This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see
. */ /** * @file event_loop.c * @brief shows how to use the daemon. THIS IS MAINLY A TEST AND DEBUG * PROGRAM * @author Andrey Uzunov */ #include "platform.h" #include
#include
#include
#include
#include
#include
#include
#include
#include "microspdy.h" #include
#include
#ifndef MINGW #include
#endif //#include "../framinglayer/structures.h" //#include "../applicationlayer/alstructures.h" static int run = 1; static int run2 = 1; static uint64_t loops; static time_t start; static void new_session_callback (void *cls, struct SPDY_Session * session) { (void)cls; char ipstr[1024]; struct sockaddr *addr; socklen_t addr_len = SPDY_get_remote_addr(session, &addr); if(!addr_len) { printf("SPDY_get_remote_addr"); abort(); } if(AF_INET == addr->sa_family) { struct sockaddr_in * addr4 = (struct sockaddr_in *) addr; if(NULL == inet_ntop(AF_INET, &(addr4->sin_addr), ipstr, sizeof(ipstr))) { printf("inet_ntop"); abort(); } printf("New connection from: %s:%i\n", ipstr, ntohs(addr4->sin_port)); } else if(AF_INET6 == addr->sa_family) { struct sockaddr_in6 * addr6 = (struct sockaddr_in6 *) addr; if(NULL == inet_ntop(AF_INET6, &(addr6->sin6_addr), ipstr, sizeof(ipstr))) { printf("inet_ntop"); abort(); } printf("New connection from: %s:%i\n", ipstr, ntohs(addr6->sin6_port)); } } static void session_closed_handler (void *cls, struct SPDY_Session * session, int by_client) { (void)cls; (void)session; //printf("session_closed_handler called\n"); if(SPDY_YES != by_client) { //killchild(child,"wrong by_client"); printf("session closed by server\n"); } else { printf("session closed by client\n"); } //session_closed_called = 1; } static void response_done_callback(void *cls, struct SPDY_Response *response, struct SPDY_Request *request, enum SPDY_RESPONSE_RESULT status, bool streamopened) { (void)streamopened; if(strcmp(cls, "/close (daemon1)") == 0) run = 0; else { if(strcmp(cls, "/close (daemon2)") == 0) run2 = 0; loops = 0; start = time(NULL); } if(SPDY_RESPONSE_RESULT_SUCCESS != status) { printf("not sent frame cause %i", status); } printf("answer for %s was sent\n", (char*)cls); //printf("raw sent headers %s\n", (char *)(response->headers)+8); SPDY_destroy_request(request); SPDY_destroy_response(response); free(cls); } /* static int print_headers (void *cls, const char *name, const char *value) { (void)cls; printf("%s: %s\n",name,value); return SPDY_YES; } */ /* void new_request_cb (void *cls, struct SPDY_Request * request, uint8_t priority, const char *method, const char *path, const char *version, const char *host, const char *scheme, struct SPDY_NameValue * headers) { (void)cls; (void)request; printf("Priority: %i\nHTTP headers, scheme: %s\n\n%s %s %s\nHost: %s\n", priority,scheme,method,path,version,host); SPDY_name_value_iterate(headers, &print_headers, NULL); } */ static int append_headers_to_data (void *cls, const char *name, const char * const *value, int num_values) { char **data = cls; void *tofree = *data; int i; if(num_values) for(i=0;i
" "
Closing now!
This is an answer to the following " "request:
%s