Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

panda/src/net/pprerror.cxx

Go to the documentation of this file.
00001 // Filename: pprerror.cxx
00002 // Created by:  drose (08Feb00)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) 2001, Disney Enterprises, Inc.  All rights reserved
00008 //
00009 // All use of this software is subject to the terms of the Panda 3d
00010 // Software license.  You should have received a copy of this license
00011 // along with this source code; you will also find a current copy of
00012 // the license at http://www.panda3d.org/license.txt .
00013 //
00014 // To contact the maintainers of this program write to
00015 // panda3d@yahoogroups.com .
00016 //
00017 ////////////////////////////////////////////////////////////////////
00018 
00019 #include <pandabase.h>
00020 #include "pprerror.h"
00021 #include "config_net.h"
00022 
00023 #include <prerror.h>
00024 #include <prprf.h>
00025 #include <prmem.h>
00026 
00027 #include <stdarg.h>
00028 #include <stdio.h>
00029 
00030 static const char *get_error_message(PRErrorCode code);
00031 
00032 ////////////////////////////////////////////////////////////////////
00033 //     Function: pprerror
00034 //  Description: A handy function like perror().  It outputs the
00035 //               printf-style format string and its arguments,
00036 //               followed by a colon and the NSPR-given description of
00037 //               its current error state.
00038 ////////////////////////////////////////////////////////////////////
00039 void
00040 pprerror(const char *format, ...) {
00041   va_list ap;
00042   va_start(ap, format);
00043 
00044   char *str = PR_vsprintf_append(NULL, format, ap);
00045   if (str == (char *)NULL) {
00046     net_cat.error()
00047       << string("Invalid format string: ") + format + "\n";
00048     return;
00049   }
00050 
00051   PRErrorCode code = PR_GetError();
00052   const char *error_message = get_error_message(code);
00053 
00054   if (error_message == (const char *)NULL) {
00055     str = PR_sprintf_append(str, ": (%d)\n", code);
00056   } else {
00057     str = PR_sprintf_append(str, ": %s (%d)\n", error_message, code);
00058   }
00059 
00060   net_cat.error() << str;
00061 
00062   PR_Free(str);
00063   if (get_net_error_abort()) {
00064     abort();
00065   }
00066   va_end(ap);
00067 }
00068 
00069 ////////////////////////////////////////////////////////////////////
00070 //     Function: get_error_message
00071 //  Description: A local function to this module, it returns a
00072 //               sensibly formatted string to describe the given NSPR
00073 //               error code.  The strings in this function were
00074 //               extracted from the NSPR documentation web site.
00075 ////////////////////////////////////////////////////////////////////
00076 static const char *
00077 get_error_message(PRErrorCode code) {
00078   switch (code) {
00079   case PR_OUT_OF_MEMORY_ERROR:
00080     return "PR_OUT_OF_MEMORY_ERROR--Insufficient memory to perform request.";
00081   case PR_BAD_DESCRIPTOR_ERROR:
00082     return "PR_BAD_DESCRIPTOR_ERROR--The file descriptor used as an argument in the preceding function is invalid.";
00083   case PR_WOULD_BLOCK_ERROR:
00084     return "PR_WOULD_BLOCK_ERROR--The operation would have blocked, which conflicts with the semantics that have been established.";
00085   case PR_ACCESS_FAULT_ERROR:
00086     return "PR_ACCESS_FAULT_ERROR--One of the arguments of the preceding function specified an invalid memory address.";
00087   case PR_INVALID_METHOD_ERROR:
00088     return "PR_INVALID_METHOD_ERROR--The preceding function is invalid for the type of file descriptor used.";
00089   case PR_ILLEGAL_ACCESS_ERROR:
00090     return "PR_ILLEGAL_ACCESS_ERROR--One of the arguments of the preceding function specified an invalid memory address.";
00091   case PR_UNKNOWN_ERROR:
00092     return "PR_UNKNOWN_ERROR--Some unknown error has occurred.";
00093   case PR_PENDING_INTERRUPT_ERROR:
00094     return "PR_PENDING_INTERRUPT_ERROR--The operation terminated because another thread has interrupted it with PR_Interrupt.";
00095   case PR_NOT_IMPLEMENTED_ERROR:
00096     return "PR_NOT_IMPLEMENTED_ERROR--The preceding function has not been implemented.";
00097   case PR_IO_ERROR:
00098     return "PR_IO_ERROR--The preceding I/O function encountered some sort of an error, perhaps an invalid device.";
00099   case PR_IO_TIMEOUT_ERROR:
00100     return "PR_IO_TIMEOUT_ERROR--The I/O operation has not completed in the time specified for the preceding function.";
00101   case PR_IO_PENDING_ERROR:
00102     return "PR_IO_PENDING_ERROR--An I/O operation has been attempted on a file descriptor that is currently busy with another operation.";
00103   case PR_DIRECTORY_OPEN_ERROR:
00104     return "PR_DIRECTORY_OPEN_ERROR--The directory could not be opened.";
00105   case PR_INVALID_ARGUMENT_ERROR:
00106     return "PR_INVALID_ARGUMENT_ERROR--One or more of the arguments to the function is invalid.";
00107   case PR_ADDRESS_NOT_AVAILABLE_ERROR:
00108     return "PR_ADDRESS_NOT_AVAILABLE_ERROR--The network address (PRNetAddr) is not available (probably in use).";
00109   case PR_ADDRESS_NOT_SUPPORTED_ERROR:
00110     return "PR_ADDRESS_NOT_SUPPORTED_ERROR--The type of network address specified is not supported.";
00111   case PR_IS_CONNECTED_ERROR:
00112     return "PR_IS_CONNECTED_ERROR--An attempt to connect on an already connected network file descriptor.";
00113   case PR_BAD_ADDRESS_ERROR:
00114     return "PR_BAD_ADDRESS_ERROR--The network address specified is invalid (as reported by the network).";
00115   case PR_ADDRESS_IN_USE_ERROR:
00116     return "PR_ADDRESS_IN_USE_ERROR--Network address specified (PRNetAddr) is in use.";
00117   case PR_CONNECT_REFUSED_ERROR:
00118     return "PR_CONNECT_REFUSED_ERROR--The peer has refused to allow the connection to be established.";
00119   case PR_NETWORK_UNREACHABLE_ERROR:
00120     return "PR_NETWORK_UNREACHABLE_ERROR--The network address specifies a host that is unreachable (perhaps temporary).";
00121   case PR_CONNECT_TIMEOUT_ERROR:
00122     return "PR_CONNECT_TIMEOUT_ERROR--The connection attempt did not complete in a reasonable period of time.";
00123   case PR_NOT_CONNECTED_ERROR:
00124     return "PR_NOT_CONNECTED_ERROR--The preceding function attempted to use connected semantics on a network file descriptor that was not connected.";
00125   case PR_LOAD_LIBRARY_ERROR:
00126     return "PR_LOAD_LIBRARY_ERROR--Failure to load a dynamic library.";
00127   case PR_UNLOAD_LIBRARY_ERROR:
00128     return "PR_UNLOAD_LIBRARY_ERROR--Failure to unload a dynamic library.";
00129   case PR_FIND_SYMBOL_ERROR:
00130     return "PR_FIND_SYMBOL_ERROR--Symbol could not be found in the specified library.";
00131   case PR_INSUFFICIENT_RESOURCES_ERROR:
00132     return "PR_INSUFFICIENT_RESOURCES_ERROR--There are insufficient system resources to process the request.";
00133   case PR_DIRECTORY_LOOKUP_ERROR:
00134     return "PR_DIRECTORY_LOOKUP_ERROR--A directory lookup on a network address has failed.";
00135   case PR_TPD_RANGE_ERROR:
00136     return "PR_TPD_RANGE_ERROR--Attempt to access a thread-private data index that is out of range of any index that has been allocated to the process.";
00137   case PR_PROC_DESC_TABLE_FULL_ERROR:
00138     return "PR_PROC_DESC_TABLE_FULL_ERROR--The process' table for holding open file descriptors is full.";
00139   case PR_SYS_DESC_TABLE_FULL_ERROR:
00140     return "PR_SYS_DESC_TABLE_FULL_ERROR--The system's table for holding open file descriptors has been exceeded.";
00141   case PR_NOT_SOCKET_ERROR:
00142     return "PR_NOT_SOCKET_ERROR--An attempt to use a non-network file descriptor on a network-only operation.";
00143   case PR_NOT_TCP_SOCKET_ERROR:
00144     return "PR_NOT_TCP_SOCKET_ERROR--Attempt to perform a TCP specific function on a non-TCP file descriptor.";
00145   case PR_SOCKET_ADDRESS_IS_BOUND_ERROR:
00146     return "PR_SOCKET_ADDRESS_IS_BOUND_ERROR--Attempt to bind an address to a TCP file descriptor that is already bound.";
00147   case PR_NO_ACCESS_RIGHTS_ERROR:
00148     return "PR_NO_ACCESS_RIGHTS_ERROR--Calling thread does not have privilege to perform the operation requested.";
00149   case PR_OPERATION_NOT_SUPPORTED_ERROR:
00150     return "PR_OPERATION_NOT_SUPPORTED_ERROR--The requested operation is not supported by the platform.";
00151   case PR_PROTOCOL_NOT_SUPPORTED_ERROR:
00152     return "PR_PROTOCOL_NOT_SUPPORTED_ERROR--The host operating system does not support the protocol requested.";
00153   case PR_REMOTE_FILE_ERROR:
00154     return "PR_REMOTE_FILE_ERROR--Access to the remote file has been severed.";
00155   case PR_BUFFER_OVERFLOW_ERROR:
00156     return "PR_BUFFER_OVERFLOW_ERROR--The value retrieved is too large to be stored in the buffer provided.";
00157   case PR_CONNECT_RESET_ERROR:
00158     return "PR_CONNECT_RESET_ERROR--The (TCP) connection has been reset by the peer.";
00159   case PR_RANGE_ERROR:
00160     return "PR_RANGE_ERROR--Unused.";
00161   case PR_DEADLOCK_ERROR:
00162     return "PR_DEADLOCK_ERROR--Performing the requested operation would have caused a deadlock. The deadlock was avoided.";
00163   case PR_FILE_IS_LOCKED_ERROR:
00164     return "PR_FILE_IS_LOCKED_ERROR--An attempt to acquire a lock on a file has failed because the file is already locked.";
00165   case PR_FILE_TOO_BIG_ERROR:
00166     return "PR_FILE_TOO_BIG_ERROR--Completing the write or seek operation would have resulted in a file larger than the system could handle.";
00167   case PR_NO_DEVICE_SPACE_ERROR:
00168     return "PR_NO_DEVICE_SPACE_ERROR--The device for storing the file is full.";
00169   case PR_PIPE_ERROR:
00170     return "PR_PIPE_ERROR--Unused.";
00171   case PR_NO_SEEK_DEVICE_ERROR:
00172     return "PR_NO_SEEK_DEVICE_ERROR--Unused.";
00173   case PR_IS_DIRECTORY_ERROR:
00174     return "PR_IS_DIRECTORY_ERROR--Attempt to perform a normal file operation on a directory.";
00175   case PR_LOOP_ERROR:
00176     return "PR_LOOP_ERROR--Symbolic link loop.";
00177   case PR_NAME_TOO_LONG_ERROR:
00178     return "PR_NAME_TOO_LONG_ERROR--Filename is longer than allowed by the host operating system.";
00179   case PR_FILE_NOT_FOUND_ERROR:
00180     return "PR_FILE_NOT_FOUND_ERROR--The requested file was not found.";
00181   case PR_NOT_DIRECTORY_ERROR:
00182     return "PR_NOT_DIRECTORY_ERROR--Attempt to perform directory specific operations on a normal file.";
00183   case PR_READ_ONLY_FILESYSTEM_ERROR:
00184     return "PR_READ_ONLY_FILESYSTEM_ERROR--Attempt to write to a read-only file system.";
00185   case PR_DIRECTORY_NOT_EMPTY_ERROR:
00186     return "PR_DIRECTORY_NOT_EMPTY_ERROR--Attempt to delete a directory that is not empty.";
00187   case PR_FILESYSTEM_MOUNTED_ERROR:
00188     return "PR_FILESYSTEM_MOUNTED_ERROR--Attempt to delete or rename a file object while the file system is busy.";
00189   case PR_NOT_SAME_DEVICE_ERROR:
00190     return "PR_NOT_SAME_DEVICE_ERROR--Request to rename a file to a file system on another device.";
00191   case PR_DIRECTORY_CORRUPTED_ERROR:
00192     return "PR_DIRECTORY_CORRUPTED_ERROR--The directory object in the file system is corrupted.";
00193   case PR_FILE_EXISTS_ERROR:
00194     return "PR_FILE_EXISTS_ERROR--Attempt to create or rename a file when the new name is already being used.";
00195   case PR_MAX_DIRECTORY_ENTRIES_ERROR:
00196     return "PR_MAX_DIRECTORY_ENTRIES_ERROR--Attempt to add new filename to directory would exceed the limit allowed.";
00197   case PR_INVALID_DEVICE_STATE_ERROR:
00198     return "PR_INVALID_DEVICE_STATE_ERROR--The device was in an invalid state to complete the desired operation.";
00199   case PR_DEVICE_IS_LOCKED_ERROR:
00200     return "PR_DEVICE_IS_LOCKED_ERROR--The device needed to perform the desired request is locked.";
00201   case PR_NO_MORE_FILES_ERROR:
00202     return "PR_NO_MORE_FILES_ERROR--There are no more entries in the directory.";
00203   case PR_END_OF_FILE_ERROR:
00204     return "PR_END_OF_FILE_ERROR--Unexpectedly encountered end of file (Mac OS only).";
00205   case PR_FILE_SEEK_ERROR:
00206     return "PR_FILE_SEEK_ERROR--An unexpected seek error (Mac OS only).";
00207   case PR_FILE_IS_BUSY_ERROR:
00208     return "PR_FILE_IS_BUSY_ERROR--The file is busy and the operation cannot be performed (Mac OS only).";
00209   case PR_IN_PROGRESS_ERROR:
00210     return "PR_IN_PROGRESS_ERROR--The operation is still in progress (probably a nonblocking connect).";
00211   case PR_ALREADY_INITIATED_ERROR:
00212     return "PR_ALREADY_INITIATED_ERROR--The (retried) operation has already been initiated (probably a nonblocking connect).";
00213   case PR_GROUP_EMPTY_ERROR:
00214     return "PR_GROUP_EMPTY_ERROR--The wait group is empty.";
00215   case PR_INVALID_STATE_ERROR:
00216     return "PR_INVALID_STATE_ERROR--The attempted operation is on an object that was in an improper state to perform the request.";
00217 
00218     // These were added with NSPR 4.0.
00219 #ifdef PR_NETWORK_DOWN_ERROR
00220   case PR_NETWORK_DOWN_ERROR:
00221     return "PR_NETWORK_DOWN_ERROR--The network is down.";
00222 
00223   case PR_SOCKET_SHUTDOWN_ERROR:
00224     return "PR_SOCKET_SHUTDOWN_ERROR--The socket has been shut down.";
00225 
00226   case PR_CONNECT_ABORTED_ERROR:
00227     return "PR_CONNECT_ABORTED_ERROR--The connection has been aborted.";
00228 
00229   case PR_HOST_UNREACHABLE_ERROR:
00230     return "PR_HOST_UNREACHABLE_ERROR--The host is unreachable.";
00231 #endif
00232 
00233   case PR_MAX_ERROR:
00234     return "PR_MAX_ERROR--Placeholder for the end of the list.";
00235   }
00236 
00237   return (const char *)NULL;
00238 }

Generated on Fri May 2 00:40:36 2003 for Panda by doxygen1.3