Skip to content

Commit dbcfcee

Browse files
committed
Realized --update-module command (update applications modules without shutdown/restart http server)
1 parent e1a2916 commit dbcfcee

16 files changed

+803
-357
lines changed

httpserver.userprefs

Lines changed: 12 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,20 @@
11
<Properties>
22
<MonoDevelop.Ide.Workspace ActiveConfiguration="Debug" />
3-
<MonoDevelop.Ide.Workbench ActiveDocument="httpserver/Server.h">
3+
<MonoDevelop.Ide.Workbench ActiveDocument="httpserver/Server.cpp">
44
<Files>
5-
<File FileName="httpserver/Server.cpp" Line="1360" Column="6" />
6-
<File FileName="httpserver/Server.h" Line="74" Column="3" />
7-
<File FileName="httpserver/Main.cpp" Line="12" Column="4" />
8-
<File FileName="httpserver/Main.h" Line="1" Column="1" />
9-
<File FileName="httpserver/DataVariantMultipartFormData.h" Line="1" Column="1" />
10-
<File FileName="httpserver/DataVariantMultipartFormData.cpp" Line="1" Column="1" />
11-
<File FileName="httpserver/ServerRequest.h" Line="1" Column="1" />
12-
<File FileName="httpserver/ServerResponse.h" Line="1" Column="1" />
13-
<File FileName="httpserver/Event.cpp" Line="1" Column="1" />
14-
<File FileName="httpserver/DataVariantAbstract.h" Line="1" Column="1" />
15-
<File FileName="httpserver/DataVariantFormUrlencoded.h" Line="1" Column="1" />
16-
<File FileName="httpserver/DataVariantFormUrlencoded.cpp" Line="1" Column="1" />
17-
<File FileName="httpserver/ServerApplicationSettings.h" Line="14" Column="12" />
18-
<File FileName="httpserver/ServerApplicationsTree.h" Line="32" Column="3" />
19-
<File FileName="httpserver/ServerApplicationsTree.cpp" Line="151" Column="4" />
20-
<File FileName="httpserver/System.h" Line="1" Column="1" />
21-
<File FileName="httpserver/DataVariantTextPlain.h" Line="1" Column="1" />
22-
<File FileName="httpserver/DataVariantTextPlain.cpp" Line="1" Column="1" />
23-
<File FileName="httpserver/System.cpp" Line="1" Column="1" />
5+
<File FileName="httpserver/Server.cpp" Line="1409" Column="30" />
6+
<File FileName="httpserver/Module.cpp" Line="1" Column="1" />
7+
<File FileName="httpserver/SignalsHandles.cpp" Line="101" Column="20" />
248
<File FileName="httpserver/Utils.h" Line="1" Column="1" />
25-
<File FileName="httpserver/Utils.cpp" Line="1" Column="1" />
26-
<File FileName="httpserver/Socket.cpp" Line="253" Column="21" />
9+
<File FileName="httpserver/Main.cpp" Line="1" Column="1" />
10+
<File FileName="httpserver/Module.h" Line="1" Column="1" />
11+
<File FileName="httpserver/Server.h" Line="96" Column="26" />
2712
<File FileName="httpserver/Event.h" Line="1" Column="1" />
28-
<File FileName="httpserver/Socket.h" Line="59" Column="29" />
13+
<File FileName="httpserver/Event.cpp" Line="1" Column="1" />
14+
<File FileName="httpserver/System.cpp" Line="12" Column="2" />
15+
<File FileName="httpserver/System.h" Line="20" Column="20" />
16+
<File FileName="httpserver/SignalsHandles.h" Line="7" Column="19" />
17+
<File FileName="httpserver/Main.h" Line="7" Column="32" />
2918
</Files>
3019
</MonoDevelop.Ide.Workbench>
3120
<MonoDevelop.Ide.DebuggingService.Breakpoints>

httpserver/Event.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ namespace HttpServer
1414
bool manualy;
1515

1616
public:
17-
Event(const bool = false, const bool = false);
17+
Event(const bool _signaled = false, const bool _manualy = false);
1818
~Event() = default;
1919

2020
public:

httpserver/Main.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,11 @@
99
int main(const int argc, const char *argv[])
1010
{
1111
const std::unordered_map<std::string, std::function<int(HttpServer::Server *, const int, const char *[])> > commands {
12-
{"--help", std::mem_fn(&HttpServer::Server::help)},
13-
{"--start", std::mem_fn(&HttpServer::Server::start)},
14-
{"--restart", std::mem_fn(&HttpServer::Server::restart)},
15-
{"--kill", std::mem_fn(&HttpServer::Server::terminate)}
12+
{"--help", std::mem_fn(&HttpServer::Server::command_help)},
13+
{"--start", std::mem_fn(&HttpServer::Server::command_start)},
14+
{"--restart", std::mem_fn(&HttpServer::Server::command_restart)},
15+
{"--kill", std::mem_fn(&HttpServer::Server::command_terminate)},
16+
{"--update-module", std::mem_fn(&HttpServer::Server::command_update_module)}
1617
};
1718

1819
int exitcode = EXIT_FAILURE;

httpserver/Main.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#ifdef WIN32
66
#include <thread>
77
std::thread threadMessageLoop;
8-
char wndClassName[] = "WndClassNameConstant";
8+
char myWndClassName[] = "WndClassNameConstant";
99
#endif
1010

1111
HttpServer::Server *globalServerPtr = nullptr;

httpserver/Module.cpp

Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
2+
#include "Module.h"
3+
4+
namespace HttpServer
5+
{
6+
Module::Module(): lib_handle(nullptr)
7+
{
8+
9+
}
10+
11+
Module::Module(const std::string &libPath): lib_handle(nullptr)
12+
{
13+
open(libPath);
14+
}
15+
16+
Module::Module(const Module &module) : lib_handle(module.lib_handle)
17+
{
18+
19+
}
20+
21+
Module::Module(Module &&module) : lib_handle(module.lib_handle)
22+
{
23+
module.lib_handle = nullptr;
24+
}
25+
26+
bool Module::open(const std::string &libPath)
27+
{
28+
if (is_open() )
29+
{
30+
close();
31+
}
32+
33+
#ifdef WIN32
34+
lib_handle = ::LoadLibrary(libPath.c_str() );
35+
#elif POSIX
36+
lib_handle = ::dlopen(libPath.c_str(), RTLD_NOW | RTLD_LOCAL);
37+
#else
38+
#error "Undefine platform"
39+
#endif
40+
41+
if (nullptr == lib_handle)
42+
{
43+
return false;
44+
}
45+
46+
return true;
47+
}
48+
49+
void Module::close()
50+
{
51+
if (lib_handle)
52+
{
53+
#ifdef WIN32
54+
::FreeLibrary(lib_handle);
55+
#elif POSIX
56+
::dlclose(lib_handle);
57+
#else
58+
#error "Undefine platform"
59+
#endif
60+
61+
lib_handle = nullptr;
62+
}
63+
}
64+
65+
bool Module::find(const std::string &symbolName, void *(**addr)(void *) ) const
66+
{
67+
if (lib_handle)
68+
{
69+
#ifdef WIN32
70+
*addr = reinterpret_cast<void *(*)(void *)>(::GetProcAddress(lib_handle, symbolName.c_str() ) );
71+
72+
return nullptr != *addr;
73+
#elif POSIX
74+
char *error = ::dlerror();
75+
76+
*addr = reinterpret_cast<void *(*)(void *)>(::dlsym(lib_handle, symbolName.c_str() ) );
77+
78+
error = ::dlerror();
79+
80+
return nullptr == error;
81+
#else
82+
#error "Undefine platform"
83+
#endif
84+
}
85+
86+
return false;
87+
}
88+
89+
bool Module::find(const char *symbolName, void *(**addr)(void *) ) const
90+
{
91+
if (lib_handle)
92+
{
93+
#ifdef WIN32
94+
*addr = reinterpret_cast<void *(*)(void *)>(::GetProcAddress(lib_handle, symbolName) );
95+
96+
return nullptr != *addr;
97+
#elif POSIX
98+
char *error = ::dlerror();
99+
100+
*addr = reinterpret_cast<void *(*)(void *)>(::dlsym(lib_handle, symbolName) );
101+
102+
error = ::dlerror();
103+
104+
return nullptr == error;
105+
#else
106+
#error "Undefine platform"
107+
#endif
108+
}
109+
110+
return false;
111+
}
112+
113+
Module &Module::operator =(const Module &module)
114+
{
115+
if (*this != module)
116+
{
117+
close();
118+
119+
lib_handle = module.lib_handle;
120+
}
121+
122+
return *this;
123+
}
124+
125+
Module &Module::operator =(Module &&module)
126+
{
127+
if (*this != module)
128+
{
129+
close();
130+
131+
lib_handle = module.lib_handle;
132+
133+
module.lib_handle = nullptr;
134+
}
135+
136+
return *this;
137+
}
138+
};

httpserver/Module.h

Lines changed: 14 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -24,25 +24,10 @@ namespace HttpServer
2424
#endif
2525

2626
public:
27-
Module(): lib_handle(nullptr)
28-
{
29-
30-
}
31-
32-
Module(const std::string &libPath): lib_handle(nullptr)
33-
{
34-
open(libPath);
35-
}
36-
37-
Module(const Module &module) : lib_handle(module.lib_handle)
38-
{
39-
40-
}
41-
42-
Module(Module &&module) : lib_handle(module.lib_handle)
43-
{
44-
module.lib_handle = nullptr;
45-
}
27+
Module();
28+
Module(const std::string &libPath);
29+
Module(const Module &module);
30+
Module(Module &&module);
4631

4732
~Module() = default;
4833

@@ -51,84 +36,23 @@ namespace HttpServer
5136
return nullptr != lib_handle;
5237
}
5338

54-
inline bool open(const std::string &libPath)
55-
{
56-
#ifdef WIN32
57-
lib_handle = ::LoadLibrary(libPath.c_str() );
58-
#elif POSIX
59-
lib_handle = ::dlopen(libPath.c_str(), RTLD_NOW);
60-
#else
61-
#error "Undefine platform"
62-
#endif
63-
64-
return (nullptr != lib_handle);
65-
}
66-
67-
inline void close()
68-
{
69-
if (lib_handle)
70-
{
71-
#ifdef WIN32
72-
::FreeLibrary(lib_handle);
73-
#elif POSIX
74-
::dlclose(lib_handle);
75-
#else
76-
#error "Undefine platform"
77-
#endif
39+
bool open(const std::string &libPath);
40+
void close();
7841

79-
lib_handle = nullptr;
80-
}
81-
}
42+
bool find(const std::string &symbolName, void *(**addr)(void *) ) const;
43+
bool find(const char *symbolName, void *(**addr)(void *) ) const;
8244

83-
inline bool find(const std::string &symbolName, void **addr) const
45+
inline bool operator ==(const Module &module) const
8446
{
85-
if (lib_handle)
86-
{
87-
#ifdef WIN32
88-
*addr = ::GetProcAddress(lib_handle, symbolName.c_str() );
89-
90-
return nullptr != *addr;
91-
#elif POSIX
92-
::dlerror();
93-
94-
*addr = ::dlsym(lib_handle, symbolName.c_str() );
95-
96-
char *error = ::dlerror();
97-
98-
return nullptr == error;
99-
#else
100-
#error "Undefine platform"
101-
#endif
102-
}
103-
104-
return false;
47+
return lib_handle == module.lib_handle;
10548
}
10649

107-
inline bool find(const char *symbolName, void **addr) const
50+
inline bool operator !=(const Module &module) const
10851
{
109-
if (lib_handle)
110-
{
111-
#ifdef WIN32
112-
*addr = ::GetProcAddress(lib_handle, symbolName);
113-
114-
return nullptr != *addr;
115-
#elif POSIX
116-
*addr = ::dlsym(lib_handle, symbolName);
117-
118-
char *error = ::dlerror();
119-
120-
return nullptr == error;
121-
#else
122-
#error "Undefine platform"
123-
#endif
124-
}
125-
126-
return false;
52+
return lib_handle != module.lib_handle;
12753
}
12854

129-
inline bool operator ==(const Module &module) const
130-
{
131-
return lib_handle == module.lib_handle;
132-
}
55+
Module &operator =(const Module &);
56+
Module &operator =(Module &&);
13357
};
13458
};

0 commit comments

Comments
 (0)