Skip to content

Commit 141a46e

Browse files
committed
Minor fixes awwit#2
1 parent a976f7a commit 141a46e

21 files changed

+198
-191
lines changed

projects/qt-creator/httpserver.pro

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,11 @@ SOURCES += \
3636
../../src/RequestParameters.cpp \
3737
../../src/Server.cpp \
3838
../../src/ServerApplicationsTree.cpp \
39-
../../src/SignalsHandles.cpp \
4039
../../src/Socket.cpp \
4140
../../src/SocketList.cpp \
4241
../../src/System.cpp \
43-
../../src/Utils.cpp
42+
../../src/Utils.cpp \
43+
../../src/SignalHandlers.cpp
4444

4545
include(deployment.pri)
4646
qtcAddDeployment()
@@ -63,8 +63,8 @@ HEADERS += \
6363
../../src/ServerApplicationsTree.h \
6464
../../src/ServerRequest.h \
6565
../../src/ServerResponse.h \
66-
../../src/SignalsHandles.h \
6766
../../src/Socket.h \
6867
../../src/SocketList.h \
6968
../../src/System.h \
70-
../../src/Utils.h
69+
../../src/Utils.h \
70+
../../src/SignalHandlers.h

projects/qt-creator/httpserver.pro.user

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<!DOCTYPE QtCreatorProject>
3-
<!-- Written by QtCreator 3.5.1, 2016-01-09T00:56:47. -->
3+
<!-- Written by QtCreator 3.5.1, 2016-01-10T19:07:47. -->
44
<qtcreator>
55
<data>
66
<variable>EnvironmentId</variable>
@@ -61,7 +61,7 @@
6161
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Desktop</value>
6262
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Desktop</value>
6363
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">{c77ee4a2-1c2a-4bac-9185-8378ec4ebf5d}</value>
64-
<value type="int" key="ProjectExplorer.Target.ActiveBuildConfiguration">0</value>
64+
<value type="int" key="ProjectExplorer.Target.ActiveBuildConfiguration">1</value>
6565
<value type="int" key="ProjectExplorer.Target.ActiveDeployConfiguration">0</value>
6666
<value type="int" key="ProjectExplorer.Target.ActiveRunConfiguration">0</value>
6767
<valuemap type="QVariantMap" key="ProjectExplorer.Target.BuildConfiguration.0">

