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