[4] | 1 | /**
|
---|
| 2 | * cf_socket.h
|
---|
| 3 | */
|
---|
| 4 | #ifndef __CF_SOCKET_H__
|
---|
| 5 | #define __CF_SOCKET_H__
|
---|
| 6 |
|
---|
| 7 | #include "cf_base.h"
|
---|
| 8 | #include <stddef.h>
|
---|
| 9 |
|
---|
| 10 | #ifdef _WIN32
|
---|
| 11 | typedef int socklen_t;
|
---|
| 12 | #endif // #ifdef _WIN32
|
---|
| 13 |
|
---|
| 14 | #define CF_ERROR_SOCKET CF_ERROR_BASE * 3
|
---|
| 15 |
|
---|
| 16 | #define CF_ERROR_SOCKET_INITIALIZE CF_ERROR_SOCKET - 1
|
---|
| 17 | #define CF_ERROR_SOCKET_NOT_INITIALIZED CF_ERROR_SOCKET - 2
|
---|
| 18 | #define CF_ERROR_SOCKET_FINALIZE CF_ERROR_SOCKET - 3
|
---|
| 19 | #define CF_ERROR_SOCKET_CLOSE CF_ERROR_SOCKET - 4
|
---|
| 20 | #define CF_ERROR_SOCKET_CREATE CF_ERROR_SOCKET - 5
|
---|
| 21 | #define CF_ERROR_SOCKET_CONNECT CF_ERROR_SOCKET - 6
|
---|
| 22 | #define CF_ERROR_SOCKET_SET_OPTION CF_ERROR_SOCKET - 7
|
---|
| 23 | #define CF_ERROR_SOCKET_GET_OPTION CF_ERROR_SOCKET - 8
|
---|
| 24 | #define CF_ERROR_SOCKET_SET_TIMEOUT CF_ERROR_SOCKET - 9
|
---|
| 25 | #define CF_ERROR_SOCKET_INVALID_ARGS CF_ERROR_SOCKET - 10
|
---|
| 26 | #define CF_ERROR_SOCKET_INVALID_SOCKET CF_ERROR_SOCKET - 11
|
---|
| 27 | #define CF_ERROR_SOCKET_GET_HOST CF_ERROR_SOCKET - 12
|
---|
| 28 | #define CF_ERROR_SOCKET_BIND CF_ERROR_SOCKET - 13
|
---|
| 29 | #define CF_ERROR_SOCKET_LISTEN CF_ERROR_SOCKET - 14
|
---|
| 30 | #define CF_ERROR_SOCKET_ACCEPT CF_ERROR_SOCKET - 15
|
---|
| 31 | #define CF_ERROR_SOCKET_SEND CF_ERROR_SOCKET - 16
|
---|
| 32 | #define CF_ERROR_SOCKET_RECV CF_ERROR_SOCKET - 17
|
---|
| 33 |
|
---|
| 34 | #ifdef __cplusplus
|
---|
| 35 | extern "C" {
|
---|
| 36 | #endif
|
---|
| 37 |
|
---|
| 38 | CF_EXPORT E_CF_BOOL
|
---|
| 39 | CF_Socket_IsInitialized (void);
|
---|
| 40 |
|
---|
| 41 | CF_EXPORT int
|
---|
| 42 | CF_Socket_Initialize (void);
|
---|
| 43 |
|
---|
| 44 | CF_EXPORT int
|
---|
| 45 | CF_Socket_Finalize (void);
|
---|
| 46 |
|
---|
| 47 | CF_EXPORT int
|
---|
| 48 | CF_Socket_Close (const int sock);
|
---|
| 49 |
|
---|
| 50 | CF_EXPORT int
|
---|
| 51 | CF_Socket_SetOption (const int sock,
|
---|
| 52 | const int optname,
|
---|
| 53 | const void * optval,
|
---|
| 54 | const size_t optlen);
|
---|
| 55 |
|
---|
| 56 | CF_EXPORT int
|
---|
| 57 | CF_Socket_GetOption (const int sock,
|
---|
| 58 | const int optname,
|
---|
| 59 | void * optval,
|
---|
| 60 | size_t * optlen);
|
---|
| 61 |
|
---|
| 62 | CF_EXPORT int
|
---|
| 63 | CF_Socket_SetTimeout (const int sock,
|
---|
| 64 | const int timeout);
|
---|
| 65 |
|
---|
| 66 | CF_EXPORT int
|
---|
| 67 | CF_Socket_Connect (const char * ip,
|
---|
| 68 | const unsigned short port);
|
---|
| 69 |
|
---|
| 70 | CF_EXPORT int
|
---|
| 71 | CF_Socket_Server (const unsigned short port,
|
---|
| 72 | const int backlog);
|
---|
| 73 |
|
---|
| 74 | CF_EXPORT int
|
---|
| 75 | CF_Socket_Accept (const int sock,
|
---|
| 76 | void * address /* struct sockaddr_in * */);
|
---|
| 77 |
|
---|
| 78 | CF_EXPORT int
|
---|
| 79 | CF_Socket_Send (const int sock,
|
---|
| 80 | const void * buf,
|
---|
| 81 | const int len);
|
---|
| 82 |
|
---|
| 83 | CF_EXPORT int
|
---|
| 84 | CF_Socket_Recv (const int sock,
|
---|
| 85 | void * buf,
|
---|
| 86 | const int len);
|
---|
| 87 |
|
---|
| 88 | #ifdef __cplusplus
|
---|
| 89 | }
|
---|
| 90 | #endif
|
---|
| 91 |
|
---|
| 92 | #endif // #ifndef __CF_SOCKET_H__
|
---|