00001 #ifndef _UNEVT_UNIXError_H_ // -*-c++-*- 00002 00003 /* 00004 * Copyright (C) 1991-9 Eric M. Hopper <hopper@omnifarious.mn.org> 00005 * 00006 * This program is free software; you can redistribute it and/or modify it 00007 * under the terms of the GNU Lesser General Public License as published 00008 * by the Free Software Foundation; either version 2 of the License, or 00009 * (at your option) any later version. 00010 * 00011 * This program is distributed in the hope that it will be useful, but 00012 * WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00014 * Lesser General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU Lesser General Public 00017 * License along with this program; if not, write to the Free Software 00018 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 00019 */ 00020 00021 #ifdef __GNUG__ 00022 # pragma interface 00023 #endif 00024 00025 /* $Header: /home/hopper/src/cvs/C++/UniEvent/UniEvent/UNIXError.h,v 1.12 2002/11/25 05:40:05 hopper Exp $ */ 00026 00027 // See ../ChangeLog for log. 00028 00029 #include <LCore/LCoreError.h> 00030 #include <cstddef> // For size_t 00031 #include <cerrno> // For errno 00032 00033 #define _UNEVT_UNIXError_H_ 00034 00035 namespace strmod { 00036 namespace unievent { 00037 00038 /** \class UNIXError UNIXError.h UniEvent/UNIXError.h 00039 * \brief Holds a UNIX errno value. 00040 * 00041 * There are no member functions to modify its value, so this is essentially a 00042 * const value. This makes the class multithread safe. 00043 * 00044 * There is a special kind of error called an EOF error. An EOF error signals 00045 * that an EOF condition exists on the file descriptor in questoin. The 'errno' 00046 * value is ESUCCESS (0) in this case. 00047 */ 00048 class UNIXError : public lcore::LCoreError 00049 { 00050 private: 00051 struct junk; 00052 public: 00053 //! A value for no error at all. 00054 static const UNIXError S_noerror; 00055 00056 //! Create an EOF error from a system call name, and an LCoreError. 00057 inline UNIXError(const char *syscallname, 00058 const lcore::LCoreError &lcerr) throw (); 00059 //! Create from a system call name, an errno value, and an LCoreError. 00060 inline UNIXError(const char *syscallname, int errnum, 00061 const lcore::LCoreError &lcerr) throw (); 00062 00063 //! Return name of system call that caused error. 00064 const char *getSyscallName() const throw () { return syscallname_; } 00065 00066 //! The numeric value of the error, which corresponds to values from errno.h 00067 int getErrorNum() const throw () { return errnum_; } 00068 /** The result of doing <code>strerror_r(getErrorNum(), buf, buflen)</code>. 00069 * 00070 * \param buf A buffer to stuff the string into. 00071 * \param buflen The maximum number of bytes the buffer can hold. 00072 * 00073 * <code>buf[buflen - 1]</code> will always be set to '\\0'. 00074 * 00075 * One some platforms (like Linux), strerror is not thread safe, and a 00076 * different function, strerror_r is called. strerror_r requires you to 00077 * supply a buffer. The sterror_r interface is supported since the 00078 * strerror_r interface can be implemented in terms of the strerror 00079 * interface, but not the other way around. 00080 */ 00081 void getErrorString(char *buf, size_t buflen) const throw (); 00082 00083 //! Is this an End-Of-File error? 00084 bool isEOF() const throw() { return iseof_; } 00085 00086 static int getErrno() { return errno; } 00087 00088 private: 00089 const char *syscallname_; 00090 const int errnum_; 00091 const bool iseof_; 00092 00093 struct junk { 00094 }; 00095 }; 00096 00097 //-----------------------------inline functions-------------------------------- 00098 00099 /** 00100 * \param syscallname Name of system call that generated the error. 00101 * \param lcerr An LCoreError, it's values will be copied into the UNIXError. 00102 * The actual Unix error number is grabbed from the global 'errno' value. 00103 */ 00104 inline 00105 UNIXError::UNIXError(const char *syscallname, 00106 const lcore::LCoreError &lcerr) throw () 00107 : LCoreError(lcerr), syscallname_(syscallname), 00108 errnum_(0), iseof_(true) 00109 { 00110 } 00111 00112 /** 00113 * \param syscallname Name of system call that generated the error. 00114 * \param errnum The Unix 'errno' value for this error. 00115 * \param lcerr An LCoreError, it's values will be copied into the UNIXError. 00116 */ 00117 inline 00118 UNIXError::UNIXError(const char *syscallname, 00119 int errnum, const lcore::LCoreError &lcerr) 00120 throw () 00121 : LCoreError(lcerr), syscallname_(syscallname), 00122 errnum_(errnum), iseof_(false) 00123 { 00124 } 00125 00126 } // namespace unievent 00127 } // namespace strmod 00128 00129 #endif
1.3-rc1