Skip to content

Commit d824fe7

Browse files
committed
Fixed issue awwit#6
1 parent a3389a3 commit d824fe7

File tree

2 files changed

+19
-13
lines changed

2 files changed

+19
-13
lines changed

src/server/protocol/extensions/Sendfile.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,8 @@ namespace HttpServer
221221
additionalHeaders.emplace_back("last-modified", Utils::getDatetimeAsString(fileTime, true) );
222222

223223
// Отправить заголовки (206 Partial Content)
224-
if (prot.sendHeaders(
224+
if (
225+
prot.sendHeaders(
225226
Http::StatusCode::PARTIAL_CONTENT,
226227
additionalHeaders,
227228
req.timeout,
@@ -377,7 +378,8 @@ namespace HttpServer
377378
additionalHeaders.emplace_back("last-modified", Utils::getDatetimeAsString(file_time, true) );
378379

379380
// Отправить заголовки (200 OK)
380-
if (prot.sendHeaders(
381+
if (
382+
prot.sendHeaders(
381383
Http::StatusCode::OK,
382384
additionalHeaders,
383385
req.timeout,

src/socket/Socket.cpp

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -103,17 +103,21 @@ namespace Socket
103103
}
104104

105105
bool Socket::bind(const int port) const noexcept {
106+
// GCC bug with global namespace: https://bbs.archlinux.org/viewtopic.php?id=53751
107+
auto const net_port = htons(static_cast<uint16_t>(port));
108+
auto const net_addr = ::htonl(INADDR_ANY);
109+
106110
const ::sockaddr_in sock_addr {
107111
AF_INET,
108-
::htons(port),
109-
::htonl(INADDR_ANY),
110-
0
112+
net_port,
113+
{ net_addr },
114+
{ 0 } // sin_zero
111115
};
112116

113117
return 0 == ::bind(
114118
this->socket_handle,
115-
reinterpret_cast<const sockaddr *>(&sock_addr),
116-
sizeof(sockaddr_in)
119+
reinterpret_cast<const ::sockaddr *>(&sock_addr),
120+
sizeof(::sockaddr_in)
117121
);
118122
}
119123

@@ -147,9 +151,9 @@ namespace Socket
147151
#ifdef WIN32
148152
WSAPOLLFD event {
149153
this->socket_handle,
150-
POLLRDNORM,
151-
0
152-
};
154+
POLLRDNORM,
155+
0
156+
};
153157

154158
if (1 == ::WSAPoll(&event, 1, ~0) && event.revents & POLLRDNORM) {
155159
client_socket = ::accept(
@@ -161,9 +165,9 @@ namespace Socket
161165
#elif POSIX
162166
struct ::pollfd event {
163167
this->socket_handle,
164-
POLLIN,
165-
0
166-
};
168+
POLLIN,
169+
0
170+
};
167171

168172
if (1 == ::poll(&event, 1, ~0) && event.revents & POLLIN) {
169173
client_socket = ::accept(

0 commit comments

Comments
 (0)