Skip to content

Commit 2ce9315

Browse files
committed
Command line parameters '--config-path=' and '--server-name=' were added (for Windows)
1 parent 5016ee4 commit 2ce9315

File tree

10 files changed

+193
-40
lines changed

10 files changed

+193
-40
lines changed

projects/msvs/httpserver.vcxproj

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,13 @@
2525
<ClCompile Include="..\..\src\DataVariantTextPlain.cpp" />
2626
<ClCompile Include="..\..\src\Event.cpp" />
2727
<ClCompile Include="..\..\src\FileIncoming.cpp" />
28+
<ClCompile Include="..\..\src\GlobalMutex.cpp" />
2829
<ClCompile Include="..\..\src\Main.cpp" />
2930
<ClCompile Include="..\..\src\Module.cpp" />
3031
<ClCompile Include="..\..\src\RequestParameters.cpp" />
3132
<ClCompile Include="..\..\src\Server.cpp" />
3233
<ClCompile Include="..\..\src\ServerApplicationsTree.cpp" />
34+
<ClCompile Include="..\..\src\SharedMemory.cpp" />
3335
<ClCompile Include="..\..\src\SignalHandlers.cpp" />
3436
<ClCompile Include="..\..\src\Socket.cpp" />
3537
<ClCompile Include="..\..\src\SocketAdapter.cpp" />
@@ -47,6 +49,7 @@
4749
<ClInclude Include="..\..\src\DataVariantTextPlain.h" />
4850
<ClInclude Include="..\..\src\Event.h" />
4951
<ClInclude Include="..\..\src\FileIncoming.h" />
52+
<ClInclude Include="..\..\src\GlobalMutex.h" />
5053
<ClInclude Include="..\..\src\Main.h" />
5154
<ClInclude Include="..\..\src\Module.h" />
5255
<ClInclude Include="..\..\src\RawData.h" />
@@ -57,6 +60,8 @@
5760
<ClInclude Include="..\..\src\ServerApplicationsTree.h" />
5861
<ClInclude Include="..\..\src\ServerRequest.h" />
5962
<ClInclude Include="..\..\src\ServerResponse.h" />
63+
<ClInclude Include="..\..\src\ServerStructuresArguments.h" />
64+
<ClInclude Include="..\..\src\SharedMemory.h" />
6065
<ClInclude Include="..\..\src\SignalHandlers.h" />
6166
<ClInclude Include="..\..\src\Socket.h" />
6267
<ClInclude Include="..\..\src\SocketAdapter.h" />
@@ -70,6 +75,7 @@
7075
<ProjectGuid>{A7023B84-DA18-3E3E-A9AE-B87F45CAC37F}</ProjectGuid>
7176
<RootNamespace>httpserver</RootNamespace>
7277
<Keyword>Qt4VSv1.0</Keyword>
78+
<WindowsTargetPlatformVersion>8.1</WindowsTargetPlatformVersion>
7379
</PropertyGroup>
7480
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
7581
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
@@ -162,7 +168,7 @@
162168
<ExceptionHandling>Sync</ExceptionHandling>
163169
<ObjectFileName>$(OutDir)obj\</ObjectFileName>
164170
<Optimization>MaxSpeed</Optimization>
165-
<PreprocessorDefinitions>_CONSOLE;WIN32;NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
171+
<PreprocessorDefinitions>_CONSOLE;WIN32;NDEBUG;NOMINMAX;%(PreprocessorDefinitions)</PreprocessorDefinitions>
166172
<PreprocessToFile>false</PreprocessToFile>
167173
<ProgramDataBaseFileName>..\..\build\</ProgramDataBaseFileName>
168174
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
@@ -201,7 +207,7 @@
201207
<ExceptionHandling>Sync</ExceptionHandling>
202208
<ObjectFileName>$(OutDir)obj\</ObjectFileName>
203209
<Optimization>MaxSpeed</Optimization>
204-
<PreprocessorDefinitions>_CONSOLE;WIN32;NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
210+
<PreprocessorDefinitions>_CONSOLE;WIN32;NDEBUG;NOMINMAX;%(PreprocessorDefinitions)</PreprocessorDefinitions>
205211
<PreprocessToFile>false</PreprocessToFile>
206212
<ProgramDataBaseFileName>..\..\build\</ProgramDataBaseFileName>
207213
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
@@ -240,7 +246,7 @@
240246
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
241247
<ExceptionHandling>Sync</ExceptionHandling>
242248
<ObjectFileName>$(OutDir)obj\</ObjectFileName>
243-
<PreprocessorDefinitions>_CONSOLE;WIN32;DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
249+
<PreprocessorDefinitions>_CONSOLE;WIN32;DEBUG;NOMINMAX;%(PreprocessorDefinitions)</PreprocessorDefinitions>
244250
<PreprocessToFile>false</PreprocessToFile>
245251
<ProgramDataBaseFileName>..\..\build\</ProgramDataBaseFileName>
246252
<RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
@@ -278,7 +284,7 @@
278284
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
279285
<ExceptionHandling>Sync</ExceptionHandling>
280286
<ObjectFileName>$(OutDir)obj\</ObjectFileName>
281-
<PreprocessorDefinitions>_CONSOLE;WIN32;DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
287+
<PreprocessorDefinitions>_CONSOLE;WIN32;DEBUG;NOMINMAX;%(PreprocessorDefinitions)</PreprocessorDefinitions>
282288
<PreprocessToFile>false</PreprocessToFile>
283289
<ProgramDataBaseFileName>..\..\build\</ProgramDataBaseFileName>
284290
<RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>

