boost-asio

Boost Asio type to use for both unix-socket and tcp socket

被刻印的时光 ゝ 提交于 2019-12-03 08:24:40
We have a boost asio based networking code, which connects to a remote side. The local side could be either a tcp4 socket or a unix socket. Is there a typename to use that could hold both of these type of boost sockets? (e.g. something like a base class for both?). Currently our code use boost::asio::generic::stream_protocol::socket for tcp socket, and boost::asio::local::stream_protocol::socket for a unix socket. Actually, there's a dedicated ip::tcp::socket type for tcp sockets. As for generic::stream_protocol::socket , it is the universal stream socket type that accepts socket protocol and

asio service handler for stdin keypress

旧时模样 提交于 2019-12-03 08:22:05
I have adapted step 3 of the Boost asio tutorial to run forever, and display "tick" and "tock" once per second instead of the counter: #include <iostream> #include <boost/asio.hpp> #include <boost/bind.hpp> #include <boost/date_time/posix_time/posix_time.hpp> void print(const boost::system::error_code& /*e*/, boost::asio::deadline_timer* t, int* count) { if( !((*count) % 2) ) std::cout << "tick\n"; else std::cout << "tock\n"; ++(*count); t->expires_at(t->expires_at() + boost::posix_time::seconds(1)); t->async_wait(boost::bind(print, boost::asio::placeholders::error, t, count)); } int main() {

How to design a custom IO object for Boost.Asio

ぐ巨炮叔叔 提交于 2019-12-03 07:57:43
I have an base class (DeviceBase) representing an embedded device, with which I want to communicate. The device can be accessed in various ways, including USB and TCP sockets. Additionally, there is a mock implementation which works on files. Until now, I have only used synchronous read/write calls, and all the implementations are simply classes derived from the base class, overriding the read/write functions. This allows me to use polymorphic pointers and containers to provide implementation-independent access to the device to the application's logic. Now i want to use Boost.Asio to enable

Whether there is a UDT backend for boost::asio?

江枫思渺然 提交于 2019-12-03 07:53:28
Please, tell to me are whether exist UDT protocol backend for boost::asio? UDT is a reliable UDP based application level data transport protocol for distributed data intensive applications over wide area high-speed networks. ( http://udt.sourceforge.net/index.html ) TCP, UDP, and ICMP are supported by Boost.Asio. Other protocols can be implemented by extending the Protocol type requirements . There are several threads on the asio-users mailing list discussing adding support for SCTP, you may be able to use that as an example. This may sound like a shameless plug... But we are currently

TCP Zero copy using boost

假如想象 提交于 2019-12-03 07:46:47
I am trying to implement tcp zero copy using boost but i am not able to find anything on google .My question is it possible to perform zero copy using boost libraries and if so please send me some example or some link. You could watch this BoostCon talk by the Yandex guys: The Optimization of a Boost.Asio-based Networking Server My gut feeling says they (the Yandex guys) overengineered this (quite a bit...). I'd say the essential solution would lie in just using pre-allocated fixed-buffers (perhaps per-thread) and use the MutableBufferSequence concept from Asio to glue them together. This

Create a layer 2 / ethernet socket with boost asio raw socket (in C++)

痴心易碎 提交于 2019-12-03 07:42:18
It is fairly easy to create IP, TCP or UDP sockets using boost::asio library. But when it comes to Ethernet sockets for instance, you need to implement boost/asio/basic_raw_socket.hpp As there are no examples of such a thing over the internet and as I spent a long time before finding the answer, I'll put my work-around in here. The most helpful resource I found was: AF_NETLINK (netlink) sockets using boost::asio A raw socket can be opened using the generic::raw_protocol stuff: std::string ifname("eth1"); typedef boost::asio::generic::raw_protocol raw_protocol_t; typedef boost::asio::generic:

using boost sockets, do I need only one io_service?

余生长醉 提交于 2019-12-03 06:23:44
having several connections in several different threads.. I'm basically doing a base class that uses boost/asio.hpp and the tcp stuff there.. now i was reading this: http://www.boost.org/doc/libs/1_44_0/doc/html/boost_asio/tutorial/tutdaytime1.html it says that "All programs that use asio need to have at least one io_service object." so should my base class has a static io_service (which means there will be only 1 for all the program and a all the different threads and connections will use the same io_service object) or make each connection its own io_service? thanks in front! update: OK so

Use streambuf as buffer for boost asio read and write

拟墨画扇 提交于 2019-12-03 06:13:35
I'm using this code for reading socket_.async_read_some(boost::asio::buffer(data_, max_length), boost::bind(&session::handle_read, this, boost::asio::placeholders::error, boost::asio::placeholders::bytes_transferred)); and this for writing boost::asio::async_write(socket_, boost::asio::buffer(data_, bytes_transferred), boost::bind(&session::handle_write, this, boost::asio::placeholders::error)); where socket_ is socket, max_length is enum with value 1024 and data_ is char array with length of max_length. But I want to replace char array buffer with streambuf. I've tried boost::asio::streambuf

Boost Asio and Web Sockets?

折月煮酒 提交于 2019-12-03 06:04:49
问题 Does anyone know of any attempt to implement the Web Sockets API using Boost asio? 回答1: Wt implemented WebSockets on top of boost::asio. 回答2: I realize this is an old thread, but wanted to update to help those looking for an answer: WebSocket++ fits the bill perfectly. Wt is an entire framework and may be more than many people want. 回答3: Beast is another project, demonstrated at CppCon 2016 and used in rippled, an open source server application that implements a decentralized cryptocurrency

boost::asio::spawn yield as callback

夙愿已清 提交于 2019-12-03 06:01:44
问题 I'm trying to rewrite a project using boost::asio::spawn coroutines. Some parts of the project cannot be changed. For example, the storage protocol library is also written with boost::asio , but without coroutines. The problem is how to convert yield_context into a normal callback (a boost::function object or a classical functor). This is what we have in the storage library API: void async_request_data(uint64_t item_id, boost::function< void(Request_result *) > callback); As we know from