forked from mengning/nezha
-
Notifications
You must be signed in to change notification settings - Fork 0
/
socketwrapper.h
104 lines (96 loc) · 3.4 KB
/
socketwrapper.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
90
91
92
93
94
95
96
97
98
99
100
101
102
/********************************************************************/
/* Copyright (C) SSE-USTC, 2012 */
/* */
/* FILE NAME : socketwraper.h */
/* PRINCIPAL AUTHOR : Mengning */
/* SUBSYSTEM NAME : network */
/* MODULE NAME : socketwraper */
/* LANGUAGE : C */
/* TARGET ENVIRONMENT : Any */
/* DATE OF FIRST RELEASE : 2012/12/13 */
/* DESCRIPTION : the interface to Linux system(socket) */
/********************************************************************/
/*
* Revision log:
*
* Created by Mengning,2012/12/13
* Support epoll,by Mengning,2012/12/18
*
*/
#ifndef _SOCKET_WRAPER_H_
#define _SOCKET_WRAPER_H_
#define MAX_LISTEN_QUEUE 4
#define MAX_CONNECT_FD 1024
typedef int tServiceHandler;
/*
* InitServer
* input : addr - server ip address
* input : port - server port to open
* output : None
* in/out : None
* return : if SUCCESS return 0
* : if FAILURE return (-1)
*/
int InitializeNetService(char * addr,short int port);
int ShutdownNetService();
/*
* OpenRemoteService - Only used in Client side,it connects Server.
* input : addr - server ip address
* input : port - server port to open
* output : None
* in/out : None
* return : if SUCCESS return tServiceHandler
* : if FAILURE return (-1)
*/
tServiceHandler OpenRemoteService(char * addr,short int port);
/*
* CloseRemoteService - Only used in Client side,it terminate connection.
* input : h - it MUST BE what OpenRemoteService returns.
* output : None
* in/out : None
* return : if SUCCESS return 0
* : if FAILURE return (-1)
*/
int CloseRemoteService(tServiceHandler h);
/*
* ServiceStart - Only used in Sever side,when client requests.
* hide client connectionn,JUST return client who have real data request
* input : None
* output : None
* in/out : None
* return : if SUCCESS return tServiceHandler
* : if FAILURE return (-1)
*/
tServiceHandler ServiceStart();
/*
* ServiceStop - Only used in Sever side,when client connects it return.
* input : h - it MUST BE what ServiceStart OR returns.
* output : None
* in/out : None
* return : if SUCCESS return 0
* : if FAILURE return (-1)
*/
int ServiceStop(tServiceHandler h);
/*
* SendData - send data to peer side
* input : h - it MUST BE what ServiceStart or OpenRemoteService returns.
* input : pBuf - point to data
* input : BufSize - the length of data bytes
* output : None
* in/out : None
* return : if SUCCESS return BufSize sended
* : if FAILURE return (-1)
* : if Connection Terminals return 0
*/
int SendData(tServiceHandler h,char * pBuf,int BufSize);
/*
* SendData - send data to peer side
* input : h - it MUST BE what ServiceStart or OpenRemoteService returns.
* in/out : pBuf - point to memory that will store recved data
* in/out : pBufSize - the max length of data to recv
* return : if SUCCESS return BufSize recved
* : if FAILURE return (-1)
* : if Connection Terminals return 0
*/
int RecvData(tServiceHandler h,char * pBuf,int *pBufSize);
#endif /* _SOCKET_WRAPER_H_ */