projects/msvs/httpserver.vcxproj.filters

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,12 @@
7676
<ClCompile Include="..\..\src\SocketAdapterTls.cpp">
7777
<Filter>Source Files</Filter>
7878
</ClCompile>
79+
<ClCompile Include="..\..\src\GlobalMutex.cpp">
80+
<Filter>Source Files</Filter>
81+
</ClCompile>
82+
<ClCompile Include="..\..\src\SharedMemory.cpp">
83+
<Filter>Source Files</Filter>
84+
</ClCompile>
7985
</ItemGroup>
8086
<ItemGroup>
8187
<ClInclude Include="..\..\src\ConfigParser.h">
@@ -153,5 +159,14 @@
153159
<ClInclude Include="..\..\src\SocketAdapterTls.h">
154160
<Filter>Header Files</Filter>
155161
</ClInclude>
162+
<ClInclude Include="..\..\src\GlobalMutex.h">
163+
<Filter>Header Files</Filter>
164+
</ClInclude>
165+
<ClInclude Include="..\..\src\ServerStructuresArguments.h">
166+
<Filter>Header Files</Filter>
167+
</ClInclude>
168+
<ClInclude Include="..\..\src\SharedMemory.h">
169+
<Filter>Header Files</Filter>
170+
</ClInclude>
156171
</ItemGroup>
157172
</Project>

projects/msvs/httpserver.vcxproj.user

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,12 @@
1313
<LocalDebuggerWorkingDirectory>D:\httpserver\debug</LocalDebuggerWorkingDirectory>
1414
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
1515
</PropertyGroup>
16+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
17+
<LocalDebuggerCommandArguments>--start</LocalDebuggerCommandArguments>
18+
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
19+
</PropertyGroup>
20+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
21+
<LocalDebuggerCommandArguments>--start</LocalDebuggerCommandArguments>
22+
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
23+
</PropertyGroup>
1624
</Project>

src/GlobalMutex.cpp

Lines changed: 50 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33

44
#ifdef WIN32
55
#include <Windows.h>
6+
7+
#ifdef UNICODE
8+
#include <codecvt>
9+
#endif
610
#elif POSIX
711
#include <fcntl.h>
812
#endif
@@ -24,7 +28,17 @@ namespace HttpServer
2428
this->close();
2529

2630
#ifdef WIN32
27-
this->mtx_desc = ::CreateMutex(nullptr, false, mutexName.c_str() );
31+
32+
this->mtx_name = "mtx-" + mutexName;
33+
34+
#ifdef UNICODE
35+
std::wstring_convert<std::codecvt_utf8_utf16<wchar_t> > converter;
36+
const std::wstring mutex_name = converter.from_bytes(this->mtx_name);
37+
#else
38+
const std::string &mutex_name = this->mtx_name;
39+
#endif
40+
41+
this->mtx_desc = ::CreateMutex(nullptr, false, mutex_name.c_str() );
2842

2943
if (nullptr == this->mtx_desc)
3044
{
@@ -39,19 +53,29 @@ namespace HttpServer
3953
}
4054

4155
this->mtx_desc = sem;
56+
this->mtx_name = mutexName;
4257
#else
4358
#error "Undefine platform"
4459
#endif
4560

46-
this->mtx_name = mutexName;
47-
4861
return true;
4962
}
5063

5164
bool GlobalMutex::destory(const std::string &mutexName)
5265
{
5366
#ifdef WIN32
54-
return true;
67+
const std::string mtx_name = "mtx-" + mutexName;
68+
69+
#ifdef UNICODE
70+
std::wstring_convert<std::codecvt_utf8_utf16<wchar_t> > converter;
71+
const std::wstring mutex_name = converter.from_bytes(mtx_name);
72+
#else
73+
const std::string &mutex_name = mtx_name;
74+
#endif
75+
76+
::HANDLE hMutex = ::OpenMutex(DELETE, true, mutex_name.c_str() );
77+
78+
return 0 != ::CloseHandle(hMutex);
5579
#elif POSIX
5680
return 0 == ::sem_unlink(mutexName.c_str() );
5781
#else
@@ -62,7 +86,16 @@ namespace HttpServer
6286
bool GlobalMutex::destory()
6387
{
6488
#ifdef WIN32
65-
const bool ret = ::CloseHandle(this->mtx_desc);
89+
#ifdef UNICODE
90+
std::wstring_convert<std::codecvt_utf8_utf16<wchar_t> > converter;
91+
const std::wstring mutex_name = converter.from_bytes(this->mtx_name);
92+
#else
93+
const std::string &mutex_name = this->mtx_name;
94+
#endif
95+
96+
::HANDLE hMutex = ::OpenMutex(DELETE, true, mutex_name.c_str() );
97+
98+
const bool ret = (0 != ::CloseHandle(hMutex) );
6699

67100
this->close();
68101

@@ -83,7 +116,17 @@ namespace HttpServer
83116
this->close();
84117

85118
#ifdef WIN32
86-
this->mtx_desc = ::OpenMutex(SYNCHRONIZE, false, mutexName.c_str() );
119+
120+
this->mtx_name = "mtx-" + mutexName;
121+
122+
#ifdef UNICODE
123+
std::wstring_convert<std::codecvt_utf8_utf16<wchar_t> > converter;
124+
const std::wstring mutex_name = converter.from_bytes(this->mtx_name);
125+
#else
126+
const std::string &mutex_name = this->mtx_name;
127+
#endif
128+
129+
this->mtx_desc = ::OpenMutex(SYNCHRONIZE, false, mutex_name.c_str() );
87130

88131
if (nullptr == this->mtx_desc)
89132
{
@@ -165,7 +208,7 @@ namespace HttpServer
165208
bool GlobalMutex::unlock() const
166209
{
167210
#ifdef WIN32
168-
return ::ReleaseMutex(this->mtx_desc);
211+
return 0 != ::ReleaseMutex(this->mtx_desc);
169212
#elif POSIX
170213
return 0 == ::sem_post(this->mtx_desc);
171214
#else

src/Module.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ namespace HttpServer
7171
}
7272

7373
#ifdef UNICODE
74-
std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>> converter;
74+
std::wstring_convert<std::codecvt_utf8_utf16<wchar_t> > converter;
7575
const std::wstring lib_path = converter.from_bytes(libPath);
7676
#else
7777
const std::string &lib_path = libPath;

src/SharedMemory.cpp

Lines changed: 55 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33

44
#ifdef WIN32
55
#include <Windows.h>
6+
7+
#ifdef UNICODE
8+
#include <codecvt>
9+
#endif
610
#elif POSIX
711
#include <unistd.h>
812
#include <sys/mman.h>
@@ -35,13 +39,22 @@ namespace HttpServer
3539

3640
#ifdef WIN32
3741

42+
this->shm_name = "shm-" + memName;
43+
44+
#ifdef UNICODE
45+
std::wstring_convert<std::codecvt_utf8_utf16<wchar_t> > converter;
46+
const std::wstring memory_name = converter.from_bytes(this->shm_name);
47+
#else
48+
const std::string &memory_name = this->shm_name;
49+
#endif
50+
3851
this->shm_desc = ::CreateFileMapping(
3952
INVALID_HANDLE_VALUE,
4053
nullptr,
4154
PAGE_READWRITE,
4255
0,
43-
memSize,
44-
memName.c_str()
56+
static_cast<::DWORD>(memSize),
57+
memory_name.c_str()
4558
);
4659

4760
if (nullptr == this->shm_desc)
@@ -65,12 +78,12 @@ namespace HttpServer
6578
return false;
6679
}
6780

81+
this->shm_name = memName;
82+
6883
#else
6984
#error "Undefine platform"
7085
#endif
7186

72-
this->shm_name = memName;
73-
7487
return true;
7588
}
7689

@@ -80,13 +93,24 @@ namespace HttpServer
8093

8194
#ifdef WIN32
8295

83-
this->shm_desc = ::OpenFileMapping(FILE_MAP_ALL_ACCESS, false, memName.c_str() );
96+
this->shm_name = "shm-" + memName;
97+
98+
#ifdef UNICODE
99+
std::wstring_convert<std::codecvt_utf8_utf16<wchar_t> > converter;
100+
const std::wstring memory_name = converter.from_bytes(this->shm_name);
101+
#else
102+
const std::string &memory_name = this->shm_name;
103+
#endif
104+
105+
this->shm_desc = ::OpenFileMapping(FILE_MAP_ALL_ACCESS, false, memory_name.c_str() );
84106

85107
if (nullptr == this->shm_desc)
86108
{
87109
return false;
88110
}
89111

112+
this->shm_name = memName;
113+
90114
#elif POSIX
91115

92116
this->shm_desc = ::shm_open(memName.c_str(), O_RDWR, 0666);
@@ -96,12 +120,12 @@ namespace HttpServer
96120
return false;
97121
}
98122

