Loading [MathJax]/extensions/AssistiveMML.js
+ - 0:00:00
Notes for current slide
Notes for next slide

Networking TS w/Algorithms

1 / 10

Networking TS Workshop

sched

2 / 10

http get request

auto host = "www.boost.org"s;
auto service = "http"s;
auto request = "GET / HTTP/1.0\r\n"
"Host: www.boost.org\r\n"
"Accept: */*\r\n"
"Connection: close\r\n\r\n"s;
auto boostorg = rx_connect(io_context, host, service) |
rxo::concat_map([=](connected c){
return rxs::just(request) |
rx_send(c);
}) |
rxo::concat_map([=](connected c){
return rx_read(c);
}) |
// share chunks
rxo::publish() |
rxo::ref_count();
3 / 10

*

derive results from the shared chunks

break out http headers

auto headers = boostorg |
split("\r\n", Split::RemoveDelimiter) |
rxo::take_while([] (const string& s){
return !s.empty();
});

accumulate count of bytes read

auto size = boostorg |
rxo::scan(0, [] (int total, const string& chunk){
return total + int(chunk.size());
});
4 / 10

combine the data sources

auto responseupdates = boostorg |
rxo::map([](const string&){return "response"s;});
headers.
concat(rxs::just("END HEADERS"s), responseupdates).
with_latest_from(size | rxo::start_with(0)).
5 / 10

combine the data sources

auto responseupdates = boostorg |
rxo::map([](const string&){return "response"s;});
headers.
concat(rxs::just("END HEADERS"s), responseupdates).
with_latest_from(size | rxo::start_with(0)).
subscribe(rxu::apply_to([](const string& s, int size){
cout << s << " : " << size << endl;
}), [](exception_ptr ex){
cerr << rxu::what(ex) << endl;
}, [](){
cout << endl;
});
6 / 10

try it out

$ c++ -std=c++14 -I ../netts/include/ -I rxcpp/Rx/v2/src/ rx.cpp
$ ./a.out
HTTP/1.1 200 OK : 0
Date: Thu, 18 May 2017 14:03:57 GMT : 0
Server: Apache/2.2.15 (CentOS) : 0
Accept-Ranges: bytes : 0
Connection: close : 0
Content-Type: text/html : 0
END HEADERS : 0
response : 8192
response : 12288
response : 16384
response : 20480
response : 24576
response : 28672
response : 32768
response : 36864
close
7 / 10

echo

auto echo = rx_connect(io_context, host, service) |
rxo::concat_map([=](connected c){
return rx_read(c) |
rx_send(c);
}) |
rxo::subscribe<connected>();
8 / 10

code

The code was a 1day minimal solution. more work is needed to build a fully general adaption.

https://github.com/kirkshoop/networkingts

9 / 10

see more of these algorithms

No raw std::thread! - Live Tweet Analysis in C++

  • friday

  • 2:30pm

10 / 10

*

Networking TS Workshop

sched

2 / 10
Paused

Help

Keyboard shortcuts

, , Pg Up, k Go to previous slide
, , Pg Dn, Space, j Go to next slide
Home Go to first slide
End Go to last slide
Number + Return Go to specific slide
b / m / f Toggle blackout / mirrored / fullscreen mode
c Clone slideshow
p Toggle presenter mode
t Restart the presentation timer
?, h Toggle this help
Esc Back to slideshow