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

68 lines
1.5 KiB
C++
Raw Normal View History

2014-06-25 22:34:04 +00:00
#pragma once
#include <fc/utility.hpp>
#include <fc/fwd.hpp>
#include <fc/io/iostream.hpp>
#include <fc/time.hpp>
2014-06-26 15:25:07 +00:00
#include <fc/noncopyable.hpp>
2014-06-25 22:34:04 +00:00
namespace fc {
namespace ip { class endpoint; }
2014-06-26 15:25:07 +00:00
class udt_socket : public virtual iostream, public noncopyable
2014-06-25 22:34:04 +00:00
{
public:
udt_socket();
~udt_socket();
2014-06-26 15:25:07 +00:00
void bind( const fc::ip::endpoint& local_endpoint );
void connect_to( const fc::ip::endpoint& remote_endpoint );
2014-06-25 22:34:04 +00:00
fc::ip::endpoint remote_endpoint() const;
fc::ip::endpoint local_endpoint() const;
void get( char& c )
{
read( &c, 1 );
}
/// istream interface
/// @{
virtual size_t readsome( char* buffer, size_t max );
virtual bool eof()const;
/// @}
/// ostream interface
/// @{
virtual size_t writesome( const char* buffer, size_t len );
virtual void flush();
virtual void close();
/// @}
void open();
bool is_open()const;
private:
friend class udt_server;
int _udt_socket_id;
};
typedef std::shared_ptr<udt_socket> udt_socket_ptr;
2014-06-26 15:25:07 +00:00
class udt_server : public noncopyable
{
public:
udt_server();
~udt_server();
void close();
void accept( udt_socket& s );
void listen( const fc::ip::endpoint& ep );
fc::ip::endpoint local_endpoint() const;
private:
int _udt_socket_id;
};
2014-06-25 22:34:04 +00:00
} // fc