asio

SO_RCVTIME and SO_RCVTIMEO not affecting Boost.Asio operations

匿名 (未验证) 提交于 2019-12-03 03:03:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Below is my code boost::asio::io_service io; boost::asio::ip::tcp::acceptor::reuse_address option(true); boost::asio::ip::tcp::acceptor accept(io); boost::asio::ip::tcp::resolver resolver(io); boost::asio::ip::tcp::resolver::query query("0.0.0.0", "8080"); boost::asio::ip::tcp::endpoint endpoint = *resolver.resolve(query); accept.open(endpoint.protocol()); accept.set_option(option); accept.bind(endpoint); accept.listen(30); boost::asio::ip::tcp::socket ps(io); accept.accept(ps); struct timeval tv; tv.tv_sec = 1; tv.tv_usec = 0; //setsockopt

boost::asio::yield_context: unexpected forced_unwind exception

匿名 (未验证) 提交于 2019-12-03 02:56:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I'm tring to write my custom async function for boost::asio as described here . However I'm getting boost::coroutines::detail::forced_unwind exception on line with result.get #include <boost/chrono.hpp> #include <boost/asio.hpp> #include <boost/asio/spawn.hpp> #include <boost/asio/steady_timer.hpp> #include <iostream> namespace asio = ::boost::asio; template <typename Timer, typename Token> auto my_timer (Timer& timer, Token&& token) { typename asio::handler_type<Token, void (::boost::system::error_code const)>::type handler (std::forward

How to get the hostname of an ip address by using asio library?

匿名 (未验证) 提交于 2019-12-03 02:38:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I am trying to get hostname from UDP endpoint. However I do not know whether boost.asio supports IP->hostname conversion. Anyone can answer my question? 回答1: getnameinfo is what you want. getnameinfo((sockaddr*)&addr, sizeof(addr), hostname, sizeof(hostname), NULL, NULL, 0); 回答2: #include<asio.hpp> #include<exception> #include<iostream> int main() { try { asio::io_service io_service; asio::ip::udp::resolver rsv(io_service); for(const auto &ele : rsv.resolve(asio::ip::udp::endpoint(asio::ip::address_v4({192,168,1,163}),0))) { std::cout<<ele

boost::asio::ip::multicast::join_group does not work

匿名 (未验证) 提交于 2019-12-03 02:20:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I tried the example , but it does not work. Apparently it does not set IPPROTO_IP/IP_MULTICAST_IF option. I can only find boost::asio::ip::multicast::outbound_interface for IPPROTO_IP/IP_MULTICAST_IF, I tried but failed. Is there any way to make boost::asio::ip::multicast work without calling c-level setsockopt? boost::asio::ip::udp::endpoint listen_endpoint( listen_address, multicast_port); socket_.open(listen_endpoint.protocol()); socket_.set_option(boost::asio::ip::udp::socket::reuse_address(true)); socket_.bind(listen_endpoint); // Join

Strange exception throw - assign: Operation not permitted

匿名 (未验证) 提交于 2019-12-03 01:54:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I want to do asynchronous read from cin therefore I have a piece of code client.h ... boost::asio::posix::stream_descriptor input; boost::asio::streambuf input_buffer client.cpp Client::Client(int argc, char **argv, boost::asio::io_service &io_service) : tcp_socket(io_service) , udp_socket(io_service) , input(io_service, ::dup(STDIN_FILENO)) { ... read_std_input(); } void Client::read_std_input() { async_read_until(input, input_buffer, '\n', boost::bind(&Client::handle_std_read, this, boost::asio::placeholders::error, boost::asio:

How to use template within template in C++11?

匿名 (未验证) 提交于 2019-12-03 01:48:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I use boost to create a websocket server. Because we need ws and wss, two versions, so I write code like below. But when I build it, said "error C2338: Unknown Socket type in async_teardown." I guess it's becuuse T1 . file 1 iSession.h ''' // // Created by p00451414 on 2019/5/14. // #ifndef ESDK_MSP_ISESSION_H #define ESDK_MSP_ISESSION_H #pragma once #include "stdfax.h" template<typename T> class iSession :public std::enable_shared_from_this <iSession<T>> { public: /*explicit iSession(boost::asio::ip::tcp::socket); explicit iSession(boost:

Strange exception throw - assign: Operation not permitted

匿名 (未验证) 提交于 2019-12-03 01:14:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: I want to do asynchronous read from cin therefore I have a piece of code client.h ... boost :: asio :: posix :: stream_descriptor input ; boost :: asio :: streambuf input_buffer client.cpp Client :: Client ( int argc , char ** argv , boost :: asio :: io_service & io_service ) : tcp_socket ( io_service ) , udp_socket ( io_service ) , input ( io_service , :: dup ( STDIN_FILENO )) { ... read_std_input (); } void Client :: read_std_input () { async_read_until ( input , input_buffer , '\n' , boost :: bind (& Client :: handle_std_read ,

boost::asio::ssl linking errors in Xcode 4

匿名 (未验证) 提交于 2019-12-03 01:06:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have a simple project in Xcode―it doesn't actually do anything yet, just includes boost::asio::ssl : // main.cpp #include <iostream> #include <string> #include <boost/asio.hpp> #include <boost/asio/ssl.hpp> using namespace std ; int main (int argc, const char * argv [] ) { return 0 ; } I have it linked with libssl.dylib and libboost_system.dylib , and get this when building: Undefined symbols for architecture x86_64: "_CONF_modules_unload", referenced from: boost::asio::ssl::detail::openssl_init_base::do_init::~do_init() in main.o "_CRYPTO

boost asio 多线程同步服务器

匿名 (未验证) 提交于 2019-12-03 00:22:01
#include<iostream> #include<stdlib.h> #include<boost\asio.hpp> #include<boost\thread.hpp> using namespace std; using namespace boost::asio; void doing(boost::shared_ptr<ip::tcp::socket> sock); int main(){ typedef boost::shared_ptr<ip::tcp::socket> socket_ptr; io_service service; ip::tcp::endpoint ep(ip::tcp::v4(), 2001); // listen on 2001 ip::tcp::acceptor acc(service, ep); while (true) { socket_ptr sock(new ip::tcp::socket(service)); acc.accept(*sock); boost::function0<void> f = boost::bind(doing,sock); boost::thread t(f); } system("pause"); return 1; } void doing(boost::shared_ptr<ip::tcp:

boost asio 同步TCP客户端

匿名 (未验证) 提交于 2019-12-03 00:22:01
#include<stdio.h> #include<boost\asio.hpp> #include<iostream> #include<stdlib.h> int main() { boost::asio::io_context service; boost::asio::ip::tcp::endpoint ep(boost::asio::ip::address::from_string("127.0.0.1"), 2001); //boost::system::error_code e; boost::asio::ip::tcp::socket sock(service); try{ sock.connect(ep); char datasend[512]; char datarecv[512]; memset(datarecv, '\0', 512); memset(datasend, '\0', 512); strcpy(datasend, "datatttttttt"); sock.send(boost::asio::buffer(datasend)); size_t recvsize = sock.receive(boost::asio::buffer(datarecv)); std::cout << datarecv << std::endl; } catch