Skip to content

Commit 5037222

Browse files
committed
Are used non blocking sockets
1 parent 472c09d commit 5037222

20 files changed

+263
-68
lines changed

LICENSE

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -631,8 +631,8 @@ to attach them to the start of each source file to most effectively
631631
state the exclusion of warranty; and each file should have at least
632632
the "copyright" line and a pointer to where the full notice is found.
633633

634-
{one line to give the program's name and a brief idea of what it does.}
635-
Copyright (C) {year} {name of author}
634+
HttpServer on C++ for Application (Sites) on C++ created as libraries.
635+
Copyright (C) 2014 Awwit
636636

637637
This program is free software: you can redistribute it and/or modify
638638
it under the terms of the GNU General Public License as published by
@@ -652,7 +652,7 @@ Also add information on how to contact you by electronic and paper mail.
652652
If the program does terminal interaction, make it output a short
653653
notice like this when it starts in an interactive mode:
654654

655-
{project} Copyright (C) {year} {fullname}
655+
HttpServer(C++) Copyright (C) 2014 Ignat Prokopovich
656656
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
657657
This is free software, and you are welcome to redistribute it
658658
under certain conditions; type `show c' for details.
@@ -671,4 +671,4 @@ into proprietary programs. If your program is a subroutine library, you
671671
may consider it more useful to permit linking proprietary applications with
672672
the library. If this is what you want to do, use the GNU Lesser General
673673
Public License instead of this License. But first, please read
674-
<http://www.gnu.org/philosophy/why-not-lgpl.html>.
674+
<http://www.gnu.org/philosophy/why-not-lgpl.html>.

README.md

Lines changed: 0 additions & 7 deletions
This file was deleted.

httpserver.userprefs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
<Properties>
22
<MonoDevelop.Ide.Workspace ActiveConfiguration="Debug" />
3-
<MonoDevelop.Ide.Workbench ActiveDocument="httpserver/DataVariantTextPlain.h">
3+
<MonoDevelop.Ide.Workbench ActiveDocument="httpserver/Utils.cpp">
44
<Files>
5-
<File FileName="httpserver/Server.cpp" Line="1054" Column="20" />
6-
<File FileName="httpserver/Server.h" Line="67" Column="4" />
5+
<File FileName="httpserver/Server.cpp" Line="1" Column="1" />
6+
<File FileName="httpserver/Server.h" Line="1" Column="1" />
77
<File FileName="httpserver/Main.cpp" Line="1" Column="1" />
88
<File FileName="httpserver/Main.h" Line="1" Column="1" />
99
<File FileName="httpserver/DataVariantMultipartFormData.h" Line="1" Column="1" />
@@ -15,27 +15,28 @@
1515
<File FileName="httpserver/ServerResponse.h" Line="1" Column="1" />
1616
<File FileName="httpserver/ServerApplicationAbstract.cpp" Line="1" Column="1" />
1717
<File FileName="httpserver/Event.cpp" Line="1" Column="1" />
18-
<File FileName="httpserver/DataVariantAbstract.h" Line="26" Column="4" />
18+
<File FileName="httpserver/DataVariantAbstract.h" Line="1" Column="1" />
1919
<File FileName="httpserver/DataVariantFormUrlencoded.h" Line="1" Column="1" />
2020
<File FileName="httpserver/DataVariantFormUrlencoded.cpp" Line="1" Column="1" />
2121
<File FileName="httpserver/ServerApplicationSettings.h" Line="1" Column="1" />
2222
<File FileName="httpserver/ServerApplicationsTree.h" Line="1" Column="1" />
2323
<File FileName="httpserver/ServerApplicationsTree.cpp" Line="1" Column="1" />
2424
<File FileName="httpserver/Module.h" Line="1" Column="1" />
2525
<File FileName="httpserver/Event.h" Line="1" Column="1" />
26-
<File FileName="httpserver/System.h" Line="1" Column="1" />
27-
<File FileName="httpserver/DataVariantTextPlain.h" Line="11" Column="3" />
28-
<File FileName="httpserver/DataVariantTextPlain.cpp" Line="6" Column="1" />
26+
<File FileName="httpserver/System.h" Line="13" Column="2" />
27+
<File FileName="httpserver/DataVariantTextPlain.h" Line="1" Column="1" />
28+
<File FileName="httpserver/DataVariantTextPlain.cpp" Line="1" Column="1" />
2929
<File FileName="httpserver/SignalsHandles.cpp" Line="1" Column="1" />
3030
<File FileName="httpserver/SignalsHandles.h" Line="1" Column="1" />
31-
<File FileName="httpserver/System.cpp" Line="1" Column="1" />
31+
<File FileName="httpserver/System.cpp" Line="58" Column="4" />
3232
<File FileName="httpserver/Socket.cpp" Line="1" Column="1" />
3333
<File FileName="httpserver/Utils.h" Line="1" Column="1" />
34-
<File FileName="httpserver/Utils.cpp" Line="1" Column="1" />
34+
<File FileName="httpserver/Utils.cpp" Line="232" Column="4" />
3535
<File FileName="httpserver/Socket.h" Line="1" Column="1" />
3636
<File FileName="httpserver/FileIncoming.h" Line="1" Column="1" />
3737
<File FileName="httpserver/RawData.h" Line="1" Column="1" />
3838
<File FileName="httpserver/FileIncoming.cpp" Line="1" Column="1" />
39+
<File FileName="httpserver/ResourceAbstract.cpp" Line="1" Column="1" />
3940
</Files>
4041
</MonoDevelop.Ide.Workbench>
4142
<MonoDevelop.Ide.DebuggingService.Breakpoints>

httpserver/DataVariantAbstract.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
#include "Socket.h"
44
#include "FileIncoming.h"
55

6-
#include <string>
76
#include <unordered_map>
87

98
namespace HttpServer
@@ -26,7 +25,8 @@ namespace HttpServer
2625
// virtual ~DataVariantAbstract() = 0;
2726

2827
/**
29-
* @param const Socket* - сокет, откуда можно достать остальные данные
28+
* @param const Socket & - сокет, откуда можно достать остальные данные
29+
* @param const std::chrono::milliseconds & - максимальное время ожидания данных (на сокете)
3030
* @param const std::string - первая часть полученных данных
3131
* @param const size_t - сколько осталось данных (в байтах) получить из сокета
3232
* @param const std::unordered_map<std::string, std::string> & - дополнительные параметры, описывающие формат данных
@@ -37,7 +37,8 @@ namespace HttpServer
3737
*/
3838
virtual bool parse
3939
(
40-
const Socket *,
40+
const Socket &,
41+
const std::chrono::milliseconds &,
4142
const std::string,
4243
const size_t,
4344
const std::unordered_map<std::string, std::string> &,

httpserver/DataVariantFormUrlencoded.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ namespace HttpServer
1010

1111
bool DataVariantFormUrlencoded::parse
1212
(
13-
const Socket *sock,
13+
const Socket &sock,
14+
const std::chrono::milliseconds &timeout,
1415
const std::string str,
1516
const size_t leftBytes,
1617
const std::unordered_map<std::string, std::string> &params,
@@ -66,4 +67,4 @@ namespace HttpServer
6667

6768
return false;
6869
}
69-
};
70+
};

httpserver/DataVariantFormUrlencoded.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ namespace HttpServer
1212
public:
1313
virtual bool parse
1414
(
15-
const Socket *,
15+
const Socket &,
16+
const std::chrono::milliseconds &,
1617
const std::string,
1718
const size_t,
1819
const std::unordered_map<std::string, std::string> &,

httpserver/DataVariantMultipartFormData.cpp

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ namespace HttpServer
1313

1414
bool DataVariantMultipartFormData::append
1515
(
16-
const Socket *sock,
16+
const Socket &sock,
17+
const std::chrono::milliseconds &timeout,
1718
std::vector<std::string::value_type> &buf,
1819
std::string &str_buf,
1920
const std::string &data_end,
@@ -29,7 +30,7 @@ namespace HttpServer
2930
}
3031

3132
// Получаем данные из сокета
32-
recv_len = sock->recv(buf);
33+
recv_len = sock.nonblock_recv(buf, timeout);
3334

3435
// Завершаем работу, если ошибка получения данных через сокет
3536
if (0 == recv_len || std::numeric_limits<size_t>::max() == recv_len)
@@ -54,7 +55,8 @@ namespace HttpServer
5455

5556
bool DataVariantMultipartFormData::parse
5657
(
57-
const Socket *sock,
58+
const Socket &sock,
59+
const std::chrono::milliseconds &timeout,
5860
const std::string str,
5961
const size_t leftBytes,
6062
const std::unordered_map<std::string, std::string> &params,
@@ -92,7 +94,7 @@ namespace HttpServer
9294
if (std::string::npos == str_cur)
9395
{
9496
// Получить следующий кусок данных
95-
if (false == append(sock, buf, str_buf, data_end, leftBytes, recv_len, read_len) )
97+
if (false == append(sock, timeout, buf, str_buf, data_end, leftBytes, recv_len, read_len) )
9698
{
9799
return false;
98100
}
@@ -125,7 +127,7 @@ namespace HttpServer
125127
if (std::string::npos == headers_end)
126128
{
127129
// Получить следующий кусок данных
128-
if (false == append(sock, buf, str_buf, data_end, leftBytes, recv_len, read_len) )
130+
if (false == append(sock, timeout, buf, str_buf, data_end, leftBytes, recv_len, read_len) )
129131
{
130132
return false;
131133
}
@@ -282,7 +284,7 @@ namespace HttpServer
282284
str_buf.assign(str_buf.cend() - data_end.length(), str_buf.cend() );
283285

284286
// Получить следующий кусок данных
285-
if (false == append(sock, buf, str_buf, data_end, leftBytes, recv_len, read_len) )
287+
if (false == append(sock, timeout, buf, str_buf, data_end, leftBytes, recv_len, read_len) )
286288
{
287289
return false;
288290
}
@@ -338,7 +340,7 @@ namespace HttpServer
338340
str_buf.assign(str_buf.cend() - data_end.length(), str_buf.cend() );
339341

340342
// Получить следующий кусок данных
341-
if (false == append(sock, buf, str_buf, data_end, leftBytes, recv_len, read_len) )
343+
if (false == append(sock, timeout, buf, str_buf, data_end, leftBytes, recv_len, read_len) )
342344
{
343345
return false;
344346
}
@@ -389,7 +391,7 @@ namespace HttpServer
389391
str_buf.assign(str_buf.cend() - data_end.length(), str_buf.cend() );
390392

391393
// Получить следующий кусок данных
392-
if (false == append(sock, buf, str_buf, data_end, leftBytes, recv_len, read_len) )
394+
if (false == append(sock, timeout, buf, str_buf, data_end, leftBytes, recv_len, read_len) )
393395
{
394396
return false;
395397
}
@@ -410,4 +412,4 @@ namespace HttpServer
410412

411413
return true;
412414
}
413-
};
415+
};

httpserver/DataVariantMultipartFormData.h

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

12-
private:
12+
protected:
1313
bool append
1414
(
15-
const Socket *,
15+
const Socket &,
16+
const std::chrono::milliseconds &,
1617
std::vector<std::string::value_type> &,
1718
std::string &, const std::string &,
1819
const size_t &,
@@ -23,7 +24,8 @@ namespace HttpServer
2324
public:
2425
virtual bool parse
2526
(
26-
const Socket *,
27+
const Socket &,
28+
const std::chrono::milliseconds &,
2729
const std::string,
2830
const size_t,
2931
const std::unordered_map<std::string, std::string> &,

httpserver/DataVariantTextPlain.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ namespace HttpServer
1010

1111
bool DataVariantTextPlain::parse
1212
(
13-
const Socket *sock,
13+
const Socket &sock,
14+
const std::chrono::milliseconds &timeout,
1415
const std::string str,
1516
const size_t leftBytes,
1617
const std::unordered_map<std::string, std::string> &params,
@@ -66,4 +67,4 @@ namespace HttpServer
6667

6768
return false;
6869
}
69-
};
70+
};

httpserver/DataVariantTextPlain.h

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,15 @@ namespace HttpServer
1010
DataVariantTextPlain();
1111

1212
public:
13-
virtual bool parse(const Socket *, const std::string, const size_t, const std::unordered_map<std::string, std::string> &, std::unordered_multimap<std::string, std::string> &, std::unordered_multimap<std::string, FileIncoming> &) override;
13+
virtual bool parse
14+
(
15+
const Socket &,
16+
const std::chrono::milliseconds &,
17+
const std::string,
18+
const size_t,
19+
const std::unordered_map<std::string, std::string> &,
20+
std::unordered_multimap<std::string, std::string> &,
21+
std::unordered_multimap<std::string, FileIncoming> &
22+
) override;
1423
};
1524
};

0 commit comments

Comments
 (0)