All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
PosixTcpSocket.h
1 // Copyright eeGeo Ltd (2012-2016), All Rights Reserved
2 
3 #pragma once
4 
5 #include "Types.h"
6 #include "ITcpSocket.h"
7 #include "ITcpSocketSet.h"
8 
9 #include <vector>
10 #include <netinet/in.h>
11 #include <sys/socket.h>
12 #include <sys/types.h>
13 
14 
15 namespace Eegeo
16 {
17  namespace Networking
18  {
19  namespace Posix
20  {
21  class PosixTcpSocket: public ITcpSocket, protected Eegeo::NonCopyable
22  {
23  public:
24  static PosixTcpSocket* CreateListenerSocket();
25 
26  PosixTcpSocket(int clientSocketDescriptor, sockaddr_in clientSocket);
27  ~PosixTcpSocket();
28 
29  u64 GetSocketDescriptor() const { return static_cast<u64>(m_socketDescriptor); }
30 
31  void StartListening(int port);
32  ITcpSocket* Accept();
33  void SetNonBlocking();
34 
35  ITcpSocketSet* GetSocketSet();
36  ITcpSocketSet* GetSocketSet(const std::vector<ITcpSocket*>& clientSockets);
37 
38  ssize_t Receive(char* buffer, size_t maxBufferLength);
39  void Send(const char* data, int length) const;
40 
41  void Close();
42 
43  private:
44 
45  int m_socketDescriptor;
46  sockaddr_in m_socket;
47  };
48  }
49  }
50 }