[4] | 1 | /**
|
---|
[26] | 2 | * @file cf_socket.h
|
---|
| 3 | * @author myusgun <myusgun@gmail.com>
|
---|
| 4 | * @version 0.1
|
---|
[34] | 5 | *
|
---|
| 6 | * @remark TCP 소켓만 지원됨
|
---|
| 7 | *
|
---|
[35] | 8 | * @example socket_server.c
|
---|
| 9 | * @example socket_client.c
|
---|
[4] | 10 | */
|
---|
| 11 | #ifndef __CF_SOCKET_H__
|
---|
| 12 | #define __CF_SOCKET_H__
|
---|
| 13 |
|
---|
| 14 | #include "cf_base.h"
|
---|
| 15 | #include <stddef.h>
|
---|
| 16 |
|
---|
[21] | 17 | #ifdef _WIN32
|
---|
| 18 | # include <WinSock2.h>
|
---|
| 19 | #else
|
---|
| 20 | # include <netinet/in.h>
|
---|
| 21 | # include <sys/socket.h>
|
---|
| 22 | # include <arpa/inet.h>
|
---|
| 23 | # include <netdb.h>
|
---|
| 24 | # include <unistd.h>
|
---|
| 25 | #endif
|
---|
| 26 |
|
---|
[4] | 27 | #define CF_ERROR_SOCKET_INITIALIZE CF_ERROR_SOCKET - 1
|
---|
| 28 | #define CF_ERROR_SOCKET_NOT_INITIALIZED CF_ERROR_SOCKET - 2
|
---|
| 29 | #define CF_ERROR_SOCKET_FINALIZE CF_ERROR_SOCKET - 3
|
---|
| 30 | #define CF_ERROR_SOCKET_CLOSE CF_ERROR_SOCKET - 4
|
---|
| 31 | #define CF_ERROR_SOCKET_CREATE CF_ERROR_SOCKET - 5
|
---|
| 32 | #define CF_ERROR_SOCKET_CONNECT CF_ERROR_SOCKET - 6
|
---|
| 33 | #define CF_ERROR_SOCKET_SET_OPTION CF_ERROR_SOCKET - 7
|
---|
| 34 | #define CF_ERROR_SOCKET_GET_OPTION CF_ERROR_SOCKET - 8
|
---|
| 35 | #define CF_ERROR_SOCKET_SET_TIMEOUT CF_ERROR_SOCKET - 9
|
---|
| 36 | #define CF_ERROR_SOCKET_INVALID_ARGS CF_ERROR_SOCKET - 10
|
---|
| 37 | #define CF_ERROR_SOCKET_INVALID_SOCKET CF_ERROR_SOCKET - 11
|
---|
| 38 | #define CF_ERROR_SOCKET_GET_HOST CF_ERROR_SOCKET - 12
|
---|
| 39 | #define CF_ERROR_SOCKET_BIND CF_ERROR_SOCKET - 13
|
---|
| 40 | #define CF_ERROR_SOCKET_LISTEN CF_ERROR_SOCKET - 14
|
---|
| 41 | #define CF_ERROR_SOCKET_ACCEPT CF_ERROR_SOCKET - 15
|
---|
| 42 | #define CF_ERROR_SOCKET_SEND CF_ERROR_SOCKET - 16
|
---|
| 43 | #define CF_ERROR_SOCKET_RECV CF_ERROR_SOCKET - 17
|
---|
| 44 |
|
---|
[6] | 45 | #ifdef _WIN32
|
---|
| 46 | typedef int socklen_t;
|
---|
| 47 | #endif // #ifdef _WIN32
|
---|
| 48 |
|
---|
[4] | 49 | #ifdef __cplusplus
|
---|
| 50 | extern "C" {
|
---|
| 51 | #endif
|
---|
| 52 |
|
---|
[6] | 53 | CF_EXPORT CF_BOOL
|
---|
[4] | 54 | CF_Socket_IsInitialized (void);
|
---|
| 55 |
|
---|
| 56 | CF_EXPORT int
|
---|
| 57 | CF_Socket_Initialize (void);
|
---|
| 58 |
|
---|
| 59 | CF_EXPORT int
|
---|
| 60 | CF_Socket_Finalize (void);
|
---|
| 61 |
|
---|
| 62 | CF_EXPORT int
|
---|
| 63 | CF_Socket_Close (const int sock);
|
---|
| 64 |
|
---|
| 65 | CF_EXPORT int
|
---|
| 66 | CF_Socket_SetOption (const int sock,
|
---|
| 67 | const int optname,
|
---|
| 68 | const void * optval,
|
---|
| 69 | const size_t optlen);
|
---|
| 70 |
|
---|
| 71 | CF_EXPORT int
|
---|
| 72 | CF_Socket_GetOption (const int sock,
|
---|
| 73 | const int optname,
|
---|
| 74 | void * optval,
|
---|
| 75 | size_t * optlen);
|
---|
| 76 |
|
---|
| 77 | CF_EXPORT int
|
---|
| 78 | CF_Socket_SetTimeout (const int sock,
|
---|
| 79 | const int timeout);
|
---|
| 80 |
|
---|
| 81 | CF_EXPORT int
|
---|
| 82 | CF_Socket_Connect (const char * ip,
|
---|
| 83 | const unsigned short port);
|
---|
| 84 |
|
---|
| 85 | CF_EXPORT int
|
---|
| 86 | CF_Socket_Server (const unsigned short port,
|
---|
| 87 | const int backlog);
|
---|
| 88 |
|
---|
| 89 | CF_EXPORT int
|
---|
[21] | 90 | CF_Socket_Accept (const int sock,
|
---|
| 91 | struct sockaddr_in * address);
|
---|
[4] | 92 |
|
---|
| 93 | CF_EXPORT int
|
---|
| 94 | CF_Socket_Send (const int sock,
|
---|
| 95 | const void * buf,
|
---|
| 96 | const int len);
|
---|
| 97 |
|
---|
| 98 | CF_EXPORT int
|
---|
| 99 | CF_Socket_Recv (const int sock,
|
---|
| 100 | void * buf,
|
---|
| 101 | const int len);
|
---|
| 102 |
|
---|
| 103 | #ifdef __cplusplus
|
---|
| 104 | }
|
---|
| 105 | #endif
|
---|
| 106 |
|
---|
| 107 | #endif // #ifndef __CF_SOCKET_H__
|
---|