2012-01-26 17:32:05 +01:00
|
|
|
/*
|
2013-07-12 17:19:03 +02:00
|
|
|
* nghttp2 - HTTP/2.0 C Library
|
2012-01-26 17:32:05 +01:00
|
|
|
*
|
|
|
|
* Copyright (c) 2012 Tatsuhiro Tsujikawa
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining
|
|
|
|
* a copy of this software and associated documentation files (the
|
|
|
|
* "Software"), to deal in the Software without restriction, including
|
|
|
|
* without limitation the rights to use, copy, modify, merge, publish,
|
|
|
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
|
|
|
* permit persons to whom the Software is furnished to do so, subject to
|
|
|
|
* the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be
|
|
|
|
* included in all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
|
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
|
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
|
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
|
|
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
|
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
|
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
*/
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <netdb.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <netinet/in.h>
|
|
|
|
#include <netinet/tcp.h>
|
2012-10-14 16:39:41 +02:00
|
|
|
#include <poll.h>
|
2012-01-26 17:32:05 +01:00
|
|
|
|
|
|
|
#include <cassert>
|
|
|
|
#include <cstdio>
|
|
|
|
#include <cerrno>
|
|
|
|
#include <cstdlib>
|
|
|
|
#include <cstring>
|
|
|
|
#include <string>
|
|
|
|
#include <iostream>
|
|
|
|
#include <string>
|
|
|
|
#include <set>
|
|
|
|
#include <iomanip>
|
|
|
|
#include <fstream>
|
|
|
|
|
2013-07-22 15:12:54 +02:00
|
|
|
#include "app_helper.h"
|
2012-08-21 16:22:33 +02:00
|
|
|
#include "util.h"
|
2012-01-26 17:32:05 +01:00
|
|
|
|
2013-07-12 17:19:03 +02:00
|
|
|
namespace nghttp2 {
|
2012-01-29 16:34:10 +01:00
|
|
|
|
2012-01-30 16:46:46 +01:00
|
|
|
namespace {
|
2013-07-15 17:15:04 +02:00
|
|
|
const char* strstatus(nghttp2_error_code error_code)
|
|
|
|
{
|
|
|
|
switch(error_code) {
|
|
|
|
case NGHTTP2_NO_ERROR:
|
|
|
|
return "NO_ERROR";
|
|
|
|
case NGHTTP2_PROTOCOL_ERROR:
|
|
|
|
return "PROTOCOL_ERROR";
|
|
|
|
case NGHTTP2_INTERNAL_ERROR:
|
|
|
|
return "INTERNAL_ERROR";
|
|
|
|
case NGHTTP2_FLOW_CONTROL_ERROR:
|
|
|
|
return "FLOW_CONTROL_ERROR";
|
|
|
|
case NGHTTP2_STREAM_CLOSED:
|
|
|
|
return "STREAM_CLOSED";
|
|
|
|
case NGHTTP2_FRAME_TOO_LARGE:
|
|
|
|
return "FRAME_TOO_LARGE";
|
|
|
|
case NGHTTP2_REFUSED_STREAM:
|
|
|
|
return "REFUSED_STREAM";
|
|
|
|
case NGHTTP2_CANCEL:
|
|
|
|
return "CANCEL";
|
|
|
|
default:
|
|
|
|
return "UNKNOWN";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} // namespace
|
|
|
|
|
2013-08-09 17:37:57 +02:00
|
|
|
namespace {
|
|
|
|
const char* strsettingsid(int32_t id)
|
|
|
|
{
|
|
|
|
switch(id) {
|
|
|
|
case NGHTTP2_SETTINGS_MAX_CONCURRENT_STREAMS:
|
|
|
|
return "MAX_CONCURRENT_STREAMS";
|
|
|
|
case NGHTTP2_SETTINGS_INITIAL_WINDOW_SIZE:
|
|
|
|
return "INITIAL_WINDOW_SIZE";
|
|
|
|
case NGHTTP2_SETTINGS_FLOW_CONTROL_OPTIONS:
|
|
|
|
return "FLOW_CONTROL_OPTIONS";
|
|
|
|
default:
|
|
|
|
return "UNKNOWN";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} // namespace
|
|
|
|
|
2013-07-15 17:15:04 +02:00
|
|
|
namespace {
|
2013-08-09 17:42:11 +02:00
|
|
|
const char* strframetype(uint8_t type)
|
|
|
|
{
|
|
|
|
switch(type) {
|
|
|
|
case NGHTTP2_DATA:
|
|
|
|
return "DATA";
|
|
|
|
case NGHTTP2_HEADERS:
|
|
|
|
return "HEADERS";
|
|
|
|
case NGHTTP2_PRIORITY:
|
|
|
|
return "PRIORITY";
|
|
|
|
case NGHTTP2_RST_STREAM:
|
|
|
|
return "RST_STREAM";
|
|
|
|
case NGHTTP2_SETTINGS:
|
|
|
|
return "SETTINGS";
|
|
|
|
case NGHTTP2_PUSH_PROMISE:
|
|
|
|
return "PUSH_PROMISE";
|
|
|
|
case NGHTTP2_PING:
|
|
|
|
return "PING";
|
|
|
|
case NGHTTP2_GOAWAY:
|
|
|
|
return "GOAWAY";
|
|
|
|
case NGHTTP2_WINDOW_UPDATE:
|
|
|
|
return "WINDOW_UPDATE";
|
|
|
|
default:
|
|
|
|
return "UNKNOWN";
|
|
|
|
}
|
2012-01-27 20:30:23 +01:00
|
|
|
};
|
2012-01-30 16:46:46 +01:00
|
|
|
} // namespace
|
2012-01-27 20:30:23 +01:00
|
|
|
|
2012-02-01 16:37:48 +01:00
|
|
|
namespace {
|
|
|
|
void print_frame_attr_indent()
|
|
|
|
{
|
|
|
|
printf(" ");
|
|
|
|
}
|
|
|
|
} // namespace
|
|
|
|
|
2013-01-27 08:27:17 +01:00
|
|
|
namespace {
|
|
|
|
bool color_output = false;
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
void set_color_output(bool f)
|
|
|
|
{
|
|
|
|
color_output = f;
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
const char* ansi_esc(const char *code)
|
|
|
|
{
|
|
|
|
return color_output ? code : "";
|
|
|
|
}
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
const char* ansi_escend()
|
|
|
|
{
|
|
|
|
return color_output ? "\033[0m" : "";
|
|
|
|
}
|
|
|
|
} // namespace
|
|
|
|
|
2013-07-19 17:08:14 +02:00
|
|
|
|
|
|
|
void print_nv(nghttp2_nv *nva, size_t nvlen)
|
2012-01-29 16:34:10 +01:00
|
|
|
{
|
2013-07-19 17:08:14 +02:00
|
|
|
size_t i;
|
|
|
|
for(i = 0; i < nvlen; ++i) {
|
2012-02-01 16:37:48 +01:00
|
|
|
print_frame_attr_indent();
|
2013-07-19 17:08:14 +02:00
|
|
|
printf("%s", ansi_esc("\033[1;34m"));
|
|
|
|
fwrite(nva[i].name, nva[i].namelen, 1, stdout);
|
|
|
|
printf("%s: ", ansi_escend());
|
|
|
|
fwrite(nva[i].value, nva[i].valuelen, 1, stdout);
|
|
|
|
printf("\n");
|
2012-01-29 16:34:10 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-01-30 16:46:46 +01:00
|
|
|
void print_timer()
|
|
|
|
{
|
2012-01-31 14:04:51 +01:00
|
|
|
timeval tv;
|
|
|
|
get_timer(&tv);
|
2013-01-27 08:27:17 +01:00
|
|
|
printf("%s[%3ld.%03ld]%s",
|
|
|
|
ansi_esc("\033[33m"),
|
2013-05-03 15:14:16 +02:00
|
|
|
(long int)tv.tv_sec, tv.tv_usec/1000,
|
2013-01-27 08:27:17 +01:00
|
|
|
ansi_escend());
|
2012-01-30 16:46:46 +01:00
|
|
|
}
|
|
|
|
|
2012-02-01 16:37:48 +01:00
|
|
|
namespace {
|
2013-07-15 17:15:04 +02:00
|
|
|
void print_frame_hd(const nghttp2_frame_hd& hd)
|
2012-02-01 16:37:48 +01:00
|
|
|
{
|
2013-08-01 14:42:16 +02:00
|
|
|
printf("<length=%d, flags=0x%02x, stream_id=%d>\n",
|
2013-07-15 17:15:04 +02:00
|
|
|
hd.length, hd.flags, hd.stream_id);
|
|
|
|
}
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
void print_flags(const nghttp2_frame_hd& hd)
|
|
|
|
{
|
|
|
|
std::string s;
|
|
|
|
switch(hd.type) {
|
|
|
|
case NGHTTP2_DATA:
|
|
|
|
if(hd.flags & NGHTTP2_FLAG_END_STREAM) {
|
|
|
|
s += "END_STREAM";
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case NGHTTP2_HEADERS:
|
|
|
|
if(hd.flags & NGHTTP2_FLAG_END_STREAM) {
|
|
|
|
s += "END_STREAM";
|
|
|
|
}
|
|
|
|
if(hd.flags & NGHTTP2_FLAG_END_HEADERS) {
|
|
|
|
if(!s.empty()) {
|
|
|
|
s += " | ";
|
|
|
|
}
|
|
|
|
s += "END_HEADERS";
|
|
|
|
}
|
|
|
|
if(hd.flags & NGHTTP2_FLAG_PRIORITY) {
|
|
|
|
if(!s.empty()) {
|
|
|
|
s += " | ";
|
|
|
|
}
|
|
|
|
s += "PRIORITY";
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case NGHTTP2_PUSH_PROMISE:
|
|
|
|
if(hd.flags & NGHTTP2_FLAG_END_PUSH_PROMISE) {
|
|
|
|
s += "END_PUSH_PROMISE";
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case NGHTTP2_PING:
|
|
|
|
if(hd.flags & NGHTTP2_FLAG_PONG) {
|
|
|
|
s += "PONG";
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
printf("; %s\n", s.c_str());
|
2012-02-01 16:37:48 +01:00
|
|
|
}
|
|
|
|
} // namespace
|
|
|
|
|
2013-01-27 08:27:17 +01:00
|
|
|
enum print_type {
|
|
|
|
PRINT_SEND,
|
|
|
|
PRINT_RECV
|
|
|
|
};
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
const char* frame_name_ansi_esc(print_type ptype)
|
|
|
|
{
|
|
|
|
return ansi_esc(ptype == PRINT_SEND ? "\033[1;35m" : "\033[1;36m");
|
|
|
|
}
|
|
|
|
} // namespace
|
|
|
|
|
2012-02-07 17:50:58 +01:00
|
|
|
namespace {
|
2013-07-15 17:15:04 +02:00
|
|
|
void print_frame(print_type ptype, nghttp2_frame *frame)
|
2012-01-27 19:54:53 +01:00
|
|
|
{
|
2013-01-27 08:27:17 +01:00
|
|
|
printf("%s%s%s frame ",
|
|
|
|
frame_name_ansi_esc(ptype),
|
2013-08-09 17:42:11 +02:00
|
|
|
strframetype(frame->hd.type),
|
2013-01-27 08:27:17 +01:00
|
|
|
ansi_escend());
|
2013-07-15 17:15:04 +02:00
|
|
|
print_frame_hd(frame->hd);
|
|
|
|
if(frame->hd.flags) {
|
2012-02-01 16:37:48 +01:00
|
|
|
print_frame_attr_indent();
|
2013-07-15 17:15:04 +02:00
|
|
|
print_flags(frame->hd);
|
|
|
|
}
|
|
|
|
switch(frame->hd.type) {
|
|
|
|
case NGHTTP2_HEADERS:
|
2013-07-16 18:13:58 +02:00
|
|
|
if(frame->hd.flags & NGHTTP2_FLAG_PRIORITY) {
|
|
|
|
print_frame_attr_indent();
|
|
|
|
printf("(pri=%d)\n", frame->headers.pri);
|
|
|
|
}
|
2013-07-15 17:15:04 +02:00
|
|
|
switch(frame->headers.cat) {
|
2013-07-25 13:53:30 +02:00
|
|
|
case NGHTTP2_HCAT_REQUEST:
|
2013-07-15 17:15:04 +02:00
|
|
|
print_frame_attr_indent();
|
|
|
|
printf("; Open new stream\n");
|
|
|
|
break;
|
2013-07-25 13:53:30 +02:00
|
|
|
case NGHTTP2_HCAT_RESPONSE:
|
2013-07-15 17:15:04 +02:00
|
|
|
print_frame_attr_indent();
|
|
|
|
printf("; First response header\n");
|
|
|
|
break;
|
2013-07-25 13:53:30 +02:00
|
|
|
case NGHTTP2_HCAT_PUSH_RESPONSE:
|
|
|
|
print_frame_attr_indent();
|
|
|
|
printf("; First push response header\n");
|
|
|
|
break;
|
2013-07-15 17:15:04 +02:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2013-07-19 17:08:14 +02:00
|
|
|
print_nv(frame->headers.nva, frame->headers.nvlen);
|
2012-01-27 19:54:53 +01:00
|
|
|
break;
|
2013-07-22 17:29:52 +02:00
|
|
|
case NGHTTP2_PRIORITY:
|
|
|
|
print_frame_attr_indent();
|
|
|
|
printf("(pri=%d)\n", frame->priority.pri);
|
|
|
|
break;
|
2013-07-12 17:19:03 +02:00
|
|
|
case NGHTTP2_RST_STREAM:
|
2012-02-01 16:37:48 +01:00
|
|
|
print_frame_attr_indent();
|
2013-07-15 17:15:04 +02:00
|
|
|
printf("(error_code=%s(%u))\n",
|
|
|
|
strstatus(frame->rst_stream.error_code),
|
|
|
|
frame->rst_stream.error_code);
|
2012-01-31 17:16:35 +01:00
|
|
|
break;
|
2013-07-12 17:19:03 +02:00
|
|
|
case NGHTTP2_SETTINGS:
|
2012-02-01 16:37:48 +01:00
|
|
|
print_frame_attr_indent();
|
|
|
|
printf("(niv=%lu)\n", static_cast<unsigned long>(frame->settings.niv));
|
2012-01-31 17:16:35 +01:00
|
|
|
for(size_t i = 0; i < frame->settings.niv; ++i) {
|
2012-02-01 16:37:48 +01:00
|
|
|
print_frame_attr_indent();
|
2013-08-09 17:37:57 +02:00
|
|
|
printf("[%s(%d):%u]\n",
|
|
|
|
strsettingsid(frame->settings.iv[i].settings_id),
|
2012-01-31 17:16:35 +01:00
|
|
|
frame->settings.iv[i].settings_id,
|
2013-07-15 17:15:04 +02:00
|
|
|
frame->settings.iv[i].value);
|
2012-01-31 17:16:35 +01:00
|
|
|
}
|
|
|
|
break;
|
2013-07-27 15:37:09 +02:00
|
|
|
case NGHTTP2_PUSH_PROMISE:
|
|
|
|
print_frame_attr_indent();
|
|
|
|
printf("(promised_stream_id=%d)\n",
|
|
|
|
frame->push_promise.promised_stream_id);
|
|
|
|
break;
|
2013-07-12 17:19:03 +02:00
|
|
|
case NGHTTP2_PING:
|
2012-02-01 16:37:48 +01:00
|
|
|
print_frame_attr_indent();
|
2013-07-15 17:15:04 +02:00
|
|
|
printf("(opaque_data=%s)\n",
|
|
|
|
util::format_hex(frame->ping.opaque_data, 8).c_str());
|
2012-01-29 16:34:10 +01:00
|
|
|
break;
|
2013-07-12 17:19:03 +02:00
|
|
|
case NGHTTP2_GOAWAY:
|
2012-02-01 16:37:48 +01:00
|
|
|
print_frame_attr_indent();
|
2013-08-09 17:46:00 +02:00
|
|
|
printf("(last_stream_id=%d, error_code=%s(%u), opaque_data(%u)=[%s])\n",
|
2013-07-15 17:15:04 +02:00
|
|
|
frame->goaway.last_stream_id,
|
|
|
|
strstatus(frame->goaway.error_code),
|
|
|
|
frame->goaway.error_code,
|
2013-08-09 17:46:00 +02:00
|
|
|
static_cast<unsigned int>(frame->goaway.opaque_data_len),
|
2013-07-15 17:15:04 +02:00
|
|
|
util::format_hex(frame->goaway.opaque_data,
|
|
|
|
frame->goaway.opaque_data_len).c_str());
|
2012-01-31 17:16:35 +01:00
|
|
|
break;
|
2013-07-12 17:19:03 +02:00
|
|
|
case NGHTTP2_WINDOW_UPDATE:
|
2012-02-25 16:12:32 +01:00
|
|
|
print_frame_attr_indent();
|
2013-07-15 17:15:04 +02:00
|
|
|
printf("(window_size_increment=%d)\n",
|
|
|
|
frame->window_update.window_size_increment);
|
2012-02-25 16:12:32 +01:00
|
|
|
break;
|
2012-01-27 19:54:53 +01:00
|
|
|
default:
|
2012-01-29 16:34:10 +01:00
|
|
|
printf("\n");
|
2012-01-27 19:54:53 +01:00
|
|
|
break;
|
|
|
|
}
|
2012-01-30 16:46:46 +01:00
|
|
|
}
|
2012-02-07 17:50:58 +01:00
|
|
|
} // namespace
|
2012-01-30 16:46:46 +01:00
|
|
|
|
2013-08-29 14:03:39 +02:00
|
|
|
int on_frame_recv_callback
|
2013-07-15 17:15:04 +02:00
|
|
|
(nghttp2_session *session, nghttp2_frame *frame, void *user_data)
|
2012-01-30 16:46:46 +01:00
|
|
|
{
|
|
|
|
print_timer();
|
|
|
|
printf(" recv ");
|
2013-07-15 17:15:04 +02:00
|
|
|
print_frame(PRINT_RECV, frame);
|
2012-01-28 11:44:42 +01:00
|
|
|
fflush(stdout);
|
2013-08-29 14:03:39 +02:00
|
|
|
return 0;
|
2012-01-27 19:54:53 +01:00
|
|
|
}
|
|
|
|
|
2013-08-29 14:12:43 +02:00
|
|
|
int on_invalid_frame_recv_callback
|
2013-07-15 17:15:04 +02:00
|
|
|
(nghttp2_session *session, nghttp2_frame *frame,
|
|
|
|
nghttp2_error_code error_code, void *user_data)
|
2012-05-09 16:27:44 +02:00
|
|
|
{
|
|
|
|
print_timer();
|
2013-07-15 17:15:04 +02:00
|
|
|
printf(" [INVALID; status=%s] recv ", strstatus(error_code));
|
|
|
|
print_frame(PRINT_RECV, frame);
|
2012-05-09 16:27:44 +02:00
|
|
|
fflush(stdout);
|
2013-08-29 14:12:43 +02:00
|
|
|
return 0;
|
2012-05-09 16:27:44 +02:00
|
|
|
}
|
|
|
|
|
2012-05-09 15:41:08 +02:00
|
|
|
namespace {
|
|
|
|
void dump_header(const uint8_t *head, size_t headlen)
|
|
|
|
{
|
|
|
|
size_t i;
|
|
|
|
print_frame_attr_indent();
|
|
|
|
printf("Header dump: ");
|
|
|
|
for(i = 0; i < headlen; ++i) {
|
|
|
|
printf("%02X ", head[i]);
|
|
|
|
}
|
|
|
|
printf("\n");
|
|
|
|
}
|
|
|
|
} // namespace
|
|
|
|
|
2013-07-15 17:15:04 +02:00
|
|
|
void on_frame_recv_parse_error_callback(nghttp2_session *session,
|
2013-07-12 17:19:03 +02:00
|
|
|
nghttp2_frame_type type,
|
2012-05-09 14:55:21 +02:00
|
|
|
const uint8_t *head,
|
|
|
|
size_t headlen,
|
|
|
|
const uint8_t *payload,
|
|
|
|
size_t payloadlen,
|
|
|
|
int error_code, void *user_data)
|
|
|
|
{
|
|
|
|
print_timer();
|
2013-01-27 08:27:17 +01:00
|
|
|
printf(" [PARSE_ERROR] recv %s%s%s frame\n",
|
|
|
|
frame_name_ansi_esc(PRINT_RECV),
|
2013-08-09 17:42:11 +02:00
|
|
|
strframetype(type),
|
2013-01-27 08:27:17 +01:00
|
|
|
ansi_escend());
|
2012-05-09 16:01:46 +02:00
|
|
|
print_frame_attr_indent();
|
2013-07-12 17:19:03 +02:00
|
|
|
printf("Error: %s\n", nghttp2_strerror(error_code));
|
2012-05-09 15:41:08 +02:00
|
|
|
dump_header(head, headlen);
|
|
|
|
fflush(stdout);
|
|
|
|
}
|
|
|
|
|
2013-07-15 17:15:04 +02:00
|
|
|
void on_unknown_frame_recv_callback(nghttp2_session *session,
|
2012-05-09 15:41:08 +02:00
|
|
|
const uint8_t *head,
|
|
|
|
size_t headlen,
|
|
|
|
const uint8_t *payload,
|
|
|
|
size_t payloadlen,
|
|
|
|
void *user_data)
|
|
|
|
{
|
|
|
|
print_timer();
|
|
|
|
printf(" recv unknown frame\n");
|
|
|
|
dump_header(head, headlen);
|
2012-05-09 14:55:21 +02:00
|
|
|
fflush(stdout);
|
|
|
|
}
|
|
|
|
|
2013-08-29 14:48:34 +02:00
|
|
|
int on_frame_send_callback
|
2013-07-15 17:15:04 +02:00
|
|
|
(nghttp2_session *session, nghttp2_frame *frame, void *user_data)
|
2012-02-07 17:50:58 +01:00
|
|
|
{
|
|
|
|
print_timer();
|
|
|
|
printf(" send ");
|
2013-07-15 17:15:04 +02:00
|
|
|
print_frame(PRINT_SEND, frame);
|
2012-02-07 17:50:58 +01:00
|
|
|
fflush(stdout);
|
2013-08-29 14:48:34 +02:00
|
|
|
return 0;
|
2012-02-07 17:50:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
namespace {
|
2013-07-15 17:15:04 +02:00
|
|
|
void print_data_frame(print_type ptype, uint16_t length, uint8_t flags,
|
|
|
|
int32_t stream_id)
|
2012-02-07 17:50:58 +01:00
|
|
|
{
|
2013-08-09 17:31:59 +02:00
|
|
|
printf("%sDATA%s frame ",
|
|
|
|
frame_name_ansi_esc(ptype), ansi_escend());
|
|
|
|
nghttp2_frame_hd hd = {length, NGHTTP2_DATA, flags, stream_id};
|
|
|
|
print_frame_hd(hd);
|
2013-08-04 11:44:11 +02:00
|
|
|
if(flags) {
|
|
|
|
print_frame_attr_indent();
|
|
|
|
print_flags(hd);
|
|
|
|
}
|
2012-02-07 17:50:58 +01:00
|
|
|
}
|
|
|
|
} // namespace
|
|
|
|
|
2013-08-29 14:22:00 +02:00
|
|
|
int on_data_recv_callback
|
2013-07-15 17:15:04 +02:00
|
|
|
(nghttp2_session *session, uint16_t length, uint8_t flags, int32_t stream_id,
|
2012-01-27 19:54:53 +01:00
|
|
|
void *user_data)
|
|
|
|
{
|
2012-01-30 16:46:46 +01:00
|
|
|
print_timer();
|
2012-02-07 17:50:58 +01:00
|
|
|
printf(" recv ");
|
2013-07-15 17:15:04 +02:00
|
|
|
print_data_frame(PRINT_RECV, length, flags, stream_id);
|
2012-01-28 11:44:42 +01:00
|
|
|
fflush(stdout);
|
2013-08-29 14:22:00 +02:00
|
|
|
return 0;
|
2012-01-27 19:54:53 +01:00
|
|
|
}
|
|
|
|
|
2012-02-07 17:50:58 +01:00
|
|
|
void on_data_send_callback
|
2013-07-15 17:15:04 +02:00
|
|
|
(nghttp2_session *session, uint16_t length, uint8_t flags, int32_t stream_id,
|
2012-01-27 20:30:23 +01:00
|
|
|
void *user_data)
|
|
|
|
{
|
2012-01-30 16:46:46 +01:00
|
|
|
print_timer();
|
|
|
|
printf(" send ");
|
2013-07-15 17:15:04 +02:00
|
|
|
print_data_frame(PRINT_SEND, length, flags, stream_id);
|
2012-01-28 11:44:42 +01:00
|
|
|
fflush(stdout);
|
2012-01-27 20:30:23 +01:00
|
|
|
}
|
|
|
|
|
2012-10-14 16:39:41 +02:00
|
|
|
int64_t time_delta(const timeval& a, const timeval& b)
|
|
|
|
{
|
|
|
|
int64_t res = (a.tv_sec - b.tv_sec) * 1000;
|
|
|
|
res += (a.tv_usec - b.tv_usec) / 1000;
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2012-01-30 16:46:46 +01:00
|
|
|
namespace {
|
2012-01-31 14:04:51 +01:00
|
|
|
timeval base_tv;
|
2012-01-30 16:46:46 +01:00
|
|
|
} // namespace
|
|
|
|
|
|
|
|
void reset_timer()
|
|
|
|
{
|
2013-01-27 09:16:13 +01:00
|
|
|
get_time(&base_tv);
|
2012-01-30 16:46:46 +01:00
|
|
|
}
|
|
|
|
|
2012-01-31 14:04:51 +01:00
|
|
|
void get_timer(timeval* tv)
|
2012-01-30 16:46:46 +01:00
|
|
|
{
|
2013-01-27 09:16:13 +01:00
|
|
|
get_time(tv);
|
2012-01-31 14:04:51 +01:00
|
|
|
tv->tv_usec -= base_tv.tv_usec;
|
|
|
|
tv->tv_sec -= base_tv.tv_sec;
|
|
|
|
if(tv->tv_usec < 0) {
|
|
|
|
tv->tv_usec += 1000000;
|
|
|
|
--tv->tv_sec;
|
2012-01-30 16:46:46 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-27 09:16:13 +01:00
|
|
|
int get_time(timeval *tv)
|
|
|
|
{
|
|
|
|
int rv;
|
|
|
|
#ifdef HAVE_CLOCK_GETTIME
|
|
|
|
timespec ts;
|
|
|
|
rv = clock_gettime(CLOCK_MONOTONIC, &ts);
|
|
|
|
tv->tv_sec = ts.tv_sec;
|
|
|
|
tv->tv_usec = ts.tv_nsec/1000;
|
|
|
|
#else // !HAVE_CLOCK_GETTIME
|
2013-03-29 14:06:33 +01:00
|
|
|
rv = gettimeofday(tv, 0);
|
2013-01-27 09:16:13 +01:00
|
|
|
#endif // !HAVE_CLOCK_GETTIME
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2013-07-12 17:19:03 +02:00
|
|
|
} // namespace nghttp2
|