-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMyIkcp.h
90 lines (74 loc) · 1.79 KB
/
MyIkcp.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/*
* =====================================================================================
*
* Filename: MyIkcp.h
*
* Description:
*
* Version: 1.0
* Created: 09/30/2017 11:16:10 AM
* Last Modified: 09/30/2017 11:16:10 AM
* Revision: none
* Compiler: gcc
*
* Author: zt (),
* Organization:
*
* =====================================================================================
*/
#ifndef MYIKCP_INC
#define MYIKCP_INC
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <mutex>
#include <thread>
#include <vector>
#include <time.h>
#include <sys/time.h>
#include "ikcp.h"
#include "UdpSocket.h"
static inline void itimeofday ( long* sec, long* usec )
{
struct timeval time;
gettimeofday ( &time, NULL );
if ( sec )
*sec = time.tv_sec;
if ( usec )
*usec = time.tv_usec;
}
static inline int64_t iclock64 ( void )
{
long s, u;
int64_t value;
itimeofday ( &s, &u );
value = ( ( int64_t ) s ) * 1000 + ( u / 1000 );
return value;
}
static inline uint32_t iclock()
{
return ( uint32_t ) ( iclock64() & 0xfffffffful );
}
class MyIkcp
{
public:
MyIkcp ( uint32_t conv, uint16_t localport, std::string remoteip, uint16_t remoteport );
virtual ~MyIkcp();
public:
void Init();
void DeInit();
int Recv ( std::vector<uint8_t>& vecuint8 );
int Send ( std::vector<uint8_t>& vecuint8 );
int Recv ( uint8_t* buf, uint32_t size );
int Send ( uint8_t* buf, uint32_t size );
static int Udpoutput ( const char* buf, int len, ikcpcb* kcp, void* user );
private:
uint32_t m_conv;
ikcpcb* m_ikcp;
UdpSocket* m_udpSocket;
uint16_t m_localport;
std::string m_remoteip;
uint16_t m_remoteport;
};
#endif /* ----- #ifndef MyIkcp.h ----- */