aboutsummaryrefslogtreecommitdiff
path: root/src/microhttpd/mhd_itc.h
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2016-09-22 14:33:39 +0000
committerChristian Grothoff <christian@grothoff.org>2016-09-22 14:33:39 +0000
commit9c1254792ca4971b36d06706e9d51c253d96106d (patch)
treeea785c930b48f073e51c9c8a119d43081f42a3e5 /src/microhttpd/mhd_itc.h
parentdf6d586ac2f0f73bcd817638a1100bf5972faca9 (diff)
downloadlibmicrohttpd-9c1254792ca4971b36d06706e9d51c253d96106d.tar.gz
libmicrohttpd-9c1254792ca4971b36d06706e9d51c253d96106d.zip
raising MHD_Pipe API abstraction level in preparation for fixing #3557
Diffstat (limited to 'src/microhttpd/mhd_itc.h')
-rw-r--r--src/microhttpd/mhd_itc.h65
1 files changed, 49 insertions, 16 deletions
diff --git a/src/microhttpd/mhd_itc.h b/src/microhttpd/mhd_itc.h
index f42634f6..7a14dd52 100644
--- a/src/microhttpd/mhd_itc.h
+++ b/src/microhttpd/mhd_itc.h
@@ -47,19 +47,25 @@
47# include "mhd_sockets.h" 47# include "mhd_sockets.h"
48#endif /* MHD_DONT_USE_PIPES */ 48#endif /* MHD_DONT_USE_PIPES */
49 49
50/* MHD_pipe is type for pipe FDs*/ 50/**
51 * Data type for a MHD pipe.
52 */
53struct MHD_Pipe
54{
51#ifndef MHD_DONT_USE_PIPES 55#ifndef MHD_DONT_USE_PIPES
52 typedef int MHD_pipe; 56 int fd[2];
53#else /* ! MHD_DONT_USE_PIPES */ 57#else /* ! MHD_DONT_USE_PIPES */
54 typedef MHD_socket MHD_pipe; 58 MHD_socket fd[2];
55#endif /* ! MHD_DONT_USE_PIPES */ 59#endif /* ! MHD_DONT_USE_PIPES */
60};
61
56 62
57/* MHD_pipe_ create pipe (!MHD_DONT_USE_PIPES) / 63/* MHD_pipe_ create pipe (!MHD_DONT_USE_PIPES) /
58 * create two connected sockets (MHD_DONT_USE_PIPES) */ 64 * create two connected sockets (MHD_DONT_USE_PIPES) */
59#ifndef MHD_DONT_USE_PIPES 65#ifndef MHD_DONT_USE_PIPES
60# define MHD_pipe_(fdarr) (!pipe((fdarr))) 66# define MHD_pipe_(pip) (!pipe((pip.fd)))
61#else /* MHD_DONT_USE_PIPES */ 67#else /* MHD_DONT_USE_PIPES */
62# define MHD_pipe_(fdarr) MHD_socket_pair_((fdarr)) 68# define MHD_pipe_(pip) MHD_socket_pair_((pip.fd))
63#endif /* MHD_DONT_USE_PIPES */ 69#endif /* MHD_DONT_USE_PIPES */
64 70
65/* MHD_pipe_last_strerror_ is description string of last errno (!MHD_DONT_USE_PIPES) / 71/* MHD_pipe_last_strerror_ is description string of last errno (!MHD_DONT_USE_PIPES) /
@@ -73,45 +79,72 @@
73/* MHD_pipe_write_ write data to real pipe (!MHD_DONT_USE_PIPES) / 79/* MHD_pipe_write_ write data to real pipe (!MHD_DONT_USE_PIPES) /
74 * write data to emulated pipe (MHD_DONT_USE_PIPES) */ 80 * write data to emulated pipe (MHD_DONT_USE_PIPES) */
75#ifndef MHD_DONT_USE_PIPES 81#ifndef MHD_DONT_USE_PIPES
76# define MHD_pipe_write_(fd, ptr, sz) write((fd), (const void*)(ptr), (sz)) 82# define MHD_pipe_write_(pip, ptr, sz) write((pip.fd[1]), (const void*)(ptr), (sz))
83#else
84# define MHD_pipe_write_(pip, ptr, sz) send((pip.fd[1]), (const char*)(ptr), (sz), 0)
85#endif
86
87
88#ifndef MHD_DONT_USE_PIPES
89# define MHD_pipe_get_read_fd_(pip) (pip.fd[0])
90#else
91# define MHD_pipe_get_read_fd_(pip) (pip.fd[0])
92#endif
93
94
95#ifndef MHD_DONT_USE_PIPES
96# define MHD_pipe_get_write_fd_(pip) (pip.fd[1])
77#else 97#else
78# define MHD_pipe_write_(fd, ptr, sz) send((fd), (const char*)(ptr), (sz), 0) 98# define MHD_pipe_get_write_fd_(pip) (pip.fd[1])
79#endif 99#endif
80 100
101
102
81/* MHD_pipe_drain_ drain data from real pipe (!MHD_DONT_USE_PIPES) / 103/* MHD_pipe_drain_ drain data from real pipe (!MHD_DONT_USE_PIPES) /
82 * drain data from emulated pipe (MHD_DONT_USE_PIPES) */ 104 * drain data from emulated pipe (MHD_DONT_USE_PIPES) */
83#ifndef MHD_DONT_USE_PIPES 105#ifndef MHD_DONT_USE_PIPES
84# define MHD_pipe_drain_(fd) do { long tmp; while (0 < read((fd), (void*)&tmp, sizeof (tmp))) ; } while (0) 106# define MHD_pipe_drain_(pip) do { long tmp; while (0 < read((pip.fd[0]), (void*)&tmp, sizeof (tmp))) ; } while (0)
85#else 107#else
86# define MHD_pipe_drain_(fd) do { long tmp; while (0 < recv((fd), (void*)&tmp, sizeof (tmp), 0)) ; } while (0) 108# define MHD_pipe_drain_(pip) do { long tmp; while (0 < recv((pip.fd[0]), (void*)&tmp, sizeof (tmp), 0)) ; } while (0)
87#endif 109#endif
88 110
89/* MHD_pipe_close_(fd) close any FDs (non-W32) / 111/* MHD_pipe_close_(fd) close any FDs (non-W32) /
90 * close emulated pipe FDs (W32) */ 112 * close emulated pipe FDs (W32) */
91#ifndef MHD_DONT_USE_PIPES 113#ifndef MHD_DONT_USE_PIPES
92# define MHD_pipe_close_(fd) close((fd)) 114# define MHD_pipe_close_(pip) do { close(pip.fd[0]); close(pip.fd[1]); } while (0)
93#else 115#else
94# define MHD_pipe_close_(fd) MHD_socket_close_((fd)) 116# define MHD_pipe_close_(fd) do { MHD_socket_close_(pip.fd[0]); MHD_socket_close_(pip.fd[1]); } while (0)
95#endif 117#endif
96 118
97/* MHD_INVALID_PIPE_ is a value of bad pipe FD */ 119/* MHD_INVALID_PIPE_ is a value of bad pipe FD */
98#ifndef MHD_DONT_USE_PIPES 120#ifndef MHD_DONT_USE_PIPES
99# define MHD_INVALID_PIPE_ (-1) 121# define MHD_INVALID_PIPE_(pip) (-1 == pip.fd[0])
100#else 122#else
101# define MHD_INVALID_PIPE_ MHD_INVALID_SOCKET 123# define MHD_INVALID_PIPE_(pip) (MHD_INVALID_SOCKET == pip.fd[0])
102#endif 124#endif
103 125
104#ifndef MHD_DONT_USE_PIPES 126#ifndef MHD_DONT_USE_PIPES
127#define MHD_make_invalid_pipe_(pip) do { \
128 pip.fd[0] = pip.fd[1] = -1; \
129 } while (0)
130#else
131#define MHD_make_invalid_pipe_(pip) do { \
132 pip.fd[0] = pip.fd[1] = MHD_INVALID_SOCKET; \
133 } while (0)
134#endif
135
136
137#ifndef MHD_DONT_USE_PIPES
105/** 138/**
106 * Change itc FD options to be non-blocking. 139 * Change itc FD options to be non-blocking.
107 * 140 *
108 * @param fd the FD to manipulate 141 * @param fd the FD to manipulate
109 * @return non-zero if succeeded, zero otherwise 142 * @return non-zero if succeeded, zero otherwise
110 */ 143 */
111 int 144int
112 MHD_itc_nonblocking_ (MHD_pipe fd); 145MHD_itc_nonblocking_ (struct MHD_Pipe fd);
113#else 146#else
114# define MHD_itc_nonblocking_(f) MHD_socket_nonblocking_((f)) 147# define MHD_itc_nonblocking_(pip) (MHD_socket_nonblocking_((pip.fd[0])) && MHD_socket_nonblocking_((pip.fd[1])))
115#endif 148#endif
116 149
117#endif /* MHD_ITC_H */ 150#endif /* MHD_ITC_H */