vshost-util-vserver

Build script and sources for util-vserver.
git clone https://ccx.te2000.cz/git/vshost-util-vserver
Log | Files | Refs

wrappers-iosock.hc (2299B)


      1 // $Id$    --*- c -*--
      2 
      3 // Copyright (C) 2004 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_ENSC_IN_WRAPPERS_H
     20 #  error wrappers_handler.hc can not be used in this way
     21 #endif
     22 
     23 #include <stdbool.h>
     24 
     25 inline static WRAPPER_DECL bool
     26 WsendAll(int fd, void const *ptr_v, size_t len, int *err)
     27 {
     28   register char const	*ptr = ptr_v;
     29   if (err) *err = 0;
     30 
     31   while (len>0) {
     32     ssize_t	res = TEMP_FAILURE_RETRY(send(fd, ptr, len, MSG_NOSIGNAL));
     33     if (res==-1) {
     34       if (err) *err = errno;
     35       return false;
     36     }
     37 
     38     if (res==0) return false;
     39 
     40     ptr += res;
     41     len -= res;
     42   }
     43   return true;
     44 }
     45 
     46 inline static WRAPPER_DECL void
     47 EsendAll(int fd, void const *ptr_v, size_t len)
     48 {
     49   register char const	*ptr = ptr_v;
     50 
     51   while (len>0) {
     52     ssize_t	res = TEMP_FAILURE_RETRY(send(fd, ptr, len, MSG_NOSIGNAL));
     53     FatalErrnoError(res==-1, "send()");
     54 
     55     ptr += res;
     56     len -= res;
     57   }
     58 }
     59 
     60 
     61 inline static WRAPPER_DECL bool
     62 WrecvAll(int fd, void *ptr_v, size_t len, int *err)
     63 {
     64   register char	*ptr = ptr_v;
     65   if (err) *err = 0;
     66   
     67   while (len>0) {
     68     ssize_t	res = TEMP_FAILURE_RETRY(recv(fd, ptr, len, MSG_NOSIGNAL));
     69     if (res==-1) {
     70       if (err) *err = errno;
     71       return false;
     72     }
     73 
     74     if (res==0) return false;
     75 
     76     ptr += res;
     77     len -= res;
     78   }
     79   return true;
     80 }
     81 
     82 inline static WRAPPER_DECL bool
     83 ErecvAll(int fd, void *ptr_v, size_t len)
     84 {
     85   register char	*ptr = ptr_v;
     86   
     87   while (len>0) {
     88     ssize_t	res = TEMP_FAILURE_RETRY(recv(fd, ptr, len, MSG_NOSIGNAL));
     89     FatalErrnoError(res==-1, "recv()");
     90 
     91     if (res==0) return false;
     92 
     93     ptr += res;
     94     len -= res;
     95   }
     96 
     97   return true;
     98 }