Skip to content

Commit 0ffda71

Browse files
committed
-
1 parent 0960eae commit 0ffda71

5 files changed

Lines changed: 25 additions & 33 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
其他发行版对应安装
3030

3131

32-
- windows使用最新编译器,安装xmake.最好安装`windows terminal`
32+
- windows使用最新msvc编译器,安装xmake.最好安装`windows terminal`
3333

3434
---
3535

src/certificate/cert.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -323,12 +323,12 @@ namespace hcpp
323323
X509_set_issuer_name(cert, X509_get_subject_name(ca_cert));
324324
}
325325

326-
void test()
327-
{
326+
// static void test()
327+
// {
328328

329-
auto cert = X509_new();
329+
// auto cert = X509_new();
330330

331-
auto pkey = generate_pkey();
331+
// auto pkey = generate_pkey();
332332
// if (pkey == NULL)
333333
// CHECK(false);
334334
// print_key(pkey);
@@ -374,5 +374,5 @@ namespace hcpp
374374

375375
// fclose(caCertFile);
376376
// X509_free(cert);
377-
}
377+
// }
378378
} // namespace hcpp

src/certificate/cert.h

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,27 +18,22 @@ namespace hcpp
1818
int nid_val_len_;
1919
};
2020

21+
const inline std::vector<name_entry> default_name_entries = {
22+
{NID_countryName, "CN", sizeof("CN") - 1},
23+
{NID_organizationName, "NoBody", sizeof("NoBody") - 1},
24+
{NID_organizationalUnitName, "JS", sizeof("JS") - 1},
25+
{NID_stateOrProvinceName, "JS", sizeof("JS") - 1},
26+
{NID_commonName, "SQ", sizeof("SQ") - 1},
27+
{NID_localityName, "SQ", sizeof("SQ") - 1},
28+
};
29+
2130
X509 *make_x509();
2231
EVP_PKEY *make_pkey();
2332
void set_version(X509 *cert);
2433
void set_serialNumber(X509 *cert);
25-
void set_issuer(X509 *cert, const std::vector<name_entry> &ne = {
26-
{NID_countryName, "CN", sizeof("CN") - 1},
27-
{NID_organizationName, "NoBody", sizeof("NoBody") - 1},
28-
{NID_organizationalUnitName, "JS", sizeof("JS") - 1},
29-
{NID_stateOrProvinceName, "JS", sizeof("JS") - 1},
30-
{NID_commonName, "SQ", sizeof("SQ") - 1},
31-
{NID_localityName, "SQ", sizeof("SQ") - 1},
32-
});
34+
void set_issuer(X509 *cert, const std::vector<name_entry> &ne = default_name_entries);
3335
void set_validity(X509 *cert, std::size_t days = 365 * 10);
34-
void set_subject(X509 *cert, const std::vector<name_entry> &ne = {
35-
{NID_countryName, "CN", sizeof("CN") - 1},
36-
{NID_organizationName, "NoBody", sizeof("NoBody") - 1},
37-
{NID_organizationalUnitName, "JS", sizeof("JS") - 1},
38-
{NID_stateOrProvinceName, "JS", sizeof("JS") - 1},
39-
{NID_commonName, "SQ", sizeof("SQ") - 1},
40-
{NID_localityName, "SQ", sizeof("SQ") - 1},
41-
});
36+
void set_subject(X509 *cert, const std::vector<name_entry> &ne = default_name_entries);
4237
void set_pubkey(X509 *cert, EVP_PKEY *pkey);
4338
void add_ca_key_usage(X509 *cert);
4439
void add_SKI(X509 *cert);

src/httpserver.cpp

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ namespace hcpp
222222

223223
co_await nc->async_send(asio::error_code{}, "ok");
224224
// 在当前协程运行
225-
auto https_listener = [c = channel_, cr_ps_map, ca_subject = ca_subject_]() -> awaitable<void>
225+
auto https_listener = [c = channel_, cr_ps_map, ca_subject = ca_subject_](io_context &executor) -> awaitable<void>
226226
{
227227
http_handler hh;
228228
for (;;)
@@ -272,7 +272,7 @@ namespace hcpp
272272
self.set_mem(co_await std::move(*cc).make(std::move(si)));
273273
};
274274

275-
co_spawn(co_await this_coro::executor, hh.http_do(std::move(hsc), std::move(sk)), detached);
275+
co_spawn(executor, hh.http_do(std::move(hsc), std::move(sk)), detached);
276276
}
277277
catch (const std::exception &e)
278278
{
@@ -281,11 +281,10 @@ namespace hcpp
281281
}
282282
};
283283

284-
auto work_guard = make_work_guard(executor);
285-
286284
auto https_service = [&executor]()
287285
{
288286
spdlog::debug("mimt https server线程创建成功");
287+
auto work_guard = make_work_guard(executor);
289288
while (!executor.stopped())
290289
{
291290
try
@@ -299,18 +298,16 @@ namespace hcpp
299298
}
300299
spdlog::debug("mimt https server线程退出成功");
301300
};
302-
std::thread t(https_service);
303-
t.detach();
301+
std::jthread t(https_service);
304302

305-
std::unique_ptr<int, std::function<void(int *)>> ptr(new int(0), [&work_guard, &executor](auto &&p)
303+
std::unique_ptr<int, std::function<void(int *)>> ptr(new int(0), [ &executor](auto &&p)
306304
{
307305
log::info("work_guard分离");
308-
work_guard.reset();
309-
std::this_thread::sleep_for(std::chrono::seconds(1));
310306
executor.stop();
307+
std::this_thread::sleep_for(std::chrono::seconds(1));
311308
delete p; });
312309

313-
co_await co_spawn(executor, https_listener(), use_awaitable);
310+
co_await https_listener(executor);
314311
// XXX 不会执行到这里
315312
co_return;
316313
}

xmake.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
set_project("hcpp")
2-
set_xmakever("2.8.7")
2+
set_xmakever("2.8.8")
33
add_rules("mode.debug", "mode.release")
44

55
set_warnings("all")

0 commit comments

Comments
 (0)