Nazara Engine  0.4
A fast, complete, cross-platform API designed for game development
AbstractSocket.hpp
1 // Copyright (C) 2017 Jérôme Leclercq
2 // This file is part of the "Nazara Engine - Network module"
3 // For conditions of distribution and use, see copyright notice in Config.hpp
4 
5 #pragma once
6 
7 #ifndef NAZARA_ABSTRACTSOCKET_HPP
8 #define NAZARA_ABSTRACTSOCKET_HPP
9 
10 #include <Nazara/Prerequesites.hpp>
11 #include <Nazara/Core/Signal.hpp>
12 #include <Nazara/Network/Config.hpp>
13 #include <Nazara/Network/Enums.hpp>
14 #include <Nazara/Network/SocketHandle.hpp>
15 
16 namespace Nz
17 {
18  class NAZARA_NETWORK_API AbstractSocket
19  {
20  public:
21  AbstractSocket(const AbstractSocket&) = delete;
22  AbstractSocket(AbstractSocket&& abstractSocket);
23  virtual ~AbstractSocket();
24 
25  void Close();
26 
27  void EnableBlocking(bool blocking);
28 
29  inline SocketError GetLastError() const;
30  inline SocketHandle GetNativeHandle() const;
31  inline SocketState GetState() const;
32  inline SocketType GetType() const;
33 
34  inline bool IsBlockingEnabled() const;
35 
36  std::size_t QueryAvailableBytes() const;
37  std::size_t QueryReceiveBufferSize() const;
38  std::size_t QuerySendBufferSize() const;
39 
40  void SetReceiveBufferSize(std::size_t size);
41  void SetSendBufferSize(std::size_t size);
42 
43  AbstractSocket& operator=(const AbstractSocket&) = delete;
44  AbstractSocket& operator=(AbstractSocket&& abstractSocket);
45 
46  // Signals:
47  NazaraSignal(OnStateChange, const AbstractSocket* /*socket*/, SocketState /*newState*/);
48 
49  protected:
50  AbstractSocket(SocketType type);
51 
52  virtual void OnClose();
53  virtual void OnOpened();
54 
55  bool Open(NetProtocol protocol);
56  void Open(SocketHandle existingHandle);
57 
58  inline void UpdateState(SocketState newState);
59 
60  NetProtocol m_protocol;
61  SocketError m_lastError;
62  SocketHandle m_handle;
63  SocketState m_state;
64  SocketType m_type;
65  bool m_isBlockingEnabled;
66  };
67 }
68 
69 #include <Nazara/Network/AbstractSocket.inl>
70 
71 #endif // NAZARA_ABSTRACTSOCKET_HPP
TODO: Inherit SoundEmitter from Node.
Definition: Algorithm.hpp:12
Network class that represents the base of socket.
Definition: AbstractSocket.hpp:18