peerplays-fc/include/fc/network/tcp_socket.hpp

60 lines
1.2 KiB
C++
Raw Normal View History

2013-01-11 14:12:53 +00:00
#pragma once
2012-09-27 23:48:48 +00:00
#include <fc/utility.hpp>
#include <fc/fwd.hpp>
#include <fc/io/iostream.hpp>
2012-09-27 23:48:48 +00:00
namespace fc {
namespace ip { class endpoint; }
class tcp_socket : public virtual iostream
{
2012-09-27 23:48:48 +00:00
public:
tcp_socket();
~tcp_socket();
void connect_to( const fc::ip::endpoint& e );
2012-09-27 23:48:48 +00:00
/// istream interface
/// @{
virtual size_t readsome( char* buffer, size_t max );
virtual bool eof()const;
/// @}
2012-09-27 23:48:48 +00:00
/// ostream interface
/// @{
virtual size_t writesome( const char* buffer, size_t len );
virtual void flush();
virtual void close();
/// @}
2012-10-22 00:54:52 +00:00
bool is_open()const;
2012-10-10 01:40:29 +00:00
2012-09-27 23:48:48 +00:00
private:
friend class tcp_server;
class impl;
2012-12-03 19:51:31 +00:00
fc::fwd<impl,0x44> my;
2012-09-27 23:48:48 +00:00
};
typedef std::shared_ptr<tcp_socket> tcp_socket_ptr;
2012-09-27 23:48:48 +00:00
class tcp_server
{
2012-09-27 23:48:48 +00:00
public:
tcp_server();
2012-09-27 23:48:48 +00:00
~tcp_server();
2012-10-17 01:48:09 +00:00
void close();
2012-09-27 23:48:48 +00:00
bool accept( tcp_socket& s );
void listen( uint16_t port );
2012-09-27 23:48:48 +00:00
private:
// non copyable
tcp_server( const tcp_server& );
tcp_server& operator=(const tcp_server& s );
2012-09-27 23:48:48 +00:00
class impl;
impl* my;
2012-09-27 23:48:48 +00:00
};
} // namesapce fc