--- smsdaemon/util.cpp 2008/06/15 16:05:14 79 +++ smsdaemon/util.cpp 2008/06/19 14:47:52 107 @@ -9,6 +9,7 @@ #include #include #include +#include #include "util.h" @@ -189,12 +190,17 @@ ostringstream command; command << "wget -O " << tempfile << " --tries=1 --timeout=15 -o /dev/null \"" << url << "\""; - int res = system( command.str().c_str() ); + int res = my_system( command.str().c_str() ); -/* if (res) + if (res<0) { - throw std::runtime_error("Command time out"); - }*/ + throw( std::runtime_error("Error retrieving document")); + } + + if (res>0) + { + throw std::runtime_error("Command time out or document not found"); + } ifstream in( tempfile.c_str() ); @@ -280,7 +286,38 @@ int mTimeDiff(const timeval& then, const timeval& now) { - return uTimeDiff(then,now) / 1000; + return ( (now.tv_sec - then.tv_sec)*1000) + + ((now.tv_usec-then.tv_usec)/1000); + } + + + timeval GetTimeOfDay() + { + timeval now; + gettimeofday(&now,0); + return now; + } + + int my_system(const char* cmd, std::string* response) + { + FILE* p; + if ((p = popen(cmd,"r")) == NULL) + return (-1); + + if (response) + { + std::string output; + char buf[256]; + while(!feof(p)) + { + int len = fread(buf,1,255, p); + buf[len] = 0; + output += buf; + } + *response = output; + } + + return (pclose(p)); } }