1 #ifndef _FIBERIO_IOSTREAM_HPP_ 2 #define _FIBERIO_IOSTREAM_HPP_ 7 #include <boost/iostreams/concepts.hpp> 8 #include <boost/iostreams/stream_buffer.hpp> 9 #include <boost/iostreams/stream.hpp> 16 public boost::iostreams::device<boost::iostreams::bidirectional>
20 : socket_{
socket }, closed_in_{
false}, closed_out_{
false}
23 std::streamsize
read(
char* s, std::streamsize n) {
24 std::streamsize bytes_read = 0;
25 while(socket_.
is_open() && bytes_read < n) {
26 bytes_read += socket_.
read(s + bytes_read, n - bytes_read);
31 std::streamsize
write(
const char* s, std::streamsize n) {
36 void close(std::ios_base::openmode mode) {
37 if (mode == std::ios_base::out) {
39 }
else if (mode == std::ios_base::in) {
42 if (closed_in_ && closed_out_) {
60 using socket_stream = boost::iostreams::stream<fiberio::detail::socket_device>;
68 boost::iostreams::stream_buffer<fiberio::detail::socket_device>;
void close()
Closes the socket if it's not already closed.
boost::iostreams::stream_buffer< fiberio::detail::socket_device > socket_streambuf
std::basic_streambuf type for reading/writing to a socket
boost::iostreams::stream< fiberio::detail::socket_device > socket_stream
std::basic_iostream type for reading/writing to a socket
Client socket for communicating over a network and opening connections.
std::size_t read(char *buf, std::size_t size)
Reads up to size bytes into buf.
void write(const char *data, std::size_t len)
Writes data from the buffer and returns once the buffer can be freed.
std::streamsize read(char *s, std::streamsize n)
void close(std::ios_base::openmode mode)
bool is_open()
Check if the connection is open.
std::streamsize write(const char *s, std::streamsize n)
socket_device(socket socket)