Skip to content

Commit 4b3ee40

Browse files
committed
Fixed code (and style) for Windows.
1 parent b04b1a7 commit 4b3ee40

File tree

12 files changed

+179
-85
lines changed

12 files changed

+179
-85
lines changed

src/server/config/ConfigParser.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ namespace HttpServer
279279

280280
try {
281281
if (app_init) {
282-
const std::string root = root_dir;
282+
const std::string &root = root_dir;
283283
success = app_init(root.data() );
284284
}
285285
}
@@ -356,8 +356,8 @@ namespace HttpServer
356356
if (names.empty() ) {
357357
apps_tree.addApplication(app_name, settings);
358358
} else {
359-
for (size_t i = 0; i < names.size(); ++i) {
360-
apps_tree.addApplication(names[i], settings);
359+
for (auto const &name : names) {
360+
apps_tree.addApplication(name, settings);
361361
}
362362
}
363363

src/server/data-variant/FormUrlencoded.cpp

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
1+
22
#include "FormUrlencoded.h"
33

44
#include "../../utils/Utils.h"
@@ -20,7 +20,7 @@ namespace DataVariant
2020
std::string::npos != var_end;
2121
var_pos = var_end + 1
2222
) {
23-
// Поиск следующего параметра
23+
// Search next parameter
2424
var_end = buf.find('&', var_pos);
2525

2626
if (std::string::npos == var_end) {
@@ -30,12 +30,11 @@ namespace DataVariant
3030
}
3131
}
3232

33-
// Поиск значения параметра
33+
// Search parameter value
3434
size_t delimiter = buf.find('=', var_pos);
3535

36-
if (delimiter >= var_end)
37-
{
38-
// Получить имя параметра
36+
if (delimiter >= var_end) {
37+
// Get parameter name
3938
std::string var_name = Utils::urlDecode(
4039
buf.substr(
4140
var_pos,
@@ -45,15 +44,13 @@ namespace DataVariant
4544
)
4645
);
4746

48-
// Сохранить параметр с пустым значением
47+
// Store parameter with empty value
4948
rd->incoming_data.emplace(
5049
std::move(var_name),
5150
std::string()
5251
);
53-
}
54-
else
55-
{
56-
// Получить имя параметра
52+
} else {
53+
// Get parameter name
5754
std::string var_name = Utils::urlDecode(
5855
buf.substr(
5956
var_pos,
@@ -63,7 +60,7 @@ namespace DataVariant
6360

6461
++delimiter;
6562

66-
// Получить значение параметра
63+
// Get parameter value
6764
std::string var_value = Utils::urlDecode(
6865
buf.substr(
6966
delimiter,
@@ -73,7 +70,7 @@ namespace DataVariant
7370
)
7471
);
7572

76-
// Сохранить параметр и значение
73+
// Store parameter and value
7774
rd->incoming_data.emplace(
7875
std::move(var_name),
7976
std::move(var_value)

src/server/protocol/ServerHttp2Protocol.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,8 @@ namespace HttpServer
2525
}
2626

2727
std::random_device rd;
28-
std::uniform_int_distribution<uint8_t> dist;
2928

30-
uint8_t padding = dist(rd);
29+
uint8_t padding = uint8_t(rd());
3130

3231
while (dataSize <= padding) {
3332
padding /= 2;
@@ -177,7 +176,7 @@ namespace HttpServer
177176
}
178177

179178
data += data_size;
180-
send_size += data_size;
179+
send_size += long(data_size);
181180
dt->send_total += data_size;
182181
// stream->window_size_out -= frame_size;
183182

src/server/protocol/extensions/Sendfile.cpp

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,9 @@ namespace HttpServer
100100

101101
*resultRangeHeader += std::to_string(range_begin) + '-' + std::to_string(range_end) + ',';
102102

103-
ranges.emplace_back(std::tuple<size_t, size_t> {range_begin, length});
103+
ranges.emplace_back(std::tuple<size_t, size_t> {
104+
range_begin, length
105+
});
104106
}
105107
}
106108
else // if range_end_str empty
@@ -275,7 +277,12 @@ namespace HttpServer
275277

276278
send_size_left -= send_size;
277279
}
278-
while (false == file.eof() && false == file.fail() && send_size > 0 && send_size_left);
280+
while (
281+
false == file.eof() &&
282+
false == file.fail() &&
283+
send_size > 0 &&
284+
send_size_left
285+
);
279286
}
280287
}
281288

@@ -407,7 +414,12 @@ namespace HttpServer
407414
&dt
408415
);
409416
}
410-
while (false == file.eof() && false == file.fail() && send_size > 0 && (dt.full_size - dt.send_total) );
417+
while (
418+
false == file.eof() &&
419+
false == file.fail() &&
420+
send_size > 0 &&
421+
(dt.full_size - dt.send_total)
422+
);
411423
}
412424

413425
file.close();

src/socket/AdapterTls.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,10 @@ namespace Socket
9797
return send_size;
9898
}
9999

100-
total += send_size;
100+
total += long(send_size);
101101
}
102102

103-
return static_cast<long>(total);
103+
return long(total);
104104
}
105105

106106
System::native_socket_type AdapterTls::get_handle() const noexcept {

src/socket/List.cpp

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
1+
22
#include "List.h"
33

44
#ifdef POSIX
@@ -271,17 +271,15 @@ namespace Socket
271271
return false;
272272
}
273273

274-
for (size_t i = 0; i < this->poll_events.size(); ++i)
274+
for (auto const &event : this->poll_events)
275275
{
276-
const WSAPOLLFD &event = this->poll_events[i];
277-
278276
if (event.revents & POLLRDNORM)
279277
{
280278
System::native_socket_type client_socket = ~0;
281279

282280
do {
283281
::sockaddr_in client_addr {};
284-
socklen_t client_addr_len = sizeof(client_addr);
282+
::socklen_t client_addr_len = sizeof(client_addr);
285283

286284
client_socket = ::accept(
287285
event.fd,
@@ -367,10 +365,8 @@ namespace Socket
367365
return false;
368366
}
369367

370-
for (size_t i = 0; i < this->poll_events.size(); ++i)
368+
for (auto const &event : this->poll_events)
371369
{
372-
const WSAPOLLFD &event = this->poll_events[i];
373-
374370
if (event.revents & POLLRDNORM) {
375371
sockets.emplace_back(Socket(event.fd) );
376372
}

src/socket/Socket.cpp

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ namespace Socket
188188
0
189189
};
190190

191-
if (1 == ::WSAPoll(&event, 1, static_cast<::INT>(timeout.count() ) ) && event.revents & POLLRDNORM) {
191+
if (1 == ::WSAPoll(&event, 1, int(timeout.count()) ) && event.revents & POLLRDNORM) {
192192
client_socket = ::accept(
193193
this->socket_handle,
194194
static_cast<sockaddr *>(nullptr),
@@ -235,7 +235,12 @@ namespace Socket
235235
{
236236
#ifdef WIN32
237237
unsigned long value = isNonBlock;
238-
return 0 == ::ioctlsocket(this->socket_handle, FIONBIO, &value);
238+
239+
return 0 == ::ioctlsocket(
240+
this->socket_handle,
241+
FIONBIO,
242+
&value
243+
);
239244
#elif POSIX
240245
return ~0 != ::fcntl(
241246
this->socket_handle,
@@ -338,7 +343,7 @@ namespace Socket
338343
0
339344
};
340345

341-
if (1 == ::WSAPoll(&event, 1, static_cast<::INT>(timeout.count() ) ) && event.revents & POLLRDNORM) {
346+
if (1 == ::WSAPoll(&event, 1, int(timeout.count()) ) && event.revents & POLLRDNORM) {
342347
recv_len = ::recv(
343348
this->socket_handle,
344349
reinterpret_cast<char *>(buf),
@@ -372,7 +377,7 @@ namespace Socket
372377
0
373378
};
374379

375-
return ::WSAPoll(&event, 1, timeout.count() ) == 1;
380+
return ::WSAPoll(&event, 1, int(timeout.count()) ) == 1;
376381
#elif POSIX
377382
struct ::pollfd event {
378383
this->socket_handle,
@@ -405,7 +410,7 @@ namespace Socket
405410
return send_size;
406411
}
407412

408-
total += static_cast<size_t>(send_size);
413+
total += size_t(send_size);
409414
}
410415

411416
return static_cast<long>(total);
@@ -435,7 +440,7 @@ namespace Socket
435440
};
436441

437442
while (total < length) {
438-
if (1 == ::WSAPoll(&event, 1, static_cast<::INT>(timeout.count() ) ) && event.revents & POLLOUT) {
443+
if (1 == ::WSAPoll(&event, 1, int(timeout.count()) ) && event.revents & POLLOUT) {
439444
const long send_size = ::send(
440445
socket_handle,
441446
reinterpret_cast<const char *>(data) + total,
@@ -447,7 +452,7 @@ namespace Socket
447452
return send_size;
448453
}
449454

450-
total += send_size;
455+
total += size_t(send_size);
451456
} else {
452457
return -1;
453458
}
@@ -473,7 +478,7 @@ namespace Socket
473478
return send_size;
474479
}
475480

476-
total += static_cast<size_t>(send_size);
481+
total += size_t(send_size);
477482
} else {
478483
return -1;
479484
}
@@ -482,7 +487,7 @@ namespace Socket
482487
#error "Undefined platform"
483488
#endif
484489

485-
return static_cast<long>(total);
490+
return long(total);
486491
}
487492

488493
long Socket::nonblock_send(

src/system/GlobalMutex.cpp

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,11 @@ namespace System
3939
const std::string &mutex_name = this->mtx_name;
4040
#endif
4141

42-
this->mtx_desc = ::CreateMutex(nullptr, false, mutex_name.c_str() );
42+
this->mtx_desc = ::CreateMutex(
43+
nullptr,
44+
false,
45+
mutex_name.c_str()
46+
);
4347

4448
if (nullptr == this->mtx_desc) {
4549
return false;
@@ -77,7 +81,11 @@ namespace System
7781
const std::string &mutex_name = mtx_name;
7882
#endif
7983

80-
::HANDLE hMutex = ::OpenMutex(DELETE, true, mutex_name.c_str() );
84+
const ::HANDLE hMutex = ::OpenMutex(
85+
DELETE,
86+
true,
87+
mutex_name.c_str()
88+
);
8189

8290
return 0 != ::CloseHandle(hMutex);
8391
#elif POSIX
@@ -97,9 +105,15 @@ namespace System
97105
const std::string &mutex_name = this->mtx_name;
98106
#endif
99107

100-
::HANDLE hMutex = ::OpenMutex(DELETE, true, mutex_name.c_str() );
108+
const ::HANDLE hMutex = ::OpenMutex(
109+
DELETE,
110+
true,
111+
mutex_name.c_str()
112+
);
101113

102-
const bool ret = (0 != ::CloseHandle(hMutex) );
114+
const bool ret = (
115+
0 != ::CloseHandle(hMutex)
116+
);
103117

104118
this->close();
105119

@@ -132,7 +146,11 @@ namespace System
132146
const std::string &mutex_name = this->mtx_name;
133147
#endif
134148

135-
this->mtx_desc = ::OpenMutex(SYNCHRONIZE, false, mutex_name.c_str() );
149+
this->mtx_desc = ::OpenMutex(
150+
SYNCHRONIZE,
151+
false,
152+
mutex_name.c_str()
153+
);
136154

137155
if (nullptr == this->mtx_desc) {
138156
return false;
@@ -193,7 +211,10 @@ namespace System
193211
bool GlobalMutex::lock() const noexcept
194212
{
195213
#ifdef WIN32
196-
return WAIT_OBJECT_0 == ::WaitForSingleObject(this->mtx_desc, INFINITE);
214+
return WAIT_OBJECT_0 == ::WaitForSingleObject(
215+
this->mtx_desc,
216+
INFINITE
217+
);
197218
#elif POSIX
198219
return 0 == ::sem_wait(this->mtx_desc);
199220
#else
@@ -204,7 +225,10 @@ namespace System
204225
bool GlobalMutex::try_lock() const noexcept
205226
{
206227
#ifdef WIN32
207-
return WAIT_OBJECT_0 == ::WaitForSingleObject(this->mtx_desc, 0);
228+
return WAIT_OBJECT_0 == ::WaitForSingleObject(
229+
this->mtx_desc,
230+
0
231+
);
208232
#elif POSIX
209233
return 0 == ::sem_trywait(this->mtx_desc);
210234
#else

0 commit comments

Comments
 (0)