Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
N
nghttp2
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Libraries
nghttp2
Commits
446f8f13
Commit
446f8f13
authored
Sep 21, 2014
by
Tatsuhiro Tsujikawa
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
src: Move libevent related helper functions to libevent_util
parent
96bb9c20
Changes
17
Show whitespace changes
Inline
Side-by-side
Showing
17 changed files
with
198 additions
and
109 deletions
+198
-109
src/HttpServer.cc
src/HttpServer.cc
+1
-0
src/Makefile.am
src/Makefile.am
+7
-3
src/h2load_http2_session.cc
src/h2load_http2_session.cc
+1
-0
src/h2load_spdy_session.h
src/h2load_spdy_session.h
+1
-0
src/libevent_util.cc
src/libevent_util.cc
+117
-0
src/libevent_util.h
src/libevent_util.h
+62
-0
src/nghttp.cc
src/nghttp.cc
+1
-0
src/shrpx_client_handler.cc
src/shrpx_client_handler.cc
+1
-0
src/shrpx_http2_session.cc
src/shrpx_http2_session.cc
+1
-0
src/shrpx_http2_upstream.cc
src/shrpx_http2_upstream.cc
+1
-0
src/shrpx_http_downstream_connection.cc
src/shrpx_http_downstream_connection.cc
+1
-0
src/shrpx_io_control.cc
src/shrpx_io_control.cc
+1
-0
src/shrpx_listen_handler.cc
src/shrpx_listen_handler.cc
+1
-0
src/shrpx_spdy_upstream.h
src/shrpx_spdy_upstream.h
+1
-0
src/shrpx_worker.cc
src/shrpx_worker.cc
+1
-0
src/util.cc
src/util.cc
+0
-82
src/util.h
src/util.h
+0
-24
No files found.
src/HttpServer.cc
View file @
446f8f13
...
...
@@ -58,6 +58,7 @@ extern "C" {
#include "app_helper.h"
#include "http2.h"
#include "util.h"
#include "libevent_util.h"
#include "ssl.h"
#ifndef O_BINARY
...
...
src/Makefile.am
View file @
446f8f13
...
...
@@ -56,8 +56,10 @@ if ENABLE_APP
bin_PROGRAMS
+=
nghttp nghttpd nghttpx
HELPER_OBJECTS
=
util.cc http2.cc timegm.c app_helper.cc nghttp2_gzip.c
HELPER_HFILES
=
util.h http2.h timegm.h app_helper.h nghttp2_config.h
\
HELPER_OBJECTS
=
util.cc libevent_util.cc
\
http2.cc timegm.c app_helper.cc nghttp2_gzip.c
HELPER_HFILES
=
util.h libevent_util.h
\
http2.h timegm.h app_helper.h nghttp2_config.h
\
nghttp2_gzip.h
HTML_PARSER_OBJECTS
=
...
...
@@ -78,7 +80,8 @@ if ENABLE_H2LOAD
bin_PROGRAMS
+=
h2load
h2load_SOURCES
=
util.cc util.h http2.cc http2.h h2load.cc h2load.h
\
h2load_SOURCES
=
util.cc util.h libevent_util.cc libevent_util.h
\
http2.cc http2.h h2load.cc h2load.h
\
timegm.c timegm.h
\
ssl.cc ssl.h
\
h2load_session.h
\
...
...
@@ -92,6 +95,7 @@ endif # ENABLE_H2LOAD
NGHTTPX_SRCS
=
\
util.cc util.h http2.cc http2.h timegm.c timegm.h base64.h
\
libevent_util.cc libevent_util.h
\
app_helper.cc app_helper.h
\
ssl.cc ssl.h
\
shrpx_config.cc shrpx_config.h
\
...
...
src/h2load_http2_session.cc
View file @
446f8f13
...
...
@@ -28,6 +28,7 @@
#include "h2load.h"
#include "util.h"
#include "libevent_util.h"
using
namespace
nghttp2
;
...
...
src/h2load_spdy_session.h
View file @
446f8f13
...
...
@@ -30,6 +30,7 @@
#include <spdylay/spdylay.h>
#include "util.h"
#include "libevent_util.h"
namespace
h2load
{
...
...
src/libevent_util.cc
0 → 100644
View file @
446f8f13
/*
* nghttp2 - HTTP/2 C Library
*
* Copyright (c) 2014 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 "libevent_util.h"
#include <cstring>
namespace
nghttp2
{
namespace
util
{
EvbufferBuffer
::
EvbufferBuffer
()
:
evbuffer_
(
nullptr
),
buf_
(
nullptr
),
bufmax_
(
0
),
buflen_
(
0
)
{}
EvbufferBuffer
::
EvbufferBuffer
(
evbuffer
*
evbuffer
,
uint8_t
*
buf
,
size_t
bufmax
)
:
evbuffer_
(
evbuffer
),
buf_
(
buf
),
bufmax_
(
bufmax
),
buflen_
(
0
)
{}
void
EvbufferBuffer
::
reset
(
evbuffer
*
evbuffer
,
uint8_t
*
buf
,
size_t
bufmax
)
{
evbuffer_
=
evbuffer
;
buf_
=
buf
;
bufmax_
=
bufmax
;
buflen_
=
0
;
}
int
EvbufferBuffer
::
flush
()
{
int
rv
;
if
(
buflen_
>
0
)
{
rv
=
evbuffer_add
(
evbuffer_
,
buf_
,
buflen_
);
if
(
rv
==
-
1
)
{
return
-
1
;
}
buflen_
=
0
;
}
return
0
;
}
int
EvbufferBuffer
::
add
(
const
uint8_t
*
data
,
size_t
datalen
)
{
int
rv
;
if
(
buflen_
+
datalen
>
bufmax_
)
{
if
(
buflen_
>
0
)
{
rv
=
evbuffer_add
(
evbuffer_
,
buf_
,
buflen_
);
if
(
rv
==
-
1
)
{
return
-
1
;
}
buflen_
=
0
;
}
if
(
datalen
>
bufmax_
)
{
rv
=
evbuffer_add
(
evbuffer_
,
data
,
datalen
);
if
(
rv
==
-
1
)
{
return
-
1
;
}
return
0
;
}
}
memcpy
(
buf_
+
buflen_
,
data
,
datalen
);
buflen_
+=
datalen
;
return
0
;
}
size_t
EvbufferBuffer
::
get_buflen
()
const
{
return
buflen_
;
}
void
bev_enable_unless
(
bufferevent
*
bev
,
int
events
)
{
if
((
bufferevent_get_enabled
(
bev
)
&
events
)
==
events
)
{
return
;
}
bufferevent_enable
(
bev
,
events
);
}
void
bev_disable_unless
(
bufferevent
*
bev
,
int
events
)
{
if
((
bufferevent_get_enabled
(
bev
)
&
events
)
==
0
)
{
return
;
}
bufferevent_disable
(
bev
,
events
);
}
}
// namespace util
}
// namespace nghttp2
src/libevent_util.h
0 → 100644
View file @
446f8f13
/*
* nghttp2 - HTTP/2 C Library
*
* Copyright (c) 2014 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.
*/
#ifndef LIBEVENT_UTIL_H
#define LIBEVENT_UTIL_H
#include "nghttp2_config.h"
#include <event2/buffer.h>
#include <event2/bufferevent.h>
namespace
nghttp2
{
namespace
util
{
class
EvbufferBuffer
{
public:
EvbufferBuffer
();
EvbufferBuffer
(
evbuffer
*
evbuffer
,
uint8_t
*
buf
,
size_t
bufmax
);
void
reset
(
evbuffer
*
evbuffer
,
uint8_t
*
buf
,
size_t
bufmax
);
int
flush
();
int
add
(
const
uint8_t
*
data
,
size_t
datalen
);
size_t
get_buflen
()
const
;
private:
evbuffer
*
evbuffer_
;
uint8_t
*
buf_
;
size_t
bufmax_
;
size_t
buflen_
;
};
// These functions are provided to reduce epoll_ctl syscall. Avoid
// calling bufferevent_enable/disable() unless it is required by
// sniffing current enabled events.
void
bev_enable_unless
(
bufferevent
*
bev
,
int
events
);
void
bev_disable_unless
(
bufferevent
*
bev
,
int
events
);
}
// namespace util
}
// namespace nghttp2
#endif // LIBEVENT_UTIL_H
src/nghttp.cc
View file @
446f8f13
...
...
@@ -67,6 +67,7 @@
#include "app_helper.h"
#include "HtmlParser.h"
#include "util.h"
#include "libevent_util.h"
#include "base64.h"
#include "http2.h"
#include "nghttp2_gzip.h"
...
...
src/shrpx_client_handler.cc
View file @
446f8f13
...
...
@@ -40,6 +40,7 @@
#include "shrpx_spdy_upstream.h"
#endif // HAVE_SPDYLAY
#include "util.h"
#include "libevent_util.h"
using
namespace
nghttp2
;
...
...
src/shrpx_http2_session.cc
View file @
446f8f13
...
...
@@ -44,6 +44,7 @@
#include "shrpx_worker_config.h"
#include "http2.h"
#include "util.h"
#include "libevent_util.h"
#include "base64.h"
using
namespace
nghttp2
;
...
...
src/shrpx_http2_upstream.cc
View file @
446f8f13
...
...
@@ -38,6 +38,7 @@
#include "shrpx_worker_config.h"
#include "http2.h"
#include "util.h"
#include "libevent_util.h"
#include "base64.h"
#include "app_helper.h"
...
...
src/shrpx_http_downstream_connection.cc
View file @
446f8f13
...
...
@@ -34,6 +34,7 @@
#include "shrpx_connect_blocker.h"
#include "http2.h"
#include "util.h"
#include "libevent_util.h"
using
namespace
nghttp2
;
...
...
src/shrpx_io_control.cc
View file @
446f8f13
...
...
@@ -27,6 +27,7 @@
#include <algorithm>
#include "util.h"
#include "libevent_util.h"
using
namespace
nghttp2
;
...
...
src/shrpx_listen_handler.cc
View file @
446f8f13
...
...
@@ -40,6 +40,7 @@
#include "shrpx_http2_session.h"
#include "shrpx_connect_blocker.h"
#include "util.h"
#include "libevent_util.h"
using
namespace
nghttp2
;
...
...
src/shrpx_spdy_upstream.h
View file @
446f8f13
...
...
@@ -34,6 +34,7 @@
#include "shrpx_upstream.h"
#include "shrpx_downstream_queue.h"
#include "util.h"
#include "libevent_util.h"
namespace
shrpx
{
...
...
src/shrpx_worker.cc
View file @
446f8f13
...
...
@@ -39,6 +39,7 @@
#include "shrpx_worker_config.h"
#include "shrpx_connect_blocker.h"
#include "util.h"
#include "libevent_util.h"
using
namespace
nghttp2
;
...
...
src/util.cc
View file @
446f8f13
...
...
@@ -509,70 +509,6 @@ void write_uri_field(std::ostream& o,
}
}
EvbufferBuffer
::
EvbufferBuffer
()
:
evbuffer_
(
nullptr
),
buf_
(
nullptr
),
bufmax_
(
0
),
buflen_
(
0
)
{}
EvbufferBuffer
::
EvbufferBuffer
(
evbuffer
*
evbuffer
,
uint8_t
*
buf
,
size_t
bufmax
)
:
evbuffer_
(
evbuffer
),
buf_
(
buf
),
bufmax_
(
bufmax
),
buflen_
(
0
)
{}
void
EvbufferBuffer
::
reset
(
evbuffer
*
evbuffer
,
uint8_t
*
buf
,
size_t
bufmax
)
{
evbuffer_
=
evbuffer
;
buf_
=
buf
;
bufmax_
=
bufmax
;
buflen_
=
0
;
}
int
EvbufferBuffer
::
flush
()
{
int
rv
;
if
(
buflen_
>
0
)
{
rv
=
evbuffer_add
(
evbuffer_
,
buf_
,
buflen_
);
if
(
rv
==
-
1
)
{
return
-
1
;
}
buflen_
=
0
;
}
return
0
;
}
int
EvbufferBuffer
::
add
(
const
uint8_t
*
data
,
size_t
datalen
)
{
int
rv
;
if
(
buflen_
+
datalen
>
bufmax_
)
{
if
(
buflen_
>
0
)
{
rv
=
evbuffer_add
(
evbuffer_
,
buf_
,
buflen_
);
if
(
rv
==
-
1
)
{
return
-
1
;
}
buflen_
=
0
;
}
if
(
datalen
>
bufmax_
)
{
rv
=
evbuffer_add
(
evbuffer_
,
data
,
datalen
);
if
(
rv
==
-
1
)
{
return
-
1
;
}
return
0
;
}
}
memcpy
(
buf_
+
buflen_
,
data
,
datalen
);
buflen_
+=
datalen
;
return
0
;
}
size_t
EvbufferBuffer
::
get_buflen
()
const
{
return
buflen_
;
}
bool
numeric_host
(
const
char
*
hostname
)
{
struct
addrinfo
hints
;
...
...
@@ -657,24 +593,6 @@ char* get_exec_path(int argc, char **const argv, const char *cwd)
return
path
;
}
void
bev_enable_unless
(
bufferevent
*
bev
,
int
events
)
{
if
((
bufferevent_get_enabled
(
bev
)
&
events
)
==
events
)
{
return
;
}
bufferevent_enable
(
bev
,
events
);
}
void
bev_disable_unless
(
bufferevent
*
bev
,
int
events
)
{
if
((
bufferevent_get_enabled
(
bev
)
&
events
)
==
0
)
{
return
;
}
bufferevent_disable
(
bev
,
events
);
}
}
// namespace util
}
// namespace nghttp2
src/util.h
View file @
446f8f13
...
...
@@ -37,9 +37,6 @@
#include <sstream>
#include <memory>
#include <event2/buffer.h>
#include <event2/bufferevent.h>
#include "http-parser/http_parser.h"
namespace
nghttp2
{
...
...
@@ -448,21 +445,6 @@ void write_uri_field(std::ostream& o,
const
char
*
uri
,
const
http_parser_url
&
u
,
http_parser_url_fields
field
);
class
EvbufferBuffer
{
public:
EvbufferBuffer
();
EvbufferBuffer
(
evbuffer
*
evbuffer
,
uint8_t
*
buf
,
size_t
bufmax
);
void
reset
(
evbuffer
*
evbuffer
,
uint8_t
*
buf
,
size_t
bufmax
);
int
flush
();
int
add
(
const
uint8_t
*
data
,
size_t
datalen
);
size_t
get_buflen
()
const
;
private:
evbuffer
*
evbuffer_
;
uint8_t
*
buf_
;
size_t
bufmax_
;
size_t
buflen_
;
};
bool
numeric_host
(
const
char
*
hostname
);
// Opens |path| with O_APPEND enabled. If file does not exist, it is
...
...
@@ -482,12 +464,6 @@ std::string ascii_dump(const uint8_t *data, size_t len);
// it.
char
*
get_exec_path
(
int
argc
,
char
**
const
argv
,
const
char
*
cwd
);
// These functions are provided to reduce epoll_ctl syscall. Avoid
// calling bufferevent_enable/disable() unless it is required by
// sniffing current enabled events.
void
bev_enable_unless
(
bufferevent
*
bev
,
int
events
);
void
bev_disable_unless
(
bufferevent
*
bev
,
int
events
);
}
// namespace util
}
// namespace nghttp2
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment