boost-asio

“An existing connection was forcibly closed by the remote host” when listening for incoming data

跟風遠走 提交于 2019-12-11 12:54:05
问题 When working with boost asio, I've stumbled upon some weird behavior, which I don't quite understand. I wrote a minimal test-program to replicate the problem: #include <boost/asio.hpp> #include <iostream> using boost::asio::ip::udp; int main(int argc,char *argv[]) { boost::asio::io_service ioService; udp::resolver resolver(ioService); udp::resolver::query queryListen("127.0.0.1","50001"); auto epListen = *resolver.resolve(queryListen); udp::socket socket(ioService,epListen); udp::resolver:

boost async_read_until combine match_condition with limit size to read

夙愿已清 提交于 2019-12-11 12:54:02
问题 Is there way to combain two conditions read until a matching character is found or 128 bytes received? It is possible to limit streambuf size: inBuf = std::make_shared< boost::asio::streambuf>(limit_size); But when handler with reason "Element not found" there is no available data in stream and transferred bytes also is 0. The idea is to read until ';' or 128 bytes received My code is following: class match_char { public: explicit match_char(char c, int len) : c_(c), len_(len) {} template

Boost asio ip tcp iostream Error Detection

我们两清 提交于 2019-12-11 12:46:41
问题 Greetings. I'm just getting started with the boost::asio library and have run into some early difficulty related to boost::asio::ip::tcp::iostream. My question has two parts: 1.) How does one connect an iostream using simply host and port number? I can make the client and server [boost.org] examples work fine as coded. The server specifies the port explicitly: boost::asio::io_service io_service; tcp::endpoint endpoint(tcp::v4(), 13); tcp::acceptor acceptor(io_service, endpoint); Port 13 is a

ASIO chat session class throws exception on destruction: C++ ASIO

有些话、适合烂在心里 提交于 2019-12-11 11:52:16
问题 I am working on a Network Application using ASIO and have referred Chat-Server/Client I have asked similar question Here To explain better I am adding more code here: My Cserver Class class CServer { private: mutable tcp::acceptor acceptor_; // only in the listener asio::io_service& io_; CSerSessionsManager mng_; std::string ip_; std::string port_; public: CServer::CServer(asio::io_service& io_service, const std::string IP, const std::string port) : io_(io_service), acceptor_(io_service) , ip

Cross platform C++ High Precision Event Timer implementation

廉价感情. 提交于 2019-12-11 10:37:26
问题 Coming from the Windows platform I usually used the Windows Multimedia Timer to produce periodic callbacks with a resolution of 1 ms +-1ms. So I could indeed produce 1000 quite equidistant callbacks per second. To achieve this accuracy without doing busy-waiting MS used the High Precision Event Timer, which directly accesses a hardware driver. I was hoping to find something like a boost library or so that provides a cross platform implementation for these kind of high precision timers. But

Boost asio: Unable to read URL Body (JSON)

♀尐吖头ヾ 提交于 2019-12-11 10:25:20
问题 I have test the following Boost::Asio minimal HTTP server example: (Minimal HTTP Server based on Boost:Asio) I'm able to successfully collect the Header information such as Content-Length but the example hangs when I try to read the Body information. Here is the function that attempts to read the Body information: static void read_body(std::shared_ptr<session> pThis) { info("read_body"); int nbuffer = pThis->headers.content_length(); std::shared_ptr<std::vector<char>> bufptr = std::make

boost::asio : data corruption

不打扰是莪最后的温柔 提交于 2019-12-11 10:07:55
问题 I present a simple client and server written in Asio to show something that might be a bug. client repeatedly sends a fixed string of length 102 to the server and server checks the string to be correct and writes an error message if not so and exits. The code is compiled and run in debian 7 (amd64) my processor has 2 cores boost version is 1.55 when running server and client, after a few thousand packets are sent a wrong packet is received.(it may be required to repeat the test a few times)

Ensure no new wait is accepted by boost::deadline_timer unless previous wait is expired

♀尐吖头ヾ 提交于 2019-12-11 09:56:10
问题 I am trying to achieve synchronization operation for hardware devices controlled by my C++ code. Suppose Two types of devices are there on which I can perform Open/Close . What I need to achieve is Open one type of device for Specified Duration . Same is true for Second type Of device. I have written code with boost::deadline_timer : #include <boost/date_time/posix_time/posix_time.hpp> #include <boost/thread.hpp> #include <boost/asio.hpp> class Test : public std::enable_shared_from_this <Test

boost::async_write fails after writing for some time

本秂侑毒 提交于 2019-12-11 09:53:42
问题 I am having a very peculiar problem. I have written a server that writes data that it receives from a third party to connected clients. The server writes to the client(s) fine for a while, but after a while, async_write either fails or a write never returns. For my program, if an async_write never returns, then no subsequent writes will take place, and my server will queue up the data it receives from the third party until everything blows up. I have included my code below: void

memory leaks if using boost::asio::io_service::run in separate thread

怎甘沉沦 提交于 2019-12-11 09:47:28
问题 I am trying to connect with a websocket using boost::asio library on win 7 32 bit. Normally, I get two memory leaks related openssl but If I am putting the boost::asio::io_service::run method in a separate thread, I am getting 6 memory leaks, out of which two leaks are of openssl lib. Here is my code sample. #include <boost/asio.hpp> #include <boost/asio/ssl.hpp> #include <boost/array.hpp> #include <boost/thread.hpp> #include <iostream> #include <string> #include <vld.h> boost::asio::io