rewrote and enhanced it
[util-vserver.git] / util-vserver / src / wrappers-io.h
1 // $Id$    --*- c -*--
2
3 // Copyright (C) 2003 Enrico Scholz <enrico.scholz@informatik.tu-chemnitz.de>
4 //  
5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; version 2 of the License.
8 //  
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 // GNU General Public License for more details.
13 //  
14 // You should have received a copy of the GNU General Public License
15 // along with this program; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17
18
19 #ifndef H_VSERVER_DJINNI_SRC_WRAPPERS_IO_H
20 #define H_VSERVER_DJINNI_SRC_WRAPPERS_IO_H
21
22 #include "wrappers.h"
23
24 #ifdef UTILVSERVER_ENABLE_SOCKET_WRAPPERS
25 inline static UNUSED bool
26 WsendAll(int fd, void const *ptr_v, size_t len)
27 {
28   register char const   *ptr = ptr_v;
29
30   while (len>0) {
31     size_t      res = TEMP_FAILURE_RETRY(send(fd, ptr, len, MSG_NOSIGNAL));
32     if (res==(size_t)-1) {
33       perror("send()");
34       return false;
35     }
36
37     if (res==0) return false;
38
39     ptr += res;
40     len -= res;
41   }
42   return true;
43 }
44
45 inline static UNUSED void
46 EsendAll(int fd, void const *ptr_v, size_t len)
47 {
48   register char const   *ptr = ptr_v;
49
50   while (len>0) {
51     size_t      res = TEMP_FAILURE_RETRY(send(fd, ptr, len, MSG_NOSIGNAL));
52     FatalErrnoError(res==(size_t)-1, "send()");
53
54     ptr += res;
55     len -= res;
56   }
57 }
58
59
60 inline static UNUSED bool
61 WrecvAll(int fd, void *ptr_v, size_t len)
62 {
63   register char *ptr = ptr_v;
64   
65   while (len>0) {
66     size_t      res = TEMP_FAILURE_RETRY(recv(fd, ptr, len, MSG_NOSIGNAL));
67     if (res==(size_t)-1) {
68       perror("recv()");
69       return false;
70     }
71
72     if (res==0) return false;
73
74     ptr += res;
75     len -= res;
76   }
77   return true;
78 }
79
80 inline static UNUSED bool
81 ErecvAll(int fd, void *ptr_v, size_t len)
82 {
83   register char *ptr = ptr_v;
84   
85   while (len>0) {
86     size_t      res = TEMP_FAILURE_RETRY(recv(fd, ptr, len, MSG_NOSIGNAL));
87     FatalErrnoError(res==(size_t)-1, "recv()");
88
89     if (res==0) return false;
90
91     ptr += res;
92     len -= res;
93   }
94
95   return true;
96 }
97 #endif
98
99 inline static UNUSED bool
100 WwriteAll(int fd, void const *ptr_v, size_t len)
101 {
102   register char const   *ptr = ptr_v;
103
104   while (len>0) {
105     size_t      res = TEMP_FAILURE_RETRY(write(fd, ptr, len));
106     if (res==(size_t)-1) {
107       perror("write()");
108       return false;
109     }
110
111     if (res==0) return false;
112
113     ptr += res;
114     len -= res;
115   }
116   return true;
117 }
118
119 inline static UNUSED void
120 EwriteAll(int fd, void const *ptr_v, size_t len)
121 {
122   register char const   *ptr = ptr_v;
123
124   while (len>0) {
125     size_t      res = TEMP_FAILURE_RETRY(write(fd, ptr, len));
126     FatalErrnoError(res==(size_t)-1, "write()");
127
128     ptr += res;
129     len -= res;
130   }
131 }
132
133
134 inline static UNUSED bool
135 WreadAll(int fd, void *ptr_v, size_t len)
136 {
137   register char *ptr = ptr_v;
138   
139   while (len>0) {
140     size_t      res = TEMP_FAILURE_RETRY(read(fd, ptr, len));
141     if (res==(size_t)-1) {
142       perror("read()");
143       return false;
144     }
145
146     if (res==0) return false;
147
148     ptr += res;
149     len -= res;
150   }
151   return true;
152 }
153
154 inline static UNUSED bool
155 EreadAll(int fd, void *ptr_v, size_t len)
156 {
157   register char *ptr = ptr_v;
158   
159   while (len>0) {
160     size_t      res = TEMP_FAILURE_RETRY(read(fd, ptr, len));
161     FatalErrnoError(res==(size_t)-1, "read()");
162
163     if (res==0) return false;
164
165     ptr += res;
166     len -= res;
167   }
168
169   return true;
170 }
171
172 #endif  //  H_VSERVER_DJINNI_SRC_WRAPPERS_IO_H