Prevent the user from sending a SIGINT while downloading a file..

pull/40/head
Massimo Gengarelli 2012-05-01 19:47:25 +02:00
parent 95133eff57
commit 2791bbbfe8
2 changed files with 16 additions and 0 deletions

View File

@ -18,6 +18,7 @@
*/
#include "Download.hh"
#include "../util/SignalHandler.hh"
#include <openssl/evp.h>
@ -57,6 +58,9 @@ Download::~Download( )
std::string Download::Finish() const
{
// Unregister the signal
SignalHandler::GetInstance().UnregisterSignal( SIGINT ) ;
std::string result ;
// get the checksum and return it ;

View File

@ -20,6 +20,7 @@
#include "HTTP.hh"
#include "Download.hh"
#include "../util/SignalHandler.hh"
// dependent libraries
#include <curl/curl.h>
@ -109,6 +110,14 @@ void DoCurl( CURL *curl )
}
}
// Callback for SIGINT
void CallbackInt( int )
{
// TODO: instead of just disabling the signal, clean up the environment
// and exit gracefully
std::cout << " Signal disabled while downloading file..\n";
}
} // end of local namespace
namespace gr { namespace http {
@ -139,6 +148,9 @@ void GetFile(
const std::string& filename,
const Headers& hdr )
{
// Register the callback
SignalHandler::GetInstance().RegisterSignal( SIGINT, &CallbackInt ) ;
Download dl( filename, Download::NoChecksum() ) ;
CURL *curl = InitCurl( url, 0, hdr ) ;