src/ConfigParser.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,16 @@ namespace HttpServer
1212
class ConfigParser
1313
{
1414
private:
15-
bool includeConfigFile(const std::string &fileName, std::string &strBuf, const size_t offset = 0);
15+
static bool includeConfigFile(const std::string &fileName, std::string &strBuf, const size_t offset = 0);
1616

17-
bool addApplication(
17+
static bool addApplication(
1818
const std::unordered_map<std::string, std::string> &app,
1919
const ServerApplicationDefaultSettings &defaults,
2020
std::vector<Module> &modules,
2121
ServerApplicationsTree &apps_tree
2222
);
2323

24-
bool parseMimes(const std::string &fileName, std::unordered_map<std::string, std::string> &mimes_types);
24+
static bool parseMimes(const std::string &fileName, std::unordered_map<std::string, std::string> &mimes_types);
2525

2626
public:
2727
bool loadConfig(

src/DataVariantAbstract.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,7 @@ namespace HttpServer
1111
std::string data_variant_name;
1212

1313
public:
14-
inline std::string getName() const
15-
{
16-
return data_variant_name;
17-
};
14+
inline std::string getName() const { return data_variant_name; }
1815

1916
public:
2017
/**

src/DataVariantMultipartFormData.cpp

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@ namespace HttpServer
2020
const std::string &data_end,
2121
const size_t &leftBytes,
2222
size_t &recv_len,
23-
size_t &read_len
24-
) const
23+
size_t &recv_total_len
24+
)
2525
{
2626
// Завершаем работу, если уже получено байт сколько нужно
27-
if (read_len >= leftBytes)
27+
if (recv_total_len >= leftBytes)
2828
{
2929
return false;
3030
}
@@ -39,7 +39,7 @@ namespace HttpServer
3939
}
4040

4141
// Обновляем общее количество полученных данных
42-
read_len += recv_len;
42+
recv_total_len += recv_len;
4343

4444
// Добавляем полученные данные к рабочему буферу
4545
str_buf.append(buf.cbegin(), buf.cbegin() + recv_len);
@@ -63,7 +63,7 @@ namespace HttpServer
6363
)
6464
{
6565
// Проверить есть ли в параметрах разделитель блоков данных
66-
auto it = contentParams.find("boundary");
66+
auto const it = contentParams.find("boundary");
6767

6868
if (contentParams.cend() == it)
6969
{
@@ -88,18 +88,17 @@ namespace HttpServer
8888
// Создание буферов
8989
std::vector<char> buf(buf_len);
9090

91-
size_t str_cur; // Текущая позиция в буфере
92-
9391
size_t recv_len; // Прочитано байт при последнем извлечении данных из сокета
94-
size_t read_len = 0; // Прочитано байт из сокета всего
92+
size_t recv_total_len = 0; // Получено байт из сокета всего
9593

9694
// Поиск разделителя блока данных
97-
str_cur = str.find(block_delimiter);
95+
// str_cur — текущая позиция в буфере
96+
size_t str_cur = str.find(block_delimiter);
9897

9998
if (std::string::npos == str_cur)
10099
{
101100
// Получить следующий кусок данных
102-
if (false == append(sock, rp.timeout, buf, str, data_end, leftBytes, recv_len, read_len) )
101+
if (false == append(sock, rp.timeout, buf, str, data_end, leftBytes, recv_len, recv_total_len) )
103102
{
104103
return false;
105104
}
@@ -132,7 +131,7 @@ namespace HttpServer
132131
if (std::string::npos == headers_end)
133132
{
134133
// Получить следующий кусок данных
135-
if (false == append(sock, rp.timeout, buf, str, data_end, leftBytes, recv_len, read_len) )
134+
if (false == append(sock, rp.timeout, buf, str, data_end, leftBytes, recv_len, recv_total_len) )
136135
{
137136
return false;
138137
}
@@ -251,17 +250,17 @@ namespace HttpServer
251250
}
252251

253252
// Поиск имени блока данных
254-
auto it_name = header_params.find("name");
253+
auto const it_name = header_params.find("name");
255254

256255
if (header_params.cend() != it_name)
257256
{
258257
// Если данные пришли из файла
259-
auto it_filename = header_params.find("filename");
258+
auto const it_filename = header_params.find("filename");
260259

261260
if (header_params.cend() != it_filename)
262261
{
263262
// Найти тип файла
264-
auto it_filetype = headers.find("Content-Type");
263+
auto const it_filetype = headers.find("Content-Type");
265264

266265
if (headers.cend() != it_filetype)
267266
{
@@ -291,7 +290,7 @@ namespace HttpServer
291290
str.erase(str.begin(), str.end() - data_end.length() );
292291

293292
// Получить следующий кусок данных
294-
if (false == append(sock, rp.timeout, buf, str, data_end, leftBytes, recv_len, read_len) )
293+
if (false == append(sock, rp.timeout, buf, str, data_end, leftBytes, recv_len, recv_total_len) )
295294
{
296295
return false;
297296
}
@@ -347,7 +346,7 @@ namespace HttpServer
347346
str.erase(str.begin(), str.end() - data_end.length() );
348347

349348
// Получить следующий кусок данных
350-
if (false == append(sock, rp.timeout, buf, str, data_end, leftBytes, recv_len, read_len) )
349+
if (false == append(sock, rp.timeout, buf, str, data_end, leftBytes, recv_len, recv_total_len) )
351350
{
352351
return false;
353352
}
@@ -399,7 +398,7 @@ namespace HttpServer
399398
str.erase(str.begin(), str.end() - data_end.length() );
400399

401400
// Получить следующий кусок данных
402-
if (false == append(sock, rp.timeout, buf, str, data_end, leftBytes, recv_len, read_len) )
401+
if (false == append(sock, rp.timeout, buf, str, data_end, leftBytes, recv_len, recv_total_len) )
403402
{
404403
return false;
405404
}

src/DataVariantMultipartFormData.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ namespace HttpServer
1010
DataVariantMultipartFormData();
1111

1212
protected:
13-
bool append
13+
static bool append
1414
(
1515
const Socket &sock,
1616
const std::chrono::milliseconds &timeout,
@@ -19,8 +19,8 @@ namespace HttpServer
1919
const std::string &data_end,
2020
const size_t &leftBytes,
2121
size_t &recv_len,
22-
size_t &read_len
23-
) const;
22+
size_t &recv_total_len
23+
);
2424

2525
public:
2626
virtual bool parse

src/Event.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace HttpServer
44
{
5-
Event::Event(const bool _signaled, const bool _manualy): signaled(_signaled), manualy(_manualy)
5+
Event::Event(const bool _signaled, const bool _manually): signaled(_signaled), manually(_manually)
66
{
77

88
}
@@ -16,7 +16,7 @@ namespace HttpServer
1616
cv.wait(lck);
1717
}
1818

19-
if (false == manualy)
19+
if (false == manually)
2020
{
2121
signaled = false;
2222
}
@@ -28,7 +28,7 @@ namespace HttpServer
2828

2929
auto const status = cv.wait_for(lck, ms);
3030

31-
if (false == manualy)
31+
if (false == manually)
3232
{
3333
signaled = false;
3434
}
@@ -42,7 +42,7 @@ namespace HttpServer
4242

4343
auto const status = cv.wait_until(lck, tp);
4444

45-
if (false == manualy)
45+
if (false == manually)
4646
{
4747
signaled = false;
4848
}

src/Event.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ namespace HttpServer
1212
std::mutex mtx;
1313
std::condition_variable cv;
1414
std::atomic<bool> signaled;
15-
bool manualy;
15+
bool manually;
1616

1717
public:
1818
Event(const bool _signaled = false, const bool _manualy = false);

src/Main.cpp

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
12
#include "Main.h"
2-
#include "SignalsHandles.h"
3+
#include "Server.h"
4+
#include "SignalHandlers.h"
35

46
#include <iostream>
57

@@ -17,20 +19,17 @@ int main(const int argc, const char *argv[])
1719

1820
if (1 < argc)
1921
{
20-
auto command = commands.find(argv[1]);
22+
auto const command = commands.find(argv[1]);
2123

22-
if (commands.cend() != command)
24+
if (commands.cend() != command)
2325
{
2426
HttpServer::Server server;
2527

26-
if (bindSignalsHandles(&server) )
28+
if (bindSignalHandlers(&server) )
2729
{
2830
exitcode = command->second(&server, argc, argv);
2931

30-
#ifdef WIN32
31-
System::sendSignal(GetCurrentProcessId(), SIGINT);
32-
threadMessageLoop.join();
33-
#endif
32+
stopSignalHandlers();
3433
}
3534
}
3635
else

src/Main.h

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
#pragma once
22

3-
#include "Server.h"
4-
5-
#ifdef WIN32
6-
#include <thread>
7-
std::thread threadMessageLoop;
8-
#endif
3+
/**
4+
* Empty
5+
*/

0 commit comments

Comments
 (0)