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 FILE *d_file;
00049 ostream &d_stream;
00050 string d_version;
00051
00052
00053 AlarmHandler() : d_file( 0 ), d_stream( cout )
00054 {}
00055
00056 public:
00059 AlarmHandler(FILE *s) : d_file(s), d_stream( cout )
00060 {}
00061
00062 AlarmHandler(ostream &out) : d_file(0), d_stream( out )
00063 {}
00064
00065 virtual ~AlarmHandler()
00066 {
00067 if( d_file )
00068 fclose( d_file ) ;
00069 }
00070
00083 virtual void handle_signal(int signum)
00084 {
00085 if (signum != SIGALRM)
00086 fprintf(stderr, "SIGALRM handler caught another signal!\n");
00087 #if 0
00088
00089 if( d_file )
00090 fprintf(d_file, "\n\n\n\n");
00091 else
00092 d_stream << "\n\n\n\n";
00093
00094 Error e("The server has timed out. This happens when a request\n\
00095 takes longer to process than the server's preset time-out value.\n\
00096 Try making a request for a smaller amount of data. You can also contact\n\
00097 the server's administrator and request that the time-out value be increased.");
00098
00099 if( d_file )
00100 e.print(d_file);
00101 else
00102 e.print(d_stream);
00103 #endif
00104 exit(1);
00105 }
00106
00107 };
00108
00109 }
00110
00111 #endif