summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKostyantyn Ovechko <fastinetserver@gmail.com>2010-08-16 00:20:29 +0300
committerKostyantyn Ovechko <fastinetserver@gmail.com>2010-08-16 00:20:29 +0300
commit6706397e1a1808ee23eedab9292bc648eb570d15 (patch)
tree9eb14af714b37f7c71fd902589677b8c3f4dab94
parentAdd show_help() function and remove deprecated code lines. (diff)
downloadidfetch-6706397e1a1808ee23eedab9292bc648eb570d15.tar.gz
idfetch-6706397e1a1808ee23eedab9292bc648eb570d15.tar.bz2
idfetch-6706397e1a1808ee23eedab9292bc648eb570d15.zip
Add try...catch blocks to a few functions in request tool
-rw-r--r--request/phase.cpp18
-rw-r--r--request/request.cpp141
-rw-r--r--request/str.cpp22
-rw-r--r--seggetd/distfile.cpp25
4 files changed, 69 insertions, 137 deletions
diff --git a/request/phase.cpp b/request/phase.cpp
index 04aef35..e45fabb 100644
--- a/request/phase.cpp
+++ b/request/phase.cpp
@@ -25,13 +25,19 @@
*/
#include "phase.h"
+#include "utils.h"
string phaseToString(int phase_num){
- switch(phase_num){
- case E_USE_AS_LOCAL_MIRRORS: return "E_USE_AS_LOCAL_MIRRORS";
- case E_ALL_LOCAL_MIRRORS_FAILED: return "E_ALL_LOCAL_MIRRORS_FAILED";
- case E_PROXY_FETCHER_DOWNLOADED: return "E_PROXY_FETCHER_DOWNLOADED";
- case E_ALL_PROXY_FETCHER_MIRRORS_FAILED: return "E_ALL_PROXY_FETCHER_MIRRORS_FAILED";
- default: return "Unknown phase";
+ try{
+ switch(phase_num){
+ case E_USE_AS_LOCAL_MIRRORS: return "E_USE_AS_LOCAL_MIRRORS";
+ case E_ALL_LOCAL_MIRRORS_FAILED: return "E_ALL_LOCAL_MIRRORS_FAILED";
+ case E_PROXY_FETCHER_DOWNLOADED: return "E_PROXY_FETCHER_DOWNLOADED";
+ case E_ALL_PROXY_FETCHER_MIRRORS_FAILED: return "E_ALL_PROXY_FETCHER_MIRRORS_FAILED";
+ default: return "Unknown phase";
+ }
+ }catch(...){
+ printout("Error in phase.cpp: phaseToString()");
+ return "Unknown phase";
}
}
diff --git a/request/request.cpp b/request/request.cpp
index b5a400b..4dc4caf 100644
--- a/request/request.cpp
+++ b/request/request.cpp
@@ -27,64 +27,69 @@
#include "request.h"
int request(string msg){
- int len;
- struct sockaddr_in address;
- int result;
- //Create a socket for the client:
- sockfd = socket(AF_INET, SOCK_STREAM, 0);
+ try{
+ int len;
+ struct sockaddr_in address;
+ int result;
+ //Create a socket for the client:
+ sockfd = socket(AF_INET, SOCK_STREAM, 0);
- //Name the socket, as agreed with the server:
- address.sin_family = AF_INET;
- address.sin_addr.s_addr = inet_addr(settings.request_ip.c_str());
- address.sin_port = htons(settings.request_port);
- len = sizeof(address);
+ //Name the socket, as agreed with the server:
+ address.sin_family = AF_INET;
+ address.sin_addr.s_addr = inet_addr(settings.request_ip.c_str());
+ address.sin_port = htons(settings.request_port);
+ len = sizeof(address);
- //Connect your socket to the server’s socket:
- result = connect(sockfd, (struct sockaddr *)&address, len);
- if(result == -1) {
- printout("Can't connect to segget daemon");
- return R_PF_ERROR_ADDING_TO_PROXY_QUEUE;
- }
- if (msg.length()>90000){return R_PF_ERROR_ADDING_TO_PROXY_QUEUE;};
- char send_buffer[100000];
+ //Connect your socket to the server’s socket:
+ result = connect(sockfd, (struct sockaddr *)&address, len);
+ if(result == -1) {
+ printout("Can't connect to segget daemon");
+ return R_PF_ERROR_ADDING_TO_PROXY_QUEUE;
+ }
+ if (msg.length()>90000){return R_PF_ERROR_ADDING_TO_PROXY_QUEUE;};
+ char send_buffer[100000];
+
+ strcpy(send_buffer,msg.c_str());
+ //You can now read and write via sockfd:
+ if (write(sockfd, send_buffer, strlen(send_buffer))!=(int)msg.length()){
+ printout("Error in request.cpp: request(): request msg size and sent data size are different.");
+ };
- strcpy(send_buffer,msg.c_str());
- //You can now read and write via sockfd:
- if (write(sockfd, send_buffer, strlen(send_buffer))!=(int)msg.length()){
- printout("Error in request.cpp: request(): request msg size and sent data size are different.");
- };
+ fd_set readfds, testfds;
+ FD_ZERO(&readfds);
+ FD_SET(sockfd, &readfds);
+ testfds = readfds;
- fd_set readfds, testfds;
- FD_ZERO(&readfds);
- FD_SET(sockfd, &readfds);
- testfds = readfds;
+ struct timeval response_timeout;
+ response_timeout.tv_sec=1;
+ response_timeout.tv_usec=0;
- struct timeval response_timeout;
- response_timeout.tv_sec=1;
- response_timeout.tv_usec=0;
-
- result = select(FD_SETSIZE, &testfds, (fd_set *)0,
- (fd_set *)0, &response_timeout);
+ result = select(FD_SETSIZE, &testfds, (fd_set *)0,
+ (fd_set *)0, &response_timeout);
- if(FD_ISSET(sockfd,&testfds)) {
- int nread;
- ioctl(sockfd, FIONREAD, &nread);
+ if(FD_ISSET(sockfd,&testfds)) {
+ int nread;
+ ioctl(sockfd, FIONREAD, &nread);
- char recv_buffer[1000];
- if(nread == 0) {
- close(sockfd);
- printout("Error in request.cpp: request(): no response from segget daemon");
+ char recv_buffer[1000];
+ if(nread == 0) {
+ close(sockfd);
+ printout("Error in request.cpp: request(): no response from segget daemon");
+ }else{
+ if (nread!=read(sockfd, recv_buffer, nread)){
+ printout("Error in request.cpp: request(): response msg size and received data size are different.");
+ };
+ return decode_server_response(recv_buffer);
+ }
}else{
- if (nread!=read(sockfd, recv_buffer, nread)){
- printout("Error in request.cpp: request(): response msg size and received data size are different.");
- };
- return decode_server_response(recv_buffer);
+ printout("Error in request.cpp: request(): zero size response from segget daemon");
}
- }else{
- printout("Error in request.cpp: request(): zero size response from segget daemon");
+ close(sockfd);
+ return R_PF_ERROR_ADDING_TO_PROXY_QUEUE;
+ }catch(...){
+ printout("Error: request.cpp: request()");
+ return R_PF_ERROR_ADDING_TO_PROXY_QUEUE;
}
- close(sockfd);
- return R_PF_ERROR_ADDING_TO_PROXY_QUEUE;
}
int load_pkgs(){
@@ -151,29 +156,9 @@ int load_pkgs(){
return 1;
}
}
-/*
-void show_pkgs(){
- try{
- for (uint array_item_num=0;array_item_num<stats.pkg_count;array_item_num++){
- cout <<"PKG:"<<array_item_num<<") cat:"<< Ppkg_array[array_item_num]->category <<" name:"<< Ppkg_array[array_item_num]->name <<"\n";
- for(uint distfile_array_item_num=0;distfile_array_item_num<Ppkg_array[array_item_num]->distfile_count;distfile_array_item_num++){
- cout << " "<< distfile_array_item_num<<") distfile_name:"<< Ppkg_array[array_item_num]->Pdistfile_list[distfile_array_item_num]->name<<"\n";
- for(uint urllist_array_item_num=0;urllist_array_item_num<Ppkg_array[array_item_num]->Pdistfile_list[distfile_array_item_num]->url_count;urllist_array_item_num++){
- cout <<" "<<Ppkg_array[array_item_num]->Pdistfile_list[distfile_array_item_num]->url_list[urllist_array_item_num]<<"\n";
- }
- }
- }
- }catch(...){
- error_log("Error in segget.cpp: show_pkgs()");
- }
-}
-*/
void _exit(int sig){
try{
-// for(uint fd = 0; fd <= ui_server.max_fd_num; fd++) {
-// close(fd);
-// }
close(sockfd);
}
catch(...)
@@ -202,17 +187,10 @@ int routine(){
}catch(...){
//error while loading pkgs
}
-/*
- try{
- //show_pkgs();
- }catch(...){
- //error while showing stats
- }
-*/
return 0;
}catch(...)
{
- printout("Error in segget.cpp: routine()");
+ printout("Error in request.cpp: routine()");
}
return 1;
}
@@ -227,19 +205,14 @@ void show_help(){
printout("--pkglist-file=PATH_TO_PKGLIST_FILE Specify path to pkg.list file. By default it's /var/tmp/seggetd/pkg.list");
printout("");
}catch(...){
- printout("Error in segget.cpp: init_curses()");
+ printout("Error in request.cpp: show_help()");
}
}
int parse_cli_arguments(int argc, char* argv[]){
try{
string option,name,value;
-// cout << "argc = " << argc << endl;
int posEqual;
-// for(int i = 0; i < argc; i++){
-// cout << "argv[" << i << "] = " << argv[i] << endl;
-// }
-// printout("");
for(int i = 0; i < argc; i++){
option=argv[i];
posEqual=option.find('=');
@@ -252,7 +225,7 @@ int parse_cli_arguments(int argc, char* argv[]){
}
return 0;
}catch(...){
- printout("Error in segget.cpp: init_curses()");
+ printout("Error in request.cpp: init_curses()");
}
return 1;
}
@@ -264,7 +237,7 @@ int main(int argc, char* argv[])
routine();
exit (0);
}catch(...){
- printout("Error in segget.cpp main()");
+ printout("Error in request.cpp main()");
}
exit(1);
} \ No newline at end of file
diff --git a/request/str.cpp b/request/str.cpp
index d86d12c..bbb4e59 100644
--- a/request/str.cpp
+++ b/request/str.cpp
@@ -51,28 +51,6 @@ string toString(bool t){
s << t;
return s.str();
}
-/*
-template<typename T> string toString(T t){
- stringstream s;
- s << t;
- return s.str();
-}
-*/
-/*
-template<typename T> string field(string prefix,T t, int width){
- try{
- stringstream s1,s2;
- s1 << t;
- width=width+prefix.length();
- s2.width(width);
- s2 << prefix+s1.str();
- return s2.str();
- }catch(...){
- error_log("Error in str.cpp: field()");
- return "";
- }
-}
-*/
string field(string prefix,ulong t, int width){
try{
stringstream s1,s2;
diff --git a/seggetd/distfile.cpp b/seggetd/distfile.cpp
index e28528a..5e1d55e 100644
--- a/seggetd/distfile.cpp
+++ b/seggetd/distfile.cpp
@@ -34,31 +34,6 @@
//Make the necessary includes and set up the variables:
using namespace std;
-/*
-#define R_LM_WAIT_FOR_LOCAL_MIRRORS 100
-
-#define R_PF_ADDED_TO_PROXY_QUEUE 101
-#define R_PF_ALREADY_WAS_IN_QUEUE 102
-#define R_PF_DOWNLOADED 103
-#define R_PF_BE_MORE_PATIENT 104
-#define R_PF_ERROR_ADDING_TO_PROXY_QUEUE 105
-#define R_PF_FAILED 106
-#define R_PF_REJECTED 107
-
-// 0 for succesfull return of provide_segment()
-#define R_R_DOWNLOAD_STARTED 0
-#define R_R_WAITING 108
-#define R_R_DOWNLOADING 109
-
-#define R_LM_PF_R_NO_FREE_NETWORK_CONNECTION_FOUND 110
-
-#define ALLOW_PROXY_FETCHER_NETWORKS 201
-#define DO_NOT_ALLOW_PROXY_FETCHER_NETWORKS 202
-#define ALLOW_REMOTE_NETWORKS 203
-#define DO_NOT_ALLOW_REMOTE_NETWORKS 204
-#define ALLOW_LOWER_PRIORITY_NETWORKS 205
-*/
-
string Tdistfile::statusToString(){
try{
switch(status){