source: libcf/trunk/include/cf_socket.h@ 21

Last change on this file since 21 was 21, checked in by cheese, 11 years ago

#1 add test code for multi-threading, socket and multi-threaded logging

File size: 2.3 KB
Line 
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# 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
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
38#ifdef _WIN32
39typedef int socklen_t;
40#endif // #ifdef _WIN32
41
42#ifdef __cplusplus
43extern "C" {
44#endif
45
46CF_EXPORT CF_BOOL
47CF_Socket_IsInitialized (void);
48
49CF_EXPORT int
50CF_Socket_Initialize (void);
51
52CF_EXPORT int
53CF_Socket_Finalize (void);
54
55CF_EXPORT int
56CF_Socket_Close (const int sock);
57
58CF_EXPORT int
59CF_Socket_SetOption (const int sock,
60 const int optname,
61 const void * optval,
62 const size_t optlen);
63
64CF_EXPORT int
65CF_Socket_GetOption (const int sock,
66 const int optname,
67 void * optval,
68 size_t * optlen);
69
70CF_EXPORT int
71CF_Socket_SetTimeout (const int sock,
72 const int timeout);
73
74CF_EXPORT int
75CF_Socket_Connect (const char * ip,
76 const unsigned short port);
77
78CF_EXPORT int
79CF_Socket_Server (const unsigned short port,
80 const int backlog);
81
82CF_EXPORT int
83CF_Socket_Accept (const int sock,
84 struct sockaddr_in * address);
85
86CF_EXPORT int
87CF_Socket_Send (const int sock,
88 const void * buf,
89 const int len);
90
91CF_EXPORT int
92CF_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__
Note: See TracBrowser for help on using the repository browser.