-
Notifications
You must be signed in to change notification settings - Fork 0
/
tcp.hpp
45 lines (41 loc) · 1.17 KB
/
tcp.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
///
/// @file tcp.hpp
/// @author lambert(Liumeng_lambert@163.com)
/// @date 2018-03-03 16:15:36
///
#ifndef _TCP_H_
#define _TCP_H_
#include <iostream>
#include <memory>
#include <functional>
#include "socket.hpp"
class TcpConnection;
typedef std::shared_ptr<TcpConnection> TcpConnectionPtr;
class TcpConnection: public std::enable_shared_from_this<TcpConnection>{
public:
TcpConnection();
TcpConnection(int sockfd);
~TcpConnection();
typedef std::function<void (const TcpConnectionPtr &)> TcpConnectionCallback;
std::string receive();
void send(const std::string & msg);
void shutdown();
void set_connection_callback(TcpConnectionCallback cb);
void set_message_callback(TcpConnectionCallback cb);
void set_close_callback(TcpConnectionCallback cb);
void handle_connection_callback();
void handle_message_callback();
void handle_close_callback();
std::string to_string();
SocketServer& get_socket();
private:
SocketServer _socket;
SocketIO _sockIO;
const InetAddress _local_addr;
const InetAddress _peer_addr;
bool _is_shutdown_write;
TcpConnectionCallback _on_connection_cb;
TcpConnectionCallback _on_message_cb;
TcpConnectionCallback _on_close_cb;
};
#endif