Overview
Features
Download
Documentation
Community
Add-Ons & Services

boost::asio::read in terms of POCO

A general discussion forum.

boost::asio::read in terms of POCO

Postby slamguy » 18 Jun 2013, 20:03

I need to receive all data from a socket stream to a buffer but I didn't come across a suitable function in Poco like boost::asio::read. What is the right way to implement boost-like behavior by using POCO?

Just to remind, from boost asio::read spec:

"This function is used to read a certain number of bytes of data from a stream. The call will block until one of the following conditions is true:
The supplied buffers are full. That is, the bytes transferred is equal to the sum of the buffer sizes.
An error occurred.
This operation is implemented in terms of zero or more calls to the stream's read_some function."

Thanks
slamguy
 
Posts: 5
Joined: 18 Jun 2013, 19:53

Re: boost::asio::read in terms of POCO

Postby alex » 19 Jun 2013, 04:25

Code: Select all
StreamSocket ss;
ss.connect(SocketAddress("localhost", 9880));
SocketStream str(ss);
str << "hello";

char buffer[5];
str.read(buffer, sizeof(buffer));
ss.close();


If you are looking for proactor-type asynchronous I/O, Poco does not have it (yet). We have Reactor, though; here is an example.
alex
 
Posts: 1046
Joined: 11 Jul 2006, 16:27
Location: United_States

Re: boost::asio::read in terms of POCO

Postby slamguy » 19 Jun 2013, 16:07

Awesome! Yeah, I see, SocketStream is inherited from std::iostream. As I understand, for input stream only it's enough to use SocketInputStream.

Thank you, Alex!
slamguy
 
Posts: 5
Joined: 18 Jun 2013, 19:53


Return to General Discussion

Who is online

Users browsing this forum: No registered users and 1 guest