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 #ifndef alarm_handler_h
00027 #define alarm_handler_h
00028
00029 #include <cstdio>
00030
00031 #include <string>
00032
00033 #include "EventHandler.h"
00034
00035 namespace libdap
00036 {
00037
00045 class AlarmHandler : public EventHandler
00046 {
00047 private:
00048
00049 FILE *d_file;
00050
00051 ostream &d_stream;
00052 string d_version;
00053
00054
00055 AlarmHandler() :
00056
00057 d_file( 0 ),
00058
00059 d_stream( cout )
00060 {}
00061
00062 public:
00065
00066 AlarmHandler(FILE *s) : d_file(s), d_stream( cout )
00067 {}
00068
00069 AlarmHandler(ostream &out) :
00070
00071 d_file(0),
00072
00073 d_stream( out )
00074 {}
00075
00076 virtual ~AlarmHandler()
00077 {
00078
00079 if( d_file )
00080 fclose( d_file ) ;
00081
00082 }
00083
00096 virtual void handle_signal(int signum)
00097 {
00098 if (signum != SIGALRM)
00099 fprintf(stderr, "SIGALRM handler caught another signal!\n");
00100 #if 0
00101
00102 if( d_file )
00103 fprintf(d_file, "\n\n\n\n");
00104 else
00105 d_stream << "\n\n\n\n";
00106
00107 Error e("The server has timed out. This happens when a request\n\
00108 takes longer to process than the server's preset time-out value.\n\
00109 Try making a request for a smaller amount of data. You can also contact\n\
00110 the server's administrator and request that the time-out value be increased.");
00111
00112 if( d_file )
00113 e.print(d_file);
00114 else
00115 e.print(d_stream);
00116 #endif
00117 exit(1);
00118 }
00119
00120 };
00121
00122 }
00123
00124 #endif