Skip to content

Commit 2005d5c

Browse files
committed
bye felicia (nghttp2/wslay)
1 parent 657e462 commit 2005d5c

24 files changed

+295
-1555
lines changed

.clang-format

+9-7
Original file line numberDiff line numberDiff line change
@@ -66,20 +66,22 @@ IncludeBlocks: Regroup
6666
IncludeCategories:
6767
- Regex: '".+\.h'
6868
Priority: 2
69-
- Regex: '^<(event2|ngtcp2)'
69+
- Regex: '^<wshttp'
7070
Priority: 3
71-
- Regex: '<winsock2\.h>'
71+
- Regex: '^<(event2|ngtcp2)'
7272
Priority: 4
73-
- Regex: '<windows\.h>'
73+
- Regex: '<winsock2\.h>'
7474
Priority: 5
75-
- Regex: '^<CLI'
75+
- Regex: '<windows\.h>'
7676
Priority: 6
77-
- Regex: '^<catch2'
77+
- Regex: '^<CLI'
7878
Priority: 7
79-
- Regex: '^<.*\.h(pp)?>$'
79+
- Regex: '^<catch2'
8080
Priority: 8
81-
- Regex: '(<)(.)+(>)'
81+
- Regex: '^<.*\.h(pp)?>$'
8282
Priority: 9
83+
- Regex: '(<)(.)+(>)'
84+
Priority: 10
8385

8486
# spacing
8587
SpaceBeforeParens: ControlStatements

.gitmodules

-6
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,3 @@
1-
[submodule "external/nghttp2"]
2-
path = external/nghttp2
3-
url = https://github.com/nghttp2/nghttp2.git
4-
[submodule "external/wslay"]
5-
path = external/wslay
6-
url = https://github.com/tatsuhiro-t/wslay.git
71
[submodule "external/spdlog"]
82
path = external/spdlog
93
url = https://github.com/gabime/spdlog.git

external/CMakeLists.txt

+1-19
Original file line numberDiff line numberDiff line change
@@ -4,29 +4,11 @@ find_package(Git)
44
if(GIT_FOUND)
55
message(STATUS "Checking submodules")
66
include(check_submodule)
7+
check_submodule(ada)
78
check_submodule(libevent)
8-
check_submodule(nghttp2)
99
check_submodule(spdlog)
10-
check_submodule(wslay)
1110
endif()
1211

13-
# nghttp2
14-
set(WITH_NEVERBLEED OFF CACHE BOOL "" FORCE)
15-
set(WITH_MRUBY OFF CACHE BOOL "" FORCE)
16-
set(BUILD_SHARED_LIBS OFF CACHE BOOL "" FORCE)
17-
set(BUILD_STATIC_LIBS ON CACHE BOOL "" FORCE)
18-
set(ENABLE_DOC OFF CACHE BOOL "" FORCE)
19-
set(ENABLE_HTTP3 OFF CACHE BOOL "" FORCE)
20-
set(ENABLE_LIB_ONLY ON CACHE BOOL "" FORCE) # toggles off ENABLE_APP and ENABLE_EXAMPLES
21-
add_subdirectory(nghttp2 EXCLUDE_FROM_ALL)
22-
23-
# wslay
24-
set(WSLAY_CONFIGURE_INSTALL OFF CACHE BOOL "" FORCE)
25-
set(WSLAY_STATIC ON CACHE BOOL "" FORCE)
26-
set(WSLAY_SHARED OFF CACHE BOOL "" FORCE)
27-
add_subdirectory(wslay EXCLUDE_FROM_ALL)
28-
add_library(wslay::wslay ALIAS wslay)
29-
3012
# spdlog
3113
set(SPDLOG_FMT_EXTERNAL_HO ON CACHE BOOL "" FORCE)
3214
add_subdirectory(spdlog EXCLUDE_FROM_ALL)

external/nghttp2

-1
This file was deleted.

external/wslay

