tracy/common/TracySocket.hpp

58 lines
1.1 KiB
C++
Raw Normal View History

2017-09-11 20:51:11 +00:00
#ifndef __TRACYSOCKET_HPP__
#define __TRACYSOCKET_HPP__
#include <functional>
2017-09-12 23:53:47 +00:00
struct timeval;
2017-09-11 20:51:11 +00:00
namespace tracy
{
class Socket
{
public:
Socket();
Socket( int sock );
~Socket();
bool Connect( const char* addr, const char* port );
void Close();
int Send( const void* buf, int len );
2017-09-12 23:53:47 +00:00
int Recv( void* buf, int len, const timeval* tv );
2017-09-11 20:51:11 +00:00
2018-03-30 23:06:35 +00:00
bool Read( void* buf, int len, const timeval* tv, std::function<bool()> exitCb );
bool HasData();
2017-09-13 00:08:30 +00:00
2017-09-11 20:51:11 +00:00
Socket( const Socket& ) = delete;
Socket( Socket&& ) = delete;
Socket& operator=( const Socket& ) = delete;
Socket& operator=( Socket&& ) = delete;
private:
int m_sock;
};
class ListenSocket
{
public:
ListenSocket();
~ListenSocket();
bool Listen( const char* port, int backlog );
2017-10-18 17:49:17 +00:00
Socket* Accept();
2017-09-11 20:51:11 +00:00
void Close();
ListenSocket( const ListenSocket& ) = delete;
ListenSocket( ListenSocket&& ) = delete;
ListenSocket& operator=( const ListenSocket& ) = delete;
ListenSocket& operator=( ListenSocket&& ) = delete;
private:
int m_sock;
};
}
#endif