File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11#include " process_ctrl.hpp"
2+ #include < cstdio>
23
34namespace cppapp {
45
@@ -47,9 +48,11 @@ void ProcessCtrl::EndGuard(int) {
4748#endif
4849}
4950
50- void ProcessCtrl::Kill (int pid, int signal) {
51+ int ProcessCtrl::Kill (int pid, int signal) {
5152#ifndef _WIN32
52- kill (pid, signal);
53+ return kill (pid, signal);
54+ #else
55+ return -1 ;
5356#endif
5457}
5558
Original file line number Diff line number Diff line change 11#pragma once
22
33#include < csignal>
4- #include < cstdio>
54#include < cstdlib>
65#include < functional>
76#include < sys/wait.h>
@@ -41,7 +40,7 @@ class ProcessCtrl {
4140 * @param pid
4241 * @note 1. Send a signal to the process with the specified pid.
4342 */
44- static void Kill (int pid, int signal = SIGINT );
43+ static int Kill (int pid, int signal = SIGINT );
4544
4645private:
4746 static void EndGuard (int );
Original file line number Diff line number Diff line change 77 "redirects" :[
88 {
99 "route" :" /hello" ,
10- "redirect" :" https://chenxuanweb.top"
10+ "redirect" :" https://www.chenxuanweb.top"
11+ },
12+ {
13+ "route" :" /" ,
14+ "redirect" :" ../asset/index.html"
1115 }
1216 ],
1317 "statics" :[
14- {
15- "route" :" /" ,
16- "path" :" ../asset/index.html"
17- },
1818 {
1919 "route" :" /home" ,
2020 "path" :" ../asset/blog-home/index.html"
Original file line number Diff line number Diff line change @@ -116,6 +116,11 @@ void RunWithConfig(Config &config) {
116116 server.set_logger (logger);
117117 }
118118
119+ // add header server for sign cppnet server
120+ server.Use ([](HttpContext &ctx) {
121+ ctx.resp ().header ().Add (" Server" , " cppnet/" + Version::GetStr ());
122+ });
123+
119124 // write pid into file
120125 File::Write (" ./server.pid" , to_string (pid));
121126
@@ -145,12 +150,20 @@ int _main(ArgcDeal &args) {
145150 cout << " pid too small, check if error" ;
146151 exit (0 );
147152 }
148- ProcessCtrl::Kill (pid);
153+ auto kill_result = ProcessCtrl::Kill (pid);
154+ if (kill_result != 0 ) {
155+ cout << " kill " << pid << " error" << endl;
156+ exit (-1 );
157+ }
158+ cout << " kill " << pid << " stop ok" << endl;
149159 if (args.GetOption (" stop" )) {
150- cout << " kill " << pid << " stop ok" << endl;
160+ // delete file
161+ File::Remove (" ./server.pid" );
162+ cout << " delete pid file" << endl;
151163 exit (0 );
164+
152165 } else {
153- printf ( " wait for the port unbound...\n " ) ;
166+ cout << " wait for the port unbound..." << endl ;
154167 sleep (1 );
155168 }
156169 }
Original file line number Diff line number Diff line change @@ -143,6 +143,11 @@ const Trie::Node *Trie::GetNode(const std::string &key) const {
143143 pos = 1 ;
144144 }
145145 }
146+
147+ if (pos != now->key_ .size ()) {
148+ return nullptr ;
149+ }
150+
146151 if (now->stop_ == false ) {
147152 return nullptr ;
148153 }
Original file line number Diff line number Diff line change @@ -77,6 +77,11 @@ TEST(Trie, Test) {
7777 });
7878 MUST_TRUE (count == 0 , " count is " << count);
7979
80+ trie.Search <int >(" world.cdsc" , [&](shared_ptr<int > data, bool last) -> bool {
81+ EXPECT_EQ (last, false );
82+ return true ;
83+ });
84+
8085 // test
8186 trie.Reset ();
8287 MUST_TRUE (trie.Get <int >(" hello" ) == nullptr , " " );
@@ -142,3 +147,17 @@ TEST(Trie, OriginApi) {
142147 });
143148 MUST_TRUE (count == 1 , " error count of " << count);
144149}
150+
151+ TEST (Trie, Search) {
152+ Trie trie;
153+ trie.Set (" /hello" , std::make_shared<vector<int >>(1 ));
154+ auto temp = trie.Get <int >(" /he" );
155+ trie.Set (" /" , std::make_shared<int >(2 ));
156+
157+ MUST_TRUE (temp == nullptr , " not null" );
158+
159+ trie.SearchNode (" /hello" , [&](const Trie::Node *node, bool last) -> bool {
160+ DEBUG (" node temp " << node->key_ << " is_end " << last);
161+ return true ;
162+ });
163+ }
You can’t perform that action at this time.
0 commit comments