-1
This file was deleted.

include/wshttp.hpp

-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
#include "wshttp/listener.hpp"
99
#include "wshttp/loop.hpp"
1010
#include "wshttp/request.hpp"
11-
#include "wshttp/session.hpp"
1211
#include "wshttp/ssl.hpp"
13-
#include "wshttp/stream.hpp"
1412
#include "wshttp/types.hpp"
1513
#include "wshttp/utils.hpp"

include/wshttp/address.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ namespace wshttp
172172
{
173173
constexpr ip_address(uint16_t p = 0) : _ip{}, _port{p} {}
174174

175-
explicit ip_address(struct sockaddr* in);
175+
explicit ip_address(const struct sockaddr* in);
176176

177177
template <ip_type T>
178178
constexpr explicit ip_address(T v4, uint16_t p) : _ip{v4}, _port{p}

include/wshttp/endpoint.hpp

+27-22
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
#pragma once
22

3+
#include "address.hpp"
34
#include "dns.hpp"
45
#include "format.hpp"
56
#include "loop.hpp"
6-
#include "session.hpp"
7+
#include "request.hpp"
78

89
namespace wshttp
910
{
1011
using namespace wshttp::literals;
1112

1213
struct ssl_creds;
14+
class listener;
1315

1416
namespace dns
1517
{
@@ -71,7 +73,7 @@ namespace wshttp
7173
std::unordered_map<uint16_t, std::shared_ptr<listener>> _listeners{};
7274

7375
// sessions managing outbound https connections
74-
std::unordered_map<domain_host, std::shared_ptr<outbound_node>> _outbounds{};
76+
// std::unordered_map<domain_host, std::shared_ptr<outbound_node>> _outbounds{};
7577

7678
std::atomic<bool> _close_immediately{false};
7779

@@ -94,35 +96,37 @@ namespace wshttp
9496
});
9597
}
9698

97-
template <typename... Opt>
98-
bool connect(std::string_view url, Opt&&... opts)
99-
{
100-
return call_get([&]() {
101-
auto _uri = uri::parse(url);
102-
if (not _uri)
103-
throw std::invalid_argument{"Failed to parse input url: {}"_format(url)};
99+
// template <typename... Opt>
100+
// bool connect(std::string_view url, Opt&&... opts)
101+
// {
102+
// return call_get([&]() {
103+
// auto _uri = uri::parse(url);
104+
// if (not _uri)
105+
// throw std::invalid_argument{"Failed to parse input url: {}"_format(url)};
104106

105-
auto [itr, b] = _outbounds.try_emplace(_uri.host_url(), nullptr);
107+
// auto [itr, b] = _outbounds.try_emplace(_uri.host_url(), nullptr);
106108

107-
if (not b)
108-
throw std::invalid_argument{
109-
"Cannot create outbound node for input: {} -- node already exists!"_format(url)};
109+
// if (not b)
110+
// throw std::invalid_argument{
111+
// "Cannot create outbound node for input: {} -- node already exists!"_format(url)};
110112

111-
itr->second = make_shared<outbound_node>(*this, std::move(_uri), std::forward<Opt>(opts)...);
113+
// itr->second = make_shared<outbound_node>(*this, std::move(_uri), std::forward<Opt>(opts)...);
112114

113-
if (not itr->second)
114-
throw std::runtime_error{"Node construction is fucked"};
115+
// if (not itr->second)
116+
// throw std::runtime_error{"Node construction is fucked"};
115117

116-
return true;
117-
});
118-
}
118+
// return true;
119+
// });
120+
// }
119121

120122
void test_parse_method(std::string url);
121123

122124
const std::shared_ptr<event_loop>& loop() { return _loop; }
123125

124126
void set_shutdown_immediate(bool b = true) { _close_immediately = b; }
125127

