Porting twisted to C++ using boost::asio
coroutines.
#include <twisted/reactor.hpp>
#include <twisted/basic_protocol.hpp>
struct echo_protocol : twisted::basic_protocol<echo_protocol> {
void on_message(const_buffer_iterator begin, const_buffer_iterator end) {
send_message(begin, end);
}
};
int main() {
twisted::reactor reac;
reac.listen_tcp<echo_protocol>(50000);
reac.run();
}
- [Line Receiver (Delimited String)] (https://github.com/StephanDollberg/twistedcpp/wiki/Tutorials#line-receiver)
- [Byte Receiver (N Bytes)] (https://github.com/StephanDollberg/twistedcpp/wiki/Tutorials#byte-receiver)
- [Mixed Receiver (Line + Byte)] (https://github.com/StephanDollberg/twistedcpp/wiki/Tutorials#mixed-receiver)
- [TCP + SSL Transports] (https://github.com/StephanDollberg/twistedcpp/wiki/Tutorials#transport-types)
- [Deferreds] (https://github.com/StephanDollberg/twistedcpp/wiki/Tutorials#using-deferreds---aka-async-callbacks)
- [Buffer Interface] (https://github.com/StephanDollberg/twistedcpp/wiki/Tutorials#the-buffer-interface---aka-using-the-protocol_core)
Check the [Tutorials] (https://github.com/StephanDollberg/twistedcpp/wiki/Tutorials) for a detailed explanation of everything.
twistedcpp is header only so you don't need to build anything. You can either add include/twisted to your compiler include path(e.g.:
-I/path/to/twisted/include
or put it to /usr/local/include
) or copy the files to your local project. However, twistedcpp depends on boost asio and if the ssl part is used also on openssl. Meaning that you have to link against -lboost_coroutine
, -lboost_context
, -lboost_system
, -lssl
and -lcrypto
.
More work, help and projects very appreciated.