mirror of
https://github.com/debauchee/barrier.git
synced 2024-12-22 10:31:45 +03:00
fe79ac593c
stay off on a socket on linux because a connection clearly doesn't send data as often as possible. will have to implement a UDP socket to reduce overhead and avoid these delays. wanted to do that anyway.
51 lines
1.1 KiB
C++
51 lines
1.1 KiB
C++
#ifndef CUNIXTCPSOCKET_H
|
|
#define CUNIXTCPSOCKET_H
|
|
|
|
#include "CSocket.h"
|
|
#include "CSocketFactory.h"
|
|
|
|
class CUnixTCPSocket : public CSocket {
|
|
public:
|
|
CUnixTCPSocket();
|
|
virtual ~CUnixTCPSocket();
|
|
|
|
// ISocket overrides
|
|
virtual void connect(const CString& hostname, UInt16 port);
|
|
virtual void listen(const CString& hostname, UInt16 port);
|
|
virtual ISocket* accept();
|
|
virtual SInt32 read(void* buffer, SInt32 numBytes);
|
|
virtual void write(const void* buffer, SInt32 numBytes);
|
|
|
|
protected:
|
|
// CSocket overrides
|
|
virtual void onJobChanged();
|
|
|
|
private:
|
|
CUnixTCPSocket(int);
|
|
|
|
// disable Nagle algorithm
|
|
void setNoDelay();
|
|
|
|
// callbacks for read/write events
|
|
void readCB();
|
|
void writeCB();
|
|
|
|
private:
|
|
enum EState { kNone, kConnecting, kConnected, kListening };
|
|
int m_fd;
|
|
EState m_state;
|
|
bool m_addedJobs;
|
|
};
|
|
|
|
class CUnixTCPSocketFactory : public CSocketFactory {
|
|
public:
|
|
CUnixTCPSocketFactory() { }
|
|
virtual ~CUnixTCPSocketFactory() { }
|
|
|
|
// CSocketFactory overrides
|
|
virtual ISocket* create() const
|
|
{ return new CUnixTCPSocket; }
|
|
};
|
|
|
|
#endif
|