1 | /**
|
---|
2 | * @file cf_socket.h
|
---|
3 | * @author myusgun <myusgun@gmail.com>
|
---|
4 | * @version 0.1
|
---|
5 | *
|
---|
6 | * @remark TCP 소켓만 지원됨
|
---|
7 | *
|
---|
8 | * @example socket_server.c
|
---|
9 | * @example socket_client.c
|
---|
10 | */
|
---|
11 | #ifndef __CF_SOCKET_H__
|
---|
12 | #define __CF_SOCKET_H__
|
---|
13 |
|
---|
14 | #include "cf_base.h"
|
---|
15 |
|
---|
16 | #include <stddef.h>
|
---|
17 |
|
---|
18 | /** 타임아웃을 설정하지 않음 */
|
---|
19 | #define CF_SOCKET_NO_TIMEOUT -1
|
---|
20 |
|
---|
21 | /** 호스트 정보 */
|
---|
22 | typedef struct cf_socket_hostinfo {
|
---|
23 | char address[128]; /**< 원격 호스트 주소 */
|
---|
24 | unsigned short port; /**< 원격 호스트 포트 */
|
---|
25 | } CF_Socket_HostInfo;
|
---|
26 |
|
---|
27 | #ifdef __cplusplus
|
---|
28 | extern "C" {
|
---|
29 | #endif
|
---|
30 |
|
---|
31 | CF_EXPORT CF_BOOL
|
---|
32 | CF_Socket_IsInitialized (void);
|
---|
33 |
|
---|
34 | CF_EXPORT int
|
---|
35 | CF_Socket_Initialize (void);
|
---|
36 |
|
---|
37 | CF_EXPORT int
|
---|
38 | CF_Socket_Finalize (void);
|
---|
39 |
|
---|
40 | CF_EXPORT int
|
---|
41 | CF_Socket_Close (const int sock);
|
---|
42 |
|
---|
43 | CF_EXPORT int
|
---|
44 | CF_Socket_SetOption (const int sock,
|
---|
45 | const int optname,
|
---|
46 | const void * optval,
|
---|
47 | const size_t optlen);
|
---|
48 |
|
---|
49 | CF_EXPORT int
|
---|
50 | CF_Socket_GetOption (const int sock,
|
---|
51 | const int optname,
|
---|
52 | void * optval,
|
---|
53 | size_t * optlen);
|
---|
54 |
|
---|
55 | CF_EXPORT int
|
---|
56 | CF_Socket_Connect (const char * ip,
|
---|
57 | const unsigned short port);
|
---|
58 |
|
---|
59 | CF_EXPORT int
|
---|
60 | CF_Socket_ConnectTimeout (const char * ip,
|
---|
61 | const unsigned short port,
|
---|
62 | const int timeout);
|
---|
63 |
|
---|
64 | CF_EXPORT int
|
---|
65 | CF_Socket_Server (const unsigned short port,
|
---|
66 | const int backlog);
|
---|
67 |
|
---|
68 | CF_EXPORT int
|
---|
69 | CF_Socket_Accept (const int sock,
|
---|
70 | CF_Socket_HostInfo * host);
|
---|
71 |
|
---|
72 | CF_EXPORT int
|
---|
73 | CF_Socket_Send (const int sock,
|
---|
74 | const void * buf,
|
---|
75 | const int len);
|
---|
76 |
|
---|
77 | CF_EXPORT int
|
---|
78 | CF_Socket_SendTimeout (const int sock,
|
---|
79 | const void * buf,
|
---|
80 | const int len,
|
---|
81 | const int timeout);
|
---|
82 |
|
---|
83 | CF_EXPORT int
|
---|
84 | CF_Socket_Recv (const int sock,
|
---|
85 | void * buf,
|
---|
86 | const int len);
|
---|
87 |
|
---|
88 | CF_EXPORT int
|
---|
89 | CF_Socket_RecvTimeout (const int sock,
|
---|
90 | void * buf,
|
---|
91 | const int len,
|
---|
92 | const int timeout);
|
---|
93 |
|
---|
94 | #ifdef __cplusplus
|
---|
95 | }
|
---|
96 | #endif
|
---|
97 |
|
---|
98 | #endif // #ifndef __CF_SOCKET_H__
|
---|