123+
this->shm_name = memName;
124+
99125
#else
100126
#error "Undefine platform"
101127
#endif
102128

103-
this->shm_name = memName;
104-
105129
return true;
106130
}
107131

@@ -120,7 +144,7 @@ namespace HttpServer
120144
{
121145
#ifdef WIN32
122146

123-
void * const addr = ::MapViewOfFile(this->shm_desc, FILE_MAP_WRITE, 0, offset, size);
147+
void * const addr = ::MapViewOfFile(this->shm_desc, FILE_MAP_WRITE, 0, static_cast<::DWORD>(offset), size);
124148

125149
if (nullptr == addr)
126150
{
@@ -155,7 +179,7 @@ namespace HttpServer
155179
{
156180
#ifdef WIN32
157181

158-
void * const addr = ::MapViewOfFile(this->shm_desc, FILE_MAP_READ, 0, offset, size);
182+
void * const addr = ::MapViewOfFile(this->shm_desc, FILE_MAP_READ, 0, static_cast<::DWORD>(offset), size);
159183

160184
if (nullptr == addr)
161185
{
@@ -211,7 +235,16 @@ namespace HttpServer
211235
bool SharedMemory::destroy()
212236
{
213237
#ifdef WIN32
214-
bool ret = ::CloseHandle(this->shm_desc);
238+
#ifdef UNICODE
239+
std::wstring_convert<std::codecvt_utf8_utf16<wchar_t> > converter;
240+
const std::wstring memory_name = converter.from_bytes(this->shm_name);
241+
#else
242+
const std::string &memory_name = this->shm_name;
243+
#endif
244+
245+
::HANDLE hMemory = ::OpenFileMapping(DELETE, false, memory_name.c_str() );
246+
247+
const bool ret = (0 != ::CloseHandle(hMemory) );
215248

216249
this->close();
217250

@@ -230,7 +263,18 @@ namespace HttpServer
230263
bool SharedMemory::destroy(const std::string &memName)
231264
{
232265
#ifdef WIN32
233-
return ::CloseHandle(this->shm_desc);
266+
const std::string shm_name = "shm-" + memName;
267+
268+
#ifdef UNICODE
269+
std::wstring_convert<std::codecvt_utf8_utf16<wchar_t> > converter;
270+
const std::wstring memory_name = converter.from_bytes(shm_name);
271+
#else
272+
const std::string &memory_name = shm_name;
273+
#endif
274+
275+
::HANDLE hMemory = ::OpenFileMapping(DELETE, false, memory_name.c_str() );
276+
277+
return 0 != ::CloseHandle(hMemory);
234278
#elif POSIX
235279
return 0 == ::shm_unlink(memName.c_str() );
236280
#else

0 commit comments

Comments
 (0)