00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
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
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
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
00121
00122 return REnoData;
00123 }
00124 #if defined (os_windows)
00125 if ((PDSOCKET_ERROR == bytes_read) && (errno == 0)) {
00126
00127
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
00164
00165 return RRVnoData;
00166 }
00167 if (bytes_read != sz) {
00168
00169
00170
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
00194
00195 return RRVnoData;
00196 }
00197
00198 if (bytes_read != sz) {
00199
00200
00201 return RRVinsufficientData;
00202 }
00203
00204 return RRVsuccess;
00205 }
00206 #endif
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
00214 #endif