-
Notifications
You must be signed in to change notification settings - Fork 244
/
Copy pathcppnet_socket.h
45 lines (35 loc) · 1.17 KB
/
cppnet_socket.h
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
// Use of this source code is governed by a BSD 3-Clause License
// that can be found in the LICENSE file.
// Author: caozhiyi ([email protected])
#ifndef INCLUDE_CPPNET_SOCKET
#define INCLUDE_CPPNET_SOCKET
#include <cstdint>
#include <string>
namespace cppnet {
// cppnet socket interface
class CNSocket {
public:
CNSocket() = default;
virtual ~CNSocket() = default;
// get os native socket
virtual uint64_t GetSocket() = 0;
// get local listen port
virtual uint16_t GetListenPort() = 0;
// get socket IP and address
virtual bool GetAddress(std::string& ip, uint16_t& port) = 0;
// post sync write event.
virtual bool Write(const char* src, uint32_t len) = 0;
// close the connect
virtual void Close() = 0;
// add a timer. must set timer call back
// interval support max 1 minute
virtual void AddTimer(uint32_t interval, bool always = false) = 0;
// stop the timer
virtual void StopTimer() = 0;
// set cppnet socket context.
virtual void SetContext(void* context) = 0;
// get context.
virtual void* GetContext() = 0;
};
} // namespace cppnet
#endif