headers.h

Go to the documentation of this file.
00001 /*
00002  * See the dyninst/COPYRIGHT file for copyright information.
00003  * 
00004  * We provide the Paradyn Tools (below described as "Paradyn")
00005  * on an AS IS basis, and do not warrant its validity or performance.
00006  * We reserve the right to update, modify, or discontinue this
00007  * software at any time.  We shall have no obligation to supply such
00008  * updates or modifications or any other form of support to you.
00009  * 
00010  * By your use of Paradyn, you understand and agree that we (or any
00011  * other person or entity with proprietary rights in Paradyn) are
00012  * under no obligation to provide either maintenance services,
00013  * update services, notices of latent defects, or correction of
00014  * defects for Paradyn.
00015  * 
00016  * This library is free software; you can redistribute it and/or
00017  * modify it under the terms of the GNU Lesser General Public
00018  * License as published by the Free Software Foundation; either
00019  * version 2.1 of the License, or (at your option) any later version.
00020  * 
00021  * This library is distributed in the hope that it will be useful,
00022  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00023  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00024  * Lesser General Public License for more details.
00025  * 
00026  * You should have received a copy of the GNU Lesser General Public
00027  * License along with this library; if not, write to the Free Software
00028  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
00029  */
00030 
00031 
00032 // $Id: headers.h,v 1.30 2008/06/30 19:40:18 legendre Exp $
00033 
00034 #ifndef KLUDGES_H
00035 #define KLUDGES_H
00036 
00037 #include <sys/types.h>
00038 
00039 #ifndef FILE__
00040 #define FILE__ strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILE__
00041 #endif
00042 
00043 /*
00044  * Kludges to handle broken system includes and such...
00045  */
00046 
00047 extern "C" {
00048 typedef int (*xdr_rd_func)(void *, char *, int);
00049 typedef int (*xdr_wr_func)(void *, char *, int);
00050 }
00051 
00052 
00053 #include "common/h/Types.h"
00054 
00055 #if defined(os_linux) || defined(os_bgp) || defined(os_bg_ion) || defined(os_bgq_ion)
00056 #include "common/h/linuxHeaders.h"
00057 
00058 #elif defined(os_freebsd)
00059 #include "common/h/freebsdHeaders.h"
00060 
00061 #elif defined(os_bg_compute)
00062 #include "common/h/bg_compute_headers.h"
00063 
00064 #elif defined(os_aix)
00065 #include "common/h/aixv41Headers.h"
00066 
00067 #elif defined(os_osf)
00068 #include "common/h/osfHeaders.h"
00069 
00070 #elif defined(os_windows)
00071 #include "common/h/ntHeaders.h"
00072 
00073 #elif defined(os_irix)
00074 #include "common/h/irixHeaders.h"
00075 
00076 #elif defined(os_vxworks)
00077 #include "common/h/vxworksHeaders.h"
00078 
00079 #endif  /* architecture specific */
00080 
00081 typedef enum {
00082    RRVsuccess,
00083    RRVnoData,
00084    RRVinsufficientData,
00085    RRVreadError,
00086    RRVerror
00087 } readReturnValue_t;
00088 
00089 
00090 #if 0
00091 template<class T>
00092 readReturnValue_t P_socketRead(PDSOCKET fd, T &it, size_t sz)
00093 {
00094    ssize_t bytes_read = 0;
00095 #if defined (os_windows)
00096    bytes_read = recv( fd, (char *)&it, sz, 0 );
00097 #else
00098 try_again:
00099    bytes_read = read(fd, &it, sz);
00100 #endif
00101 
00102    if ( (ssize_t)PDSOCKET_ERROR == bytes_read ) {
00103 #if defined (os_windows)
00104       if (errno != 0) {
00105          fprintf(stderr, "%s[%d]:  read failed: %s:%d\n", FILE__, __LINE__,
00106                strerror(errno), errno);
00107          return REreadError;
00108       }
00109 #else
00110       if (errno == EAGAIN || errno == EINTR)
00111          goto try_again;
00112 
00113       fprintf(stderr, "%s[%d]:  read failed: %s:%d\n", FILE__, __LINE__,
00114             strerror(errno), errno);
00115       return REreadError;
00116 #endif
00117    }
00118 
00119    if (0 == bytes_read) {
00120       //  fd closed on other end (most likely)
00121       //bperr("%s[%d]:  cannot read, fd is closed\n", FILE__, __LINE__);
00122       return REnoData;
00123    }
00124 #if defined (os_windows)
00125    if ((PDSOCKET_ERROR == bytes_read) && (errno == 0)) {
00126       //  fd closed on other end (most likely)
00127       //bperr("%s[%d]:  cannot read, fd is closed\n", FILE__, __LINE__);
00128       return REnoData;
00129    }
00130 #endif
00131 
00132    if (bytes_read != sz) {
00133       fprintf(stderr, "%s[%d]:  read wrong number of bytes! %d, not %d\n",
00134             FILE__, __LINE__, bytes_read, sz);
00135       fprintf(stderr, "FIXME:  Need better logic to handle incomplete reads\n");
00136       return REinsufficientData;
00137    }
00138 
00139    return REsuccess;
00140 
00141 }
00142 #endif
00143 
00144 #if !defined(os_bg_compute)
00145 #if !defined(os_windows)
00146 template <class T>
00147 readReturnValue_t P_socketRead(PDSOCKET fd, T &it, ssize_t sz)
00148 {
00149    ssize_t bytes_read = 0;
00150 try_again:
00151    bytes_read = read(fd, (char *)&it, sz);
00152 
00153    if ( (ssize_t)-1 == bytes_read ) {
00154       if (errno == EAGAIN || errno == EINTR) 
00155          goto try_again;
00156 
00157       fprintf(stderr, "%s[%d]:  read failed: %s:%d\n", FILE__, __LINE__,
00158             strerror(errno), errno);
00159       return RRVreadError;
00160    }
00161 
00162    if (0 == bytes_read) {
00163       //  fd closed on other end (most likely)
00164       //bperr("%s[%d]:  cannot read, fd is closed\n", FILE__, __LINE__);
00165       return RRVnoData;
00166    }
00167    if (bytes_read != sz) {
00168       //bperr("%s[%d]:  read wrong number of bytes! %d, not %d\n", 
00169       //      FILE__, __LINE__, bytes_read, sz);
00170       //bperr("FIXME:  Need better logic to handle incomplete reads\n");
00171       return RRVinsufficientData;
00172    }
00173 
00174    return RRVsuccess;
00175 }
00176 #else
00177 
00178 #define ssize_t int
00179 template <class T>
00180 readReturnValue_t P_socketRead(PDSOCKET fd, T &it, ssize_t sz)
00181 {
00182    ssize_t bytes_read = 0;
00183 
00184    bytes_read = recv( fd, (char *)&it, sz, 0 );
00185 
00186    if ( PDSOCKET_ERROR == bytes_read && errno != 0 ) {
00187       fprintf(stderr, "%s[%d]:  read failed: %s:%d\n", FILE__, __LINE__,
00188             strerror(errno), errno);
00189       return RRVreadError;
00190    }
00191 
00192    if (0 == bytes_read || (PDSOCKET_ERROR == bytes_read && errno == 0)) {
00193       //  fd closed on other end (most likely)
00194       //bperr("%s[%d]:  cannot read, fd is closed\n", FILE__, __LINE__);
00195       return RRVnoData;
00196    }
00197 
00198    if (bytes_read != sz) {
00199       //bperr("%s[%d]:  read wrong number of bytes!\n", FILE__, __LINE__);
00200       //bperr("FIXME:  Need better logic to handle incomplete reads\n");
00201       return RRVinsufficientData;
00202    }
00203 
00204    return RRVsuccess;
00205 }
00206 #endif /* !defined(os_windows) */
00207 
00208 template<class T>
00209 readReturnValue_t P_socketRead(PDSOCKET fd, T &it)
00210 {
00211    return P_socketRead<T>(fd, it, sizeof(T));
00212 }
00213 #endif /* !os_bg_compute */
00214 #endif /* KLUDGES_H */
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on 12 Jul 2013 for SymtabAPI by  doxygen 1.6.1