-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsocket.h
More file actions
94 lines (68 loc) · 1.45 KB
/
Copy pathsocket.h
File metadata and controls
94 lines (68 loc) · 1.45 KB
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
90
91
92
93
94
#ifndef _SOCKET_
#define _SOCKET_
/*
-- packet 구조 --
packet size : 4 byte
packet command : 4 byte
packet data size : 5 byte
packet data : data size 만큼
*/
#include <stdio.h>
#include <stdlib.h>
#ifdef __linux__
#include <sys/socket.h>
#include <arpa/inet.h> //inet_addr
#else
#include <Windows.h>
#include <winsock.h>
#endif
#include "predef.h"
struct SocketBuffer
{
int totalsize; // 전체 길이
int currentsize; // 진행중인 버퍼 위치 (송/수신 모두)
char buffer[SOCKET_BUFFER];
SocketBuffer()
{
totalsize = -1;
currentsize = 0;
memset(buffer, 0, SOCKET_BUFFER);
}
};
class Socket
{
public :
Socket();
~Socket();
bool init();
void uninit();
bool connect();
void closesocket();
bool update();
bool sendpacket(char *packet,int packetsize); // 실제로 보내는것 아님
bool recvpacket(SocketBuffer *buffer);
int sendImmediate(char* buf, int datasize);
private :
void senddone();
void recvdone();
bool initserver();
bool initclient();
void closeserver();
void closeclient();
bool updateserver();
bool updateclient();
#if WIN32
SOCKET sock;
SOCKET clisock;
#else
int sock;
int clisock;
#endif
struct sockaddr_in server;
struct sockaddr_in cli_addr;
std::deque<SocketBuffer> recvbufferlist;
std::deque<SocketBuffer> sendbufferlist;
SocketBuffer sendbuffer;
SocketBuffer recvbuffer;
};
#endif