hce-node application  1.4.3
HCE Hierarchical Cluster Engine node application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
cf_socket.h
Go to the documentation of this file.
1 /*
2  * Citrusleaf Foundation
3  * include/cf_socket.h - Some helpers for IO
4  *
5  * Copyright 2008 by Citrusleaf. All rights reserved.
6  * THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE. THE COPYRIGHT NOTICE
7  * ABOVE DOES NOT EVIDENCE ANY ACTUAL OR INTENDED PUBLICATION.
8  */
9 
10 #pragma once
11 
12 #include <stddef.h>
13 #include <stdint.h>
14 
15 
16 #ifndef CF_WINDOWS
17 //====================================================================
18 // Linux
19 //
20 
21 #include <unistd.h>
22 #include <arpa/inet.h>
23 #include <netinet/in.h>
24 #include <sys/socket.h>
25 
26 // Windows send() and recv() parameter types are different.
27 #define cf_socket_data_t void
28 #define cf_socket_size_t size_t
29 
30 #define cf_close(fd) (close(fd))
31 
32 //------------------------------------------------
33 // The API below is not used by the libevent2
34 // client, so we'll postpone the Windows version.
35 //
36 
37 extern int
38 cf_socket_read_timeout(int fd, uint8_t *buf, size_t buf_len, uint64_t trans_deadline, int attempt_ms);
39 extern int
40 cf_socket_write_timeout(int fd, uint8_t *buf, size_t buf_len, uint64_t trans_deadline, int attempt_ms);
41 extern int
42 cf_socket_read_forever(int fd, uint8_t *buf, size_t buf_len);
43 extern int
44 cf_socket_write_forever(int fd, uint8_t *buf, size_t buf_len);
45 
46 extern void
47 cf_print_sockaddr_in(char *prefix, struct sockaddr_in *sa_in);
48 
49 
50 #else // CF_WINDOWS
51 //====================================================================
52 // Windows
53 //
54 
55 #include <WinSock2.h>
56 #include <Ws2tcpip.h>
57 
58 #define cf_socket_data_t char
59 #define cf_socket_size_t int
60 
61 #define cf_close(fd) (closesocket(fd))
62 
63 #define MSG_DONTWAIT 0
64 #define MSG_NOSIGNAL 0
65 
66 #define SHUT_RDWR SD_BOTH
67 
68 
69 #endif // CF_WINDOWS
70 
71 
72 extern int
74 extern int
75 cf_socket_start_connect_nb(int fd, struct sockaddr_in *sa);
76 extern int
77 cf_socket_create_and_connect_nb(struct sockaddr_in *sa);