Commit cb579718 authored by Matteo Quintiliani's avatar Matteo Quintiliani
Browse files

Improved nmxp_openSocket() adding a parameter to call function for exit condition


git-svn-id: file:///home/quintiliani/svncopy/nmxptool/trunk@1070 3cd66e75-5955-46cb-a940-c26e5fc5497d
parent f92732b0
TODO LIST:
- Improved nmxp_openSocket() in nmxp_base.c
- Add option for output directory dump and mini-seed
- Location code
......
......@@ -7,7 +7,7 @@
* Istituto Nazionale di Geofisica e Vulcanologia - Italy
* quintiliani@ingv.it
*
* $Id: nmxp.h,v 1.51 2008-04-01 08:09:13 mtheo Exp $
* $Id: nmxp.h,v 1.52 2008-04-22 12:53:42 mtheo Exp $
*
*/
......@@ -1163,7 +1163,7 @@ int nmxp_sendDataRequest(int isock, int32_t key, int32_t start_time, int32_t end
* \warning Returned value will need to be freed.
*
*/
NMXP_CHAN_LIST *nmxp_getAvailableChannelList(char * hostname, int portnum, NMXP_DATATYPE datatype);
NMXP_CHAN_LIST *nmxp_getAvailableChannelList(char * hostname, int portnum, NMXP_DATATYPE datatype, int (*func_cond)(void));
/*! \brief Get the list of the start and end time for the available data for each channel.
......@@ -1181,7 +1181,7 @@ NMXP_CHAN_LIST *nmxp_getAvailableChannelList(char * hostname, int portnum, NMXP_
* \warning Returned value will need to be freed.
*
*/
NMXP_META_CHAN_LIST *nmxp_getMetaChannelList(char * hostname, int portnum, NMXP_DATATYPE datatype, int flag_request_channelinfo, char *datas_username, char *datas_password, NMXP_CHAN_LIST **pchannelList);
NMXP_META_CHAN_LIST *nmxp_getMetaChannelList(char * hostname, int portnum, NMXP_DATATYPE datatype, int flag_request_channelinfo, char *datas_username, char *datas_password, NMXP_CHAN_LIST **pchannelList, int (*func_cond)(void));
/*! \brief Base function for qsort() in order to sort an array of pointers to pointers to NMXP_DATA_PROCESS
......
......@@ -7,7 +7,7 @@
* Istituto Nazionale di Geofisica e Vulcanologia - Italy
* quintiliani@ingv.it
*
* $Id: nmxp_base.h,v 1.31 2008-04-01 14:10:05 mtheo Exp $
* $Id: nmxp_base.h,v 1.32 2008-04-22 12:53:42 mtheo Exp $
*
*/
......@@ -37,7 +37,7 @@
* \retval -1 "Empty host name", "Cannot lookup host", ...
*
*/
int nmxp_openSocket(char *hostname, int portNum);
int nmxp_openSocket(char *hostname, int portNum, int (*func_cond)(void));
/*! \brief Close a socket.
......
......@@ -7,7 +7,7 @@
* Istituto Nazionale di Geofisica e Vulcanologia - Italy
* quintiliani@ingv.it
*
* $Id: nmxp.c,v 1.88 2008-04-09 07:57:01 mtheo Exp $
* $Id: nmxp.c,v 1.89 2008-04-22 12:53:42 mtheo Exp $
*
*/
......@@ -456,13 +456,13 @@ int nmxp_sendDataRequest(int isock, int32_t key, int32_t start_time, int32_t end
}
NMXP_CHAN_LIST *nmxp_getAvailableChannelList(char * hostname, int portnum, NMXP_DATATYPE datatype) {
NMXP_CHAN_LIST *nmxp_getAvailableChannelList(char * hostname, int portnum, NMXP_DATATYPE datatype, int (*func_cond)(void)) {
int naqssock;
NMXP_CHAN_LIST *channelList = NULL, *channelList_subset = NULL;
/* int i; */
/* 1. Open a socket*/
naqssock = nmxp_openSocket(hostname, portnum);
naqssock = nmxp_openSocket(hostname, portnum, func_cond);
if(naqssock != NMXP_SOCKET_ERROR) {
......@@ -515,7 +515,7 @@ NMXP_CHAN_LIST *nmxp_getAvailableChannelList(char * hostname, int portnum, NMXP_
}
NMXP_META_CHAN_LIST *nmxp_getMetaChannelList(char * hostname, int portnum, NMXP_DATATYPE datatype, int flag_request_channelinfo, char *datas_username, char *datas_password, NMXP_CHAN_LIST **pchannelList) {
NMXP_META_CHAN_LIST *nmxp_getMetaChannelList(char * hostname, int portnum, NMXP_DATATYPE datatype, int flag_request_channelinfo, char *datas_username, char *datas_password, NMXP_CHAN_LIST **pchannelList, int (*func_cond)(void)) {
int naqssock;
NMXP_CHAN_PRECISLIST *precisChannelList = NULL;
NMXP_CHAN_LIST *channelList = NULL;
......@@ -538,7 +538,7 @@ NMXP_META_CHAN_LIST *nmxp_getMetaChannelList(char * hostname, int portnum, NMXP_
str_end[0] = 0;
/* DAP Step 1: Open a socket */
if( (naqssock = nmxp_openSocket(hostname, portnum)) == NMXP_SOCKET_ERROR) {
if( (naqssock = nmxp_openSocket(hostname, portnum, func_cond)) == NMXP_SOCKET_ERROR) {
nmxp_log(NMXP_LOG_ERR, NMXP_LOG_D_CONNFLOW, "Error opening socket!\n");
return NULL;
}
......
......@@ -7,7 +7,7 @@
* Istituto Nazionale di Geofisica e Vulcanologia - Italy
* quintiliani@ingv.it
*
* $Id: nmxp_base.c,v 1.72 2008-04-01 14:10:05 mtheo Exp $
* $Id: nmxp_base.c,v 1.73 2008-04-22 12:53:42 mtheo Exp $
*
*/
......@@ -39,10 +39,10 @@
#define MAX_OUTDATA 4096
int nmxp_openSocket(char *hostname, int portNum)
int nmxp_openSocket(char *hostname, int portNum, int (*func_cond)(void))
{
static int sleepTime = 1;
int isock = 0;
int isock = -1;
struct hostent *hostinfo = NULL;
struct sockaddr_in psServAddr;
struct in_addr hostaddr;
......@@ -63,7 +63,7 @@ int nmxp_openSocket(char *hostname, int portNum)
return -1;
}
while(1)
while(!func_cond())
{
isock = socket (AF_INET, SOCK_STREAM, 0);
......@@ -100,24 +100,27 @@ int nmxp_openSocket(char *hostname, int portNum)
nmxp_log(NMXP_LOG_NORM, NMXP_LOG_D_CONNFLOW, "Attempting to connect to %s port %d\n",
NMXP_LOG_STR(inet_ntoa(hostaddr)), portNum);
if (connect(isock, (struct sockaddr *)&psServAddr, sizeof(psServAddr)) >= 0)
{
sleepTime = 1;
nmxp_log(NMXP_LOG_NORM, NMXP_LOG_D_CONNFLOW, "Connection established: socket=%i,IP=%s,port=%d\n",
isock, NMXP_LOG_STR(inet_ntoa(hostaddr)), portNum);
return isock;
}
else
{
nmxp_log(NMXP_LOG_ERR, NMXP_LOG_D_CONNFLOW, "Connecting to %s port %d. Trying again after %d seconds...\n",
NMXP_LOG_STR(inet_ntoa(hostaddr)), portNum, sleepTime);
nmxp_closeSocket(isock);
nmxp_sleep (sleepTime);
sleepTime *= 2;
if (sleepTime > NMXP_SLEEPMAX)
sleepTime = NMXP_SLEEPMAX;
if(connect(isock, (struct sockaddr *)&psServAddr, sizeof(psServAddr)) >= 0) {
sleepTime = 1;
nmxp_log(NMXP_LOG_NORM, NMXP_LOG_D_CONNFLOW, "Connection established: socket=%i,IP=%s,port=%d\n",
isock, NMXP_LOG_STR(inet_ntoa(hostaddr)), portNum);
return isock;
} else {
nmxp_log(NMXP_LOG_ERR, NMXP_LOG_D_CONNFLOW, "Connecting to %s port %d. Trying again after %d seconds...\n",
NMXP_LOG_STR(inet_ntoa(hostaddr)), portNum, sleepTime);
nmxp_closeSocket(isock);
isock = -1;
if(!func_cond()) {
nmxp_sleep (sleepTime);
sleepTime *= 2;
if (sleepTime > NMXP_SLEEPMAX)
sleepTime = NMXP_SLEEPMAX;
}
}
}
return isock;
}
......
......@@ -7,7 +7,7 @@
* Istituto Nazionale di Geofisica e Vulcanologia - Italy
* quintiliani@ingv.it
*
* $Id: nmxptool.c,v 1.191 2008-04-11 12:21:23 mtheo Exp $
* $Id: nmxptool.c,v 1.192 2008-04-22 12:53:42 mtheo Exp $
*
*/
......@@ -227,13 +227,13 @@ int main (int argc, char **argv) {
/* List available channels on server */
if(params.flag_listchannels) {
nmxp_meta_chan_print(nmxp_getMetaChannelList(params.hostname, params.portnumberdap, NMXP_DATA_TIMESERIES, params.flag_request_channelinfo, params.datas_username, params.datas_password, &channelList));
nmxp_meta_chan_print(nmxp_getMetaChannelList(params.hostname, params.portnumberdap, NMXP_DATA_TIMESERIES, params.flag_request_channelinfo, params.datas_username, params.datas_password, &channelList, nmxptool_sigcondition_read));
return 1;
} else if(params.flag_listchannelsnaqs) {
channelList = nmxp_getAvailableChannelList(params.hostname, params.portnumberpds, NMXP_DATA_TIMESERIES);
channelList = nmxp_getAvailableChannelList(params.hostname, params.portnumberpds, NMXP_DATA_TIMESERIES, nmxptool_sigcondition_read);
nmxp_chan_print_channelList(channelList);
return 1;
......@@ -301,12 +301,12 @@ int main (int argc, char **argv) {
if_dap_condition_only_one_time = 1;
/* From DataServer */
if(!nmxp_getMetaChannelList(params.hostname, params.portnumberdap, NMXP_DATA_TIMESERIES,
params.flag_request_channelinfo, params.datas_username, params.datas_password, &channelList)) {
params.flag_request_channelinfo, params.datas_username, params.datas_password, &channelList, nmxptool_sigcondition_read)) {
return -1;
}
} else {
/* From NaqsServer */
channelList = nmxp_getAvailableChannelList(params.hostname, params.portnumberpds, NMXP_DATA_TIMESERIES);
channelList = nmxp_getAvailableChannelList(params.hostname, params.portnumberpds, NMXP_DATA_TIMESERIES, nmxptool_sigcondition_read);
}
if(!channelList) {
......@@ -413,7 +413,7 @@ int main (int argc, char **argv) {
/* ************************************************************** */
/* DAP Step 1: Open a socket */
if( (naqssock = nmxp_openSocket(params.hostname, params.portnumberdap)) == NMXP_SOCKET_ERROR) {
if( (naqssock = nmxp_openSocket(params.hostname, params.portnumberdap, nmxptool_sigcondition_read)) == NMXP_SOCKET_ERROR) {
nmxp_log(NMXP_LOG_ERR, NMXP_LOG_D_CONNFLOW, "Error opening socket!\n");
return 1;
}
......@@ -719,7 +719,7 @@ int main (int argc, char **argv) {
/* ************************************************************* */
/* PDS Step 1: Open a socket */
naqssock = nmxp_openSocket(params.hostname, params.portnumberpds);
naqssock = nmxp_openSocket(params.hostname, params.portnumberpds, nmxptool_sigcondition_read);
if(naqssock == NMXP_SOCKET_ERROR) {
return 1;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment