5
投票
1答案
775 次观看

Boost:我们如何为TCP服务器指定“任何端口”?

如何在Boost中为基于TCP的服务器指定“选择任何可用端口”? 接受连接后,如何检索端口? 已更新:“可用端口”是指:操作系统可以选择任何可用端口,即我不想指定端口。

2
投票
1答案
664 次观看

提升asio udp waitForReadyRead

我正在尝试使用boost asio udpSocket实现一个功能,该功能一直等到准备好读取数据,或者等到超时到期为止。 使用asyc_read和async_wait,我可以做类似的事情,但是我必须读取数据。我想做同样的 而无需读取数据 在许多情况下,这将使udpSocket类的使用更加容易,但是考虑到udpSocket接口,我无法弄清楚如何实现这种功能,而无需手动缓冲数据并重写sync_read函数 最好的Dd

3
投票
2答案
725 次观看

库使用winsock.h的问题

我有一个使用Boost.Asio和Intel IPP库随附的Media-Decoding-Samples的项目。问题如下。如果我在编译项目时未定义WIN32_LEAN_AND_MEAN,则Asio会抱怨臭名昭著的“ winsock.h已包括”错误。如果我定义了宏,则另一个库中的标头具有未定义的类型,因为它依赖于包括winsock.h的windows.h。我尝试将winsock.h手动添加到该标头中,但这使Boost.Asio再次发出声音。我能想到的唯一解决方案是遍历每个编译单元,并确保始终首先包含Asio。由于项目的规模和复杂性(以及该解决方案的丑陋性),我想找到一种更好的方法。 谢谢!

5
投票
1答案
1700 次观看

Boost.Asio文档不存在。这些错误是什么意思?

我在Boost.Asio中遇到两个错误。 第一次发生在我尝试在套接字上接收数据时 char reply[1024]; boost::system::error_code error; size_t reply_length = s.receive(boost::asio::buffer(reply, 1024), 0, error); if (error) cout << error.message() << endl; //outputs "End of file" 当我尝试从(有效!)本机套接字创建ip :: tcp :: socket时发生第二种...

10
投票
1答案
5760 次观看

如何从本机套接字创建Boost.Asio套接字?

我只是想从现有的本地套接字创建一个boost ip::tcp::socket。在分配函数中, 我猜第二个应该是套接字描述符,但是我非常感谢澄清。 void SendData (int socket, std::string message) { boost::asio::io_service ioserv; boost::asio::ip::tcp::socket s(ioserv); s.assign(/* what goes here? */, /* ..and here? */); s.send(boost::asio::buffer(mess...

3
投票
1答案
1169 次观看

boost asio:维护已连接客户端的列表

我正在寻找修改Boost Asio的最佳方法 HTTP Server 3示例,用于维护当前连接的客户端的列表。 如果我将示例中的server.hpp修改为: class server : private boost::noncopyable { public: typedef std::vector< connection_ptr > ConnectionList; // ... ConnectionList::const_iterator GetClientList() const { return connecti...

1
投票
2答案
10095 次观看

Boost Asio async_read不会停止阅读吗?

所以 我一直在玩Boost asio函数和套接字(特别是异步读/写)。现在,我以为boost::asio::async_read仅在从网络连接传入新缓冲区时才调用处理程序...但是,它不会停止读取相同的缓冲区,因此一直在调用处理程序。我已经能够通过检查传输的字节数来缓解这种情况,但是它基本上处于一个繁忙的循环中,浪费了CPU周期。 这就是我所拥有的: class tcp_connection : : public boost::enable_shared_from_this<tcp_connection> { public: // other functio...

0
投票
2答案
939 次观看

有可能用Pimpl包装升压插座吗?

在一个项目中,我们希望以某种方式包装Boost Asio套接字,即using类或包装.h不必包含boost标头。 我们通常对包装好的类使用指针和前向声明。 前向声明: namespace boost { namespace asio { namespace ip { class udp; } } } 然后声明套接字: scoped_ptr<boost::asio::ip::udp::socket> socket_; scoped_ptr<boost::asio::ip::udp::endpoint...

5
投票
1答案
1457 次观看

C++, boost asio, receive null terminated string

How can I retrieve null-terminated string from a socket using the boost::asio library?

7
投票
1答案
4088 次观看

How to resolve host (only) using Boost.Asio?

According to the documentation of boost::asio::ip::tcp::resolver::query in order to resolve host it should receive service as well. What if I want to resolve host without relation to port? How should I do it at all? Should I specify dummy port?

18
投票
4答案
22915 次观看

boost::asio::ip::tcp::socket is connected?

I want to verify the connection status before performing read/write operations. Is there a way to make an isConnect() method? I saw this, but it seems "ugly". I have tested is_open() function as well, but it doesn't have the expected behavior.

31
投票
3答案
41596 次观看

Linking Boost Library in Linux

I am trying to build a project using Boost's Asio and I am having some trouble. Initially, I tried to build the project without any additional libraries since everything is supposedly in the header files. The program I am trying to build looks like this: #include <iostream> #include <...

1
投票
1答案
1194 次观看

getting an error of "Service not found" in a async_resolve handler

I have code that looks like the following: //unrelated code snipped resolver.reset(new tcp::resolver(iosvc)); tcp::resolver::query query(host, port); resolver->async_resolve(query, boost::bind(&TCPTransport::handle_resolve, this, boost::asio::placeholders::error, boost::as...

0
投票
2答案
11846 次观看

Boost Threads and Timers, C++

I have this code for a custom class 'sau_timer': sau_timer::sau_timer(int secs, timerparam f, vector<string> params) : strnd(io), t(io, boost::posix_time::seconds(secs)) { assert(secs > 0); this->f = f; this->params = params; t.async_wait(strnd.wrap(boost::bin...

1
投票
1答案
1700 次观看

Boost.Asio iostream flush not working?

any ideas why stream.flush(); won't work? boost::asio::ip::tcp::iostream stream("localhost","5000"); assert(stream.good()); stream << 1; stream.flush(); while(true); it's only flushed if the loop is removed and the line boost::this_thread::sleep(boost::posix_time::seconds(1)); is exe...

1
投票
3答案
3119 次观看

boost::bind, boost::asio, boost::thread, and classes

sau_timer::sau_timer(int secs, timerparam f) : strnd(io), t(io, boost::posix_time::seconds(secs)) { assert(secs > 0); this->f = f; //t.async_wait(boost::bind(&sau_timer::exec, this, _1)); t.async_wait(strnd.wrap(boost::bind(&sau_timer::exec, this))); boost:...

0
投票
1答案
1474 次观看

boost asio example crashes on mac osx

I am trying to run blocking_udp_echo_server.cpp from Boost asio example on MacOSX 10.5. But it crashes: From the console: /Developer/SDKs/MacOSX10.5.sdk/usr/include/c++/4.0.0/debug/safe_iterator.h:127: error: attempt to copy-construct an iterator from a singular iterator. Objects involved ...

4
投票
1答案
970 次观看

boost.asio, how to read a complete IP packet using asio

I would like to use a function which reads on a socket port, and gives back the control whenever an IP packet is received. the boost::asio::ip::udp::socket has a function receive (or async_receive) that returns how many bytes were read. the doc states: Receive some data on a connected socket. ...

0
投票
1答案
1189 次观看

Boost.Asio synchronous communication

I have a problem using asio. My client/server application requires only synchronous communication. So, using the examples for synchro from the boost homepage, I have set up two procedures to send and receive data. Their code is as follows: void vReceive(tcp::socket & socket, std::string &amp...

3
投票
1答案
504 次观看

Is there an elegant way to bridge two devices/streams in Asio?

Given two stream-oriented I/O objects in Asio, what is the simplest way to forward data from one device to the other in both directions? Could this be done with boost::iostreams::combination or boost::iostreams:copy perhaps? Or is a manual approach better--waiting for data on each end and then wr...

0
投票
3答案
1723 次观看

About write buffer in general network programming

I'm writing server using boost.asio. I have read and write buffer for each connection and use asynchronized read/write function (async_write_some / async_read_some). With read buffer and async_read_some, there's no problem. Just invoking async_read_some function is okay because read buffer is re...

7
投票
2答案
13825 次观看

C++ Using windows named pipes

For some reason both the mast and slave fail, however I could find any good examples on how their meant to work, so im not sure where I went wrong. The master never exits the WaitForSingleObject after ConnectNamedPipe, and the slave throws an exception in the first boost::asio::read call, "Wait...

29
投票
6答案
13134 次观看

C++ Socket Server - Unable to saturate CPU

I've developed a mini HTTP server in C++, using boost::asio, and now I'm load testing it with multiple clients and I've been unable to get close to saturating the CPU. I'm testing on a Amazon EC2 instance, and getting about 50% usage of one cpu, 20% of another, and the remaining two are idle (ac...

8
投票
1答案
3098 次观看

Boost::Asio read/write operations

What is the difference between calling boost::asio::ip::tcp::socket's read_some/write_some member functions and calling the boost::asio::read/boost::asio::write free functions? More specifically: Is there any benefit to using one over the other? Why are both included in the library?

7
投票
2答案
7217 次观看

boost::asio, asynchronous read error

For some reason this results in an access violation, however not having any detailed documentation/help on this I'm not sure where I'm doing it wrong. Since going by what I've seen on the boost site this should be correct, and print the contents of each asio::write call from the client to a new ...

10
投票
2答案
4717 次观看

How should one tear down a boost::asio::ip::udp::socket?

I have read the boost asio reference, gone through the tutorial and looked at some of the examples. Still, I am unable to see how a socket should be torn down: Should I call close() or is this done by the socket's destructor? When should I call shutdown() What are the effects of shutdown()? I...

2
投票
3答案
1886 次观看

C++ mysql and boost asio header conflict

There seems to be a conflict with the windows headers between the mysql c-api and boost::asio. If I include mysql first I get: boost/asio/detail/socket_types.hpp(27) : fatal error C1189: #error : WinSock.h has already been included #if defined(BOOST_WINDOWS) || defined(__CYGWIN__) # if de...

0
投票
1答案
2128 次观看

Boost asio async vs blocking reads, udp speed/quality

I have a quick and dirty proof of concept app that I wrote in C# that reads high data rate multicast UDP packets from the network. For various reasons the full implementation will be written in C++ and I am considering using boost asio. The C# version used a thread to receive the data using blo...

0
投票
2答案
1321 次观看

How should a HTTP server (using sockets) detect that the client is no longer connected and abort processing?

I'm implementing a basic HTTP Server in C++, using boost::asio. As I process each request, I write out the data in chunks, asychronously. If at any point I knew the client was no longer connected, I'd like to abort the processing, e.g. there's no point continuing to build results up to send out...

2
投票
3答案
681 次观看

I have a server listening on sockets, whats a good approach to service CPU-bound requests with multiple threads?

I've got an application, written in C++, that uses boost::asio. It listens for requests on a socket, and for each request does some CPU-bound work (e.g. no disk or network i/o), and then responds with a response. This application will run on a multi-core system, so I plan to have (at least) 1 t...