128+
bool in_event_loop() const { return _loop->in_event_loop(); }
129+
126130
protected:
127131
template <typename T, typename Callable>
128132
std::shared_ptr<T> shared_ptr(T* obj, Callable&& deleter)
@@ -136,17 +140,18 @@ namespace wshttp
136140
return _loop->template make_shared<T>(std::forward<Args>(args)...);
137141
}
138142

139-
void close_node(domain_host d);
140143
void close_listener(uint16_t p);
141144

142-
bool in_event_loop() const { return _loop->in_event_loop(); }
143-
144145
void shutdown_endpoint();
145146

146147
SSL_CTX* inbound_ctx();
147148

148149
SSL_CTX* outbound_ctx();
149150

151+
struct event_base* ev_base() { return loop()->loop().get(); }
152+
153+
struct evhttp* make_evhttp();
154+
150155
private:
151156
void handle_ep_opt(std::shared_ptr<ssl_creds> c);
152157

include/wshttp/listener.hpp

+18-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#pragma once
22

33
#include "address.hpp"
4+
#include "loop.hpp"
45
#include "ssl.hpp"
56

67
extern "C" {
@@ -19,23 +20,29 @@ namespace wshttp
1920
public:
2021
local_node(ip_address l) : _local{std::move(l)} {}
2122

22-
virtual SSL* new_ssl() = 0;
23+
virtual bufferevent* new_nev() = 0;
2324
virtual void close() = 0;
2425
};
2526

2627
class app_context;
2728
class endpoint;
28-
class inbound_session;
29+
struct inbound_request;
2930

3031
namespace deleters
3132
{
3233
struct _evconnlistener
3334
{
3435
inline void operator()(::evconnlistener* e) const { ::evconnlistener_free(e); }
3536
};
37+
38+
struct _evhttp
39+
{
40+
inline void operator()(::evhttp* e) const { return evhttp_free(e); }
41+
};
3642
} // namespace deleters
3743

3844
using tcp_listener = std::shared_ptr<evconnlistener>;
45+
using evhttp_ptr = std::unique_ptr<::evhttp, deleters::_evhttp>;
3946

4047
class listener
4148
{
@@ -44,7 +51,7 @@ namespace wshttp
4451
friend class event_loop;
4552
friend struct listen_callbacks;
4653

47-
explicit listener(endpoint& e, uint16_t p) : _ep{e}, _local{p} { _init_internals(); }
54+
explicit listener(endpoint& e, uint16_t p);
4855

4956
public:
5057
listener() = delete;
@@ -56,14 +63,19 @@ namespace wshttp
5663
ip_address _local{};
5764
int _fd{-1};
5865

59-
tcp_listener _tcp;
66+
// tcp_listener _tcp;
67+
evhttp_ptr _evh;
6068

6169
// key: remote address, value: session ptr
62-
std::unordered_map<ip_address, std::shared_ptr<inbound_session>> _sessions;
70+
std::unordered_map<ip_address, std::shared_ptr<inbound_request>> _sessions;
6371

64-
void _init_internals();
72+
// void _init_internals();
6573

6674
protected:
75+
int accept_request(struct evhttp_request* req);
76+
77+
bufferevent* new_bev();
78+
6779
SSL* new_ssl();
6880

6981
void close_all();

include/wshttp/loop.hpp

+3-4
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,6 @@ extern "C" {
1616

1717
namespace wshttp
1818
{
19-
using Job = std::function<void()>;
20-
using loop_ptr = std::shared_ptr<::event_base>;
21-
using caller_id_t = uint16_t;
22-
2319
class event_loop;
2420

2521
namespace deleters
@@ -30,7 +26,10 @@ namespace wshttp
3026
};
3127
} // namespace deleters
3228

29+
using Job = std::function<void()>;
30+
using loop_ptr = std::shared_ptr<::event_base>;
3331
using event_ptr = std::unique_ptr<::event, deleters::_event>;
32+
using caller_id_t = uint16_t;
3433

3534
struct ev_watcher
3635
{

0 commit comments

Comments
 (0)