R-Type
ClientSession.hpp
Go to the documentation of this file.
1 /*
2 ** EPITECH PROJECT, 2023
3 ** ClientSession.hpp
4 ** File description:
5 ** ClientSession
6 */
7 
8 #ifndef CLIENTSESSION_HPP_
9 #define CLIENTSESSION_HPP_
10 
11 #include "SafeQueue.hpp"
12 #include <asio.hpp>
13 #include <iostream>
14 
15 namespace RType::Server
16 {
18  class ClientSession : public std::enable_shared_from_this<ClientSession>
19  {
20  public:
21  ClientSession(asio::io_context &IOContext);
23 
26  asio::ip::tcp::socket &getSocket();
27 
29  void start();
30 
33  std::shared_ptr<ClientSession> get();
34 
38  void handleRead(const asio::error_code &error, std::size_t transferredBytes);
39 
42  void handleWrite(const asio::error_code &error);
43 
44  protected:
45  private:
46  asio::ip::tcp::socket _socket;
47  std::array<char, 1024> _readBuffer;
48  };
49 }; // namespace RType::Server
50 #endif /* !CLIENTSESSION_HPP_ */
Client Session that will handle every client's event.
Definition: ClientSession.hpp:19
void handleWrite(const asio::error_code &error)
handles the asynchronous wait on write to the client session
Definition: ClientSession.cpp:18
asio::ip::tcp::socket & getSocket()
Get the socket of the client session.
Definition: ClientSession.cpp:14
void start()
start that will waiting for a message from the client
Definition: ClientSession.cpp:40
void handleRead(const asio::error_code &error, std::size_t transferredBytes)
handles the asynchronous wait on read for the client session
Definition: ClientSession.cpp:28
ClientSession(asio::io_context &IOContext)
Definition: ClientSession.cpp:10
~ClientSession()
Definition: ClientSession.cpp:12
std::shared_ptr< ClientSession > get()
Get the pointer of 'this' object.
Definition: ClientSession.cpp:16
Definition: ClientSession.hpp:16