15. Brief History
• Architecture: Christopher Alexander 1977/79
• A Place To Wait
• Beck & Cunningham 1987
• GoF Patterns (Gamma et al.) 1994
4
16. Brief History
• Architecture: Christopher Alexander 1977/79
• A Place To Wait
• Beck & Cunningham 1987
• GoF Patterns (Gamma et al.) 1994
• Many more since then
4
23. Misconceptions
• Patterns are invented
• GoF patterns are the only patterns
• More patterns == Better software
• Patterns have no drawbacks
6
24. Misconceptions
• Patterns are invented
• GoF patterns are the only patterns
• More patterns == Better software
• Patterns have no drawbacks
• Singleton is a good pattern
6
32. Two Patterns for Asynchronous I/O
• Reactor
• Notify when I/O is ready
• “Consumer” must perform I/O
8
33. Two Patterns for Asynchronous I/O
• Reactor
• Notify when I/O is ready
• “Consumer” must perform I/O
• Proactor
8
34. Two Patterns for Asynchronous I/O
• Reactor
• Notify when I/O is ready
• “Consumer” must perform I/O
• Proactor
• Notify when I/O is done
• “Consumer” works with data
8
35. Two Patterns for Asynchronous I/O
• Reactor
• Notify when I/O is ready
• “Consumer” must perform I/O
• Proactor
• Notify when I/O is done
• “Consumer” works with data
8
39. Overview
• Created by Christopher Kohlhoff in 2003
• Part of the Boost libraries since 2008
10
40. Overview
• Created by Christopher Kohlhoff in 2003
• Part of the Boost libraries since 2008
• Available on Linux, BSD, macOS, Windows, …
10
41. Overview
• Created by Christopher Kohlhoff in 2003
• Part of the Boost libraries since 2008
• Available on Linux, BSD, macOS, Windows, …
• Based on the Proactor pattern
10
42. Overview
• Created by Christopher Kohlhoff in 2003
• Part of the Boost libraries since 2008
• Available on Linux, BSD, macOS, Windows, …
• Based on the Proactor pattern
• NOT only for asynchronous I/O
10
43. ASIO Hello World
#include <asio.hpp>
#include <chrono>
#include <iostream>
int main() {
auto && service = asio::io_service{};
auto && timer = asio::steady_timer{service};
timer.expires_from_now(std::chrono::seconds{1});
timer.async_wait([](auto error){
std::cout << "timer fired!n";
});
service.run();
}
11
50. It’s almost as simple
• OOTB Support for ICMP, TCP, UDP, IPv4/6, Multicast
14
51. It’s almost as simple
• OOTB Support for ICMP, TCP, UDP, IPv4/6, Multicast
• Includes support for resolving addresses
14
52. It’s almost as simple
• OOTB Support for ICMP, TCP, UDP, IPv4/6, Multicast
• Includes support for resolving addresses
• Also support TLS through OpenSSL
14
53. It’s almost as simple
• OOTB Support for ICMP, TCP, UDP, IPv4/6, Multicast
• Includes support for resolving addresses
• Also support TLS through OpenSSL
• “Byte-based” and “Condition-based”
14
78. Glueing it all together (contd.)
auto const cpus = std::thread::hardware_concurrency();
auto pool = std::vector<std::future<void>>{cpus};
for(auto & future : pool) {
future = std::async(std::launch::async, [&]{
service.run();
});
}
31