2017-09-11 20:51:11 +00:00
|
|
|
#ifndef __TRACYSOCKET_HPP__
|
|
|
|
#define __TRACYSOCKET_HPP__
|
|
|
|
|
2018-02-13 13:57:47 +00:00
|
|
|
#include <functional>
|
|
|
|
|
2017-09-12 23:53:47 +00:00
|
|
|
struct timeval;
|
|
|
|
|
2017-09-11 20:51:11 +00:00
|
|
|
namespace tracy
|
|
|
|
{
|
|
|
|
|
2018-08-19 15:45:03 +00:00
|
|
|
#ifdef _MSC_VER
|
|
|
|
void InitWinSock();
|
|
|
|
#endif
|
|
|
|
|
2017-09-11 20:51:11 +00:00
|
|
|
class Socket
|
|
|
|
{
|
2018-07-15 17:34:47 +00:00
|
|
|
enum { BufSize = 128 * 1024 };
|
|
|
|
|
2017-09-11 20:51:11 +00:00
|
|
|
public:
|
|
|
|
Socket();
|
|
|
|
Socket( int sock );
|
|
|
|
~Socket();
|
|
|
|
|
|
|
|
bool Connect( const char* addr, const char* port );
|
|
|
|
void Close();
|
|
|
|
|
|
|
|
int Send( const void* buf, int len );
|
|
|
|
|
2018-03-30 23:06:35 +00:00
|
|
|
bool Read( void* buf, int len, const timeval* tv, std::function<bool()> exitCb );
|
2017-09-13 23:12:27 +00:00
|
|
|
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:
|
2018-07-15 17:34:47 +00:00
|
|
|
int RecvBuffered( void* buf, int len, const timeval* tv );
|
|
|
|
int Recv( void* buf, int len, const timeval* tv );
|
|
|
|
|
2017-09-11 20:51:11 +00:00
|
|
|
int m_sock;
|
2018-07-15 17:34:47 +00:00
|
|
|
|
|
|
|
char* m_buf;
|
|
|
|
char* m_bufPtr;
|
|
|
|
int m_bufLeft;
|
2017-09-11 20:51:11 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
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
|