Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
opendht
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Model registry
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
savoirfairelinux
opendht
Commits
9f493b95
Commit
9f493b95
authored
5 years ago
by
Seva
Browse files
Options
Downloads
Patches
Plain Diff
http: make continious reads non blocking
parent
b98cc78b
No related branches found
No related tags found
No related merge requests found
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
docker/DockerfileDeps
+11
-0
11 additions, 0 deletions
docker/DockerfileDeps
docker/DockerfileDepsLlvm
+10
-3
10 additions, 3 deletions
docker/DockerfileDepsLlvm
include/opendht/http.h
+8
-0
8 additions, 0 deletions
include/opendht/http.h
src/http.cpp
+29
-23
29 additions, 23 deletions
src/http.cpp
with
58 additions
and
26 deletions
docker/DockerfileDeps
+
11
−
0
View file @
9f493b95
...
@@ -43,3 +43,14 @@ RUN wget https://github.com/msgpack/msgpack-c/releases/download/cpp-2.1.5/msgpac
...
@@ -43,3 +43,14 @@ RUN wget https://github.com/msgpack/msgpack-c/releases/download/cpp-2.1.5/msgpac
&& cmake -DMSGPACK_CXX11=ON -DMSGPACK_BUILD_EXAMPLES=OFF -DCMAKE_INSTALL_PREFIX=/usr .. \
&& cmake -DMSGPACK_CXX11=ON -DMSGPACK_BUILD_EXAMPLES=OFF -DCMAKE_INSTALL_PREFIX=/usr .. \
&& make -j8 && make install \
&& make -j8 && make install \
&& cd ../.. && rm -rf msgpack-2.1.5 msgpack-2.1.5.tar.gz
&& cd ../.. && rm -rf msgpack-2.1.5 msgpack-2.1.5.tar.gz
RUN git clone https://github.com/binarytrails/opendht.git \
&& cd opendht && git checkout proxy_restinio \
&& mkdir build && cd build \
&& cmake .. -DCMAKE_INSTALL_PREFIX=/usr -DOPENDHT_PYTHON=On -DOPENDHT_LTO=On \
-DOPENDHT_TESTS=ON -DOPENDHT_PROXY_SERVER=ON -DOPENDHT_PROXY_CLIENT=ON \
-DOPENDHT_PROXY_SERVER_IDENTITY=ON -DOPENDHT_DOCUMENTATION=Off \
-DOPENDHT_PUSH_NOTIFICATIONS=ON -DCMAKE_BUILD_TYPE=Debug \
&& make -j8 && make install \
&& ./opendht_unit_tests \
&& cd ../../ && rm -rf opendht
This diff is collapsed.
Click to expand it.
docker/DockerfileDepsLlvm
+
10
−
3
View file @
9f493b95
...
@@ -8,6 +8,8 @@ ENV CC cc
...
@@ -8,6 +8,8 @@ ENV CC cc
ENV CXX c++
ENV CXX c++
#patch for https://github.com/Stiffstream/restinio-conan-example/issues/2
#patch for https://github.com/Stiffstream/restinio-conan-example/issues/2
RUN apt-get update && apt-get install -y \
python3-pip libasio-dev
RUN pip3 install --upgrade cmake
RUN pip3 install --upgrade cmake
#install conan & add restinio remotes
#install conan & add restinio remotes
RUN pip3 install conan && \
RUN pip3 install conan && \
...
@@ -24,10 +26,15 @@ RUN echo "*** Installing RESTinio & dependencies ***" \
...
@@ -24,10 +26,15 @@ RUN echo "*** Installing RESTinio & dependencies ***" \
&& conan install -o restinio:boost_libs=none --build=missing . \
&& conan install -o restinio:boost_libs=none --build=missing . \
&& conan package . -pf /usr/local \
&& conan package . -pf /usr/local \
&& cd ../ && rm -rf restinio*
&& cd ../ && rm -rf restinio*
#installing dependencies
RUN echo "*** Installing asio & fmt dependencies ***" \
&& cp -r ~/.conan/data/asio/*/bincrafters/stable/package/*/include/* /usr/local/include/ \
&& cp -r ~/.conan/data/fmt/*/bincrafters/stable/package/*/lib/* /usr/local/lib/ \
&& cp -r ~/.conan/data/fmt/*/bincrafters/stable/package/*/include/* /usr/local/include/
#build http_parser fork
#build http_parser fork
RUN echo "*** Building http_parser for custom HTTP methods ***" \
RUN echo "*** Building http_parser
dependency
for custom HTTP methods ***" \
&& git clone https://github.com/eao197/http-parser.git \
&& git clone https://github.com/eao197/http-parser.git \
&& cd http-parser && make && make install PREFIX=/usr \
&& cd http-parser && make
-j8
&& make install PREFIX=/usr \
&& cd ../ && rm -rf restinio-conan/
&& cd ../ && rm -rf restinio-conan/
#build msgpack from source
#build msgpack from source
...
...
This diff is collapsed.
Click to expand it.
include/opendht/http.h
+
8
−
0
View file @
9f493b95
...
@@ -42,8 +42,11 @@ public:
...
@@ -42,8 +42,11 @@ public:
void
close
();
void
close
();
private:
private:
friend
class
Client
;
uint16_t
id_
;
uint16_t
id_
;
asio
::
ip
::
tcp
::
socket
socket_
;
asio
::
ip
::
tcp
::
socket
socket_
;
asio
::
streambuf
response_stream_
;
};
};
/**
/**
...
@@ -112,6 +115,11 @@ private:
...
@@ -112,6 +115,11 @@ private:
std
::
shared_ptr
<
http_parser_settings
>
parser_s
=
nullptr
,
std
::
shared_ptr
<
http_parser_settings
>
parser_s
=
nullptr
,
std
::
shared_ptr
<
Connection
>
conn
=
nullptr
);
std
::
shared_ptr
<
Connection
>
conn
=
nullptr
);
void
handle_response
(
const
asio
::
error_code
&
ec
,
std
::
shared_ptr
<
http_parser
>
parser
=
nullptr
,
std
::
shared_ptr
<
http_parser_settings
>
parser_s
=
nullptr
,
std
::
shared_ptr
<
Connection
>
conn
=
nullptr
);
uint16_t
port_
;
uint16_t
port_
;
asio
::
ip
::
address
addr_
;
asio
::
ip
::
address
addr_
;
asio
::
ip
::
tcp
::
resolver
resolver_
;
asio
::
ip
::
tcp
::
resolver
resolver_
;
...
...
This diff is collapsed.
Click to expand it.
src/http.cpp
+
29
−
23
View file @
9f493b95
...
@@ -256,30 +256,36 @@ Client::async_request(std::string request,
...
@@ -256,30 +256,36 @@ Client::async_request(std::string request,
}
}
// read response
// read response
logger_
->
d
(
"[connection:%i] response read"
,
conn
->
id
());
logger_
->
d
(
"[connection:%i] response read"
,
conn
->
id
());
asio
::
streambuf
resp_s
;
asio
::
async_read_until
(
conn
->
socket_
,
conn
->
response_stream_
,
"
\r\n\r\n
"
,
auto
&
socket
=
conn
->
get_socket
();
std
::
bind
(
&
Client
::
handle_response
,
this
,
ec
,
parser
,
parser_s
,
conn
));
asio
::
read_until
(
socket
,
resp_s
,
"
\r\n\r\n
"
);
});
}
while
(
asio
::
read
(
socket
,
resp_s
,
asio
::
transfer_at_least
(
1
),
ec
)){
void
Client
::
handle_response
(
const
asio
::
error_code
&
ec
,
std
::
shared_ptr
<
http_parser
>
parser
,
std
::
shared_ptr
<
http_parser_settings
>
parser_s
,
std
::
shared_ptr
<
Connection
>
conn
){
if
(
ec
&&
ec
!=
asio
::
error
::
eof
){
if
(
logger_
)
logger_
->
e
(
"[connection:%i] error handling response: %s"
,
conn
->
id
(),
ec
.
message
().
c_str
());
}
std
::
ostringstream
str_s
;
std
::
ostringstream
str_s
;
str_s
<<
&
resp_s
;
str_s
<<
&
conn
->
response_stream_
;
// parse the request
// parse the request
http_parser_execute
(
parser
.
get
(),
parser_s
.
get
(),
http_parser_execute
(
parser
.
get
(),
parser_s
.
get
(),
str_s
.
str
().
c_str
(),
str_s
.
str
().
size
());
str_s
.
str
().
c_str
(),
str_s
.
str
().
size
());
// detect parsing errors
// detect parsing errors
if
(
HPE_OK
!=
parser
->
http_errno
&&
HPE_PAUSED
!=
parser
->
http_errno
){
if
(
HPE_OK
!=
parser
->
http_errno
&&
HPE_PAUSED
!=
parser
->
http_errno
){
if
(
logger_
){
auto
err
=
HTTP_PARSER_ERRNO
(
parser
.
get
());
auto
err
=
HTTP_PARSER_ERRNO
(
parser
.
get
());
if
(
logger_
)
logger_
->
e
(
"[connection:%i] error parsing: %s"
,
conn
->
id
(),
http_errno_name
(
err
));
logger_
->
e
(
"[connection:%i] error parsing: %s"
,
conn
->
id
(),
http_errno_name
(
err
));
}
}
}
}
if
(
ec
!=
asio
::
error
::
eof
)
asio
::
async_read
(
conn
->
socket_
,
conn
->
response_stream_
,
asio
::
transfer_at_least
(
1
),
throw
std
::
runtime_error
{
fmt
::
format
(
std
::
bind
(
&
Client
::
handle_response
,
this
,
ec
,
parser
,
parser_s
,
conn
));
"[connection:{}] error parsing: {}"
,
conn
->
id
(),
ec
)};
if
(
logger_
)
logger_
->
d
(
"[connection:%i] request finished"
,
conn
->
id
());
});
}
}
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment