INFO: The new Git default branch name is "main". Details here: https://about.gitlab.com/blog/2021/03/10/new-git-default-branch-name/

Commit 7a23592c authored by Matteo Quintiliani's avatar Matteo Quintiliani
Browse files

Added time-out management


git-svn-id: file:///home/quintiliani/svncopy/nmxptool/trunk@425 3cd66e75-5955-46cb-a940-c26e5fc5497d
parent 41e82755
......@@ -7,7 +7,7 @@
* Istituto Nazionale di Geofisica e Vulcanologia - Italy
* quintiliani@ingv.it
*
* $Id: nmxp.h,v 1.40 2007-10-07 14:48:56 mtheo Exp $
* $Id: nmxp.h,v 1.41 2007-10-07 18:13:39 mtheo Exp $
*
*/
......@@ -1025,6 +1025,7 @@ typedef struct {
double last_sample_time;
int32_t max_pdlist_items;
double max_tollerable_latency;
int timeoutrecv;
int32_t n_pdlist;
NMXP_DATA_PROCESS **pdlist; /* Array for pd queue */
} NMXP_RAW_STREAM_DATA;
......@@ -1094,7 +1095,7 @@ int nmxp_sendAddTimeSeriesChannel(int isock, NMXP_CHAN_LIST_NET *channelList, in
* \retval NULL on error
*
*/
NMXP_DATA_PROCESS *nmxp_receiveData(int isock, NMXP_CHAN_LIST_NET *channelList, const char *network_code);
NMXP_DATA_PROCESS *nmxp_receiveData(int isock, NMXP_CHAN_LIST_NET *channelList, const char *network_code, int timeoutsec, int *recv_errno );
/*! \brief Sends the message "ConnectRequest" on a socket
......@@ -1189,9 +1190,10 @@ int nmxp_raw_stream_seq_no_compare(const void *a, const void *b);
*
* \param raw_stream_buffer pointer to NMXP_RAW_STREAM_DATA struct to initialize
* \param max_pdlist_items value of max number of items in array
* \param timeoutrecv value of time-out within receving packets
*
*/
void nmxp_raw_stream_init(NMXP_RAW_STREAM_DATA *raw_stream_buffer, int32_t max_tollerable_latency);
void nmxp_raw_stream_init(NMXP_RAW_STREAM_DATA *raw_stream_buffer, int32_t max_tollerable_latency, int timeoutrecv);
/*! \brief Free fields inside a NMXP_RAW_STREAM_DATA structure
......
......@@ -7,7 +7,7 @@
* Istituto Nazionale di Geofisica e Vulcanologia - Italy
* quintiliani@ingv.it
*
* $Id: nmxp_base.h,v 1.23 2007-10-07 14:11:23 mtheo Exp $
* $Id: nmxp_base.h,v 1.24 2007-10-07 18:13:39 mtheo Exp $
*
*/
......@@ -69,6 +69,8 @@ int nmxp_send_ctrl(int isock, void *buffer, int length);
* \param isock A descriptor referencing the socket.
* \param[out] buffer Data buffer.
* \param length Length in bytes.
* \param timeoutsec Time-out in seconds
* \param[out] errno errno value after recv()
*
* \warning Data buffer it has to be allocated before and big enough to contain length bytes!
*
......@@ -76,7 +78,7 @@ int nmxp_send_ctrl(int isock, void *buffer, int length);
* \retval NMXP_SOCKET_ERROR on error
*
*/
int nmxp_recv_ctrl(int isock, void *buffer, int length);
int nmxp_recv_ctrl(int isock, void *buffer, int length, int timeoutsec, int *recv_errno );
/*! \brief Sends header of a message.
......@@ -102,7 +104,7 @@ int nmxp_sendHeader(int isock, NMXP_MSG_CLIENT type, int32_t length);
* \retval NMXP_SOCKET_ERROR on error
*
*/
int nmxp_receiveHeader(int isock, NMXP_MSG_SERVER *type, int32_t *length);
int nmxp_receiveHeader(int isock, NMXP_MSG_SERVER *type, int32_t *lengthi, int timeoutsec, int *recv_errno );
/*! \brief Sends header and body of a message.
......@@ -132,7 +134,7 @@ int nmxp_sendMessage(int isock, NMXP_MSG_CLIENT type, void *buffer, int32_t leng
* \retval NMXP_SOCKET_ERROR on error
*
*/
int nmxp_receiveMessage(int isock, NMXP_MSG_SERVER *type, void **buffer, int32_t *length);
int nmxp_receiveMessage(int isock, NMXP_MSG_SERVER *type, void **buffer, int32_t *length, int timeoutsec, int *recv_errno );
/*! \brief Process Compressed Data message by function func_processData().
......
......@@ -7,7 +7,7 @@
* Istituto Nazionale di Geofisica e Vulcanologia - Italy
* quintiliani@ingv.it
*
* $Id: nmxp.c,v 1.49 2007-10-07 14:11:23 mtheo Exp $
* $Id: nmxp.c,v 1.50 2007-10-07 18:13:39 mtheo Exp $
*
*/
......@@ -30,6 +30,7 @@ int nmxp_sendTerminateSubscription(int isock, NMXP_SHUTDOWN_REASON reason, char
int nmxp_receiveChannelList(int isock, NMXP_CHAN_LIST **pchannelList) {
int ret;
int i;
int recv_errno;
NMXP_MSG_SERVER type;
void *buffer;
......@@ -37,7 +38,7 @@ int nmxp_receiveChannelList(int isock, NMXP_CHAN_LIST **pchannelList) {
*pchannelList = NULL;
ret = nmxp_receiveMessage(isock, &type, &buffer, &length);
ret = nmxp_receiveMessage(isock, &type, &buffer, &length, 0, &recv_errno);
if(type != NMXP_MSG_CHANNELLIST) {
nmxp_log(1, 0, "Type %d is not NMXP_MSG_CHANNELLIST!\n", type);
......@@ -100,13 +101,13 @@ int nmxp_sendAddTimeSeriesChannel(int isock, NMXP_CHAN_LIST_NET *channelList, in
}
NMXP_DATA_PROCESS *nmxp_receiveData(int isock, NMXP_CHAN_LIST_NET *channelList, const char *network_code) {
NMXP_DATA_PROCESS *nmxp_receiveData(int isock, NMXP_CHAN_LIST_NET *channelList, const char *network_code, int timeoutsec, int *recv_errno ) {
NMXP_MSG_SERVER type;
void *buffer = NULL;
int32_t length;
NMXP_DATA_PROCESS *pd = NULL;
if(nmxp_receiveMessage(isock, &type, &buffer, &length) == NMXP_SOCKET_OK) {
if(nmxp_receiveMessage(isock, &type, &buffer, &length, timeoutsec, recv_errno) == NMXP_SOCKET_OK) {
if(type == NMXP_MSG_COMPRESSED) {
nmxp_log(0, 1, "Type %d is NMXP_MSG_COMPRESSED!\n", type);
pd = nmxp_processCompressedData(buffer, length, channelList, network_code);
......@@ -165,7 +166,8 @@ int nmxp_sendConnectRequest(int isock, char *naqs_username, char *naqs_password,
int nmxp_readConnectionTime(int isock, int32_t *connection_time) {
int ret;
ret = nmxp_recv_ctrl(isock, connection_time, sizeof(int32_t));
int recv_errno;
ret = nmxp_recv_ctrl(isock, connection_time, sizeof(int32_t), 0, &recv_errno);
*connection_time = ntohl(*connection_time);
nmxp_log(0, 1, "Read connection time from socket %d.\n", *connection_time);
if(ret != NMXP_SOCKET_OK) {
......@@ -181,14 +183,15 @@ int nmxp_waitReady(int isock) {
int32_t signature;
int32_t type = 0;
int32_t length;
int recv_errno;
while(rc == NMXP_SOCKET_OK && type != NMXP_MSG_READY) {
rc = nmxp_recv_ctrl(isock, &signature, sizeof(signature));
rc = nmxp_recv_ctrl(isock, &signature, sizeof(signature), 0, &recv_errno);
if(rc != NMXP_SOCKET_OK) return rc;
signature = ntohl(signature);
if(signature == 0) {
nmxp_log(0, 1, "signature is equal to zero. receive again.\n");
rc = nmxp_recv_ctrl(isock, &signature, sizeof(signature));
rc = nmxp_recv_ctrl(isock, &signature, sizeof(signature), 0, &recv_errno);
signature = ntohl(signature);
}
if(signature != NMX_SIGNATURE) {
......@@ -197,12 +200,12 @@ int nmxp_waitReady(int isock) {
int32_t err_length;
int32_t err_reason;
char err_buff[200];
rc = nmxp_recv_ctrl(isock, &err_length, sizeof(err_length));
rc = nmxp_recv_ctrl(isock, &err_length, sizeof(err_length), 0, &recv_errno);
err_length = ntohl(err_length);
rc = nmxp_recv_ctrl(isock, &err_reason, sizeof(err_reason));
rc = nmxp_recv_ctrl(isock, &err_reason, sizeof(err_reason), 0, &recv_errno);
err_reason = ntohl(err_reason);
if(err_length > 4) {
rc = nmxp_recv_ctrl(isock, err_buff, err_length-4);
rc = nmxp_recv_ctrl(isock, err_buff, err_length-4, 0, &recv_errno);
err_buff[err_length] = 0;
}
nmxp_log(1, 0, "TerminateMessage from Server: %s (%d).\n", err_buff, err_reason);
......@@ -210,31 +213,31 @@ int nmxp_waitReady(int isock) {
return NMXP_SOCKET_ERROR;
}
rc = nmxp_recv_ctrl(isock, &type, sizeof(type));
rc = nmxp_recv_ctrl(isock, &type, sizeof(type), 0, &recv_errno);
if(rc != NMXP_SOCKET_OK) return rc;
type = ntohl(type);
if(type != NMXP_MSG_READY) {
nmxp_log(0, 1, "type is not READY. type = %d\n", type);
rc = nmxp_recv_ctrl(isock, &length, sizeof(length));
rc = nmxp_recv_ctrl(isock, &length, sizeof(length), 0, &recv_errno);
if(rc != NMXP_SOCKET_OK) return rc;
length = ntohl(length);
if(length > 0) {
if(length == 4) {
int32_t app;
rc = nmxp_recv_ctrl(isock, &app, length);
rc = nmxp_recv_ctrl(isock, &app, length, 0, &recv_errno);
if(rc != NMXP_SOCKET_OK) return rc;
app = ntohl(app);
nmxp_log(0, 1, "value = %d\n", app);
} else {
char *buf_app = (char *) malloc(sizeof(char) * length);
rc = nmxp_recv_ctrl(isock, buf_app, length);
rc = nmxp_recv_ctrl(isock, buf_app, length, 0, &recv_errno);
if(buf_app) {
free(buf_app);
}
}
}
} else {
rc = nmxp_recv_ctrl(isock, &length, sizeof(length));
rc = nmxp_recv_ctrl(isock, &length, sizeof(length), 0, &recv_errno);
if(rc != NMXP_SOCKET_OK) return rc;
length = ntohl(length);
if(length != 0) {
......@@ -337,6 +340,7 @@ NMXP_META_CHAN_LIST *nmxp_getMetaChannelList(char * hostname, int portnum, NMXP_
int32_t connection_time;
char *datas_username = NULL, *datas_password = NULL;
int ret_sock;
int recv_errno;
NMXP_MSG_SERVER type;
......@@ -381,7 +385,7 @@ NMXP_META_CHAN_LIST *nmxp_getMetaChannelList(char * hostname, int portnum, NMXP_
/* DAP Step 5: Send Data Request */
nmxp_sendHeader(naqssock, NMXP_MSG_CHANNELLISTREQUEST, 0);
/* DAP Step 6: Receive Data until receiving a Ready message */
ret_sock = nmxp_receiveMessage(naqssock, &type, &buffer, &length);
ret_sock = nmxp_receiveMessage(naqssock, &type, &buffer, &length, 0, &recv_errno);
nmxp_log(0, 1, "ret_sock = %d, type = %d, length = %d\n", ret_sock, type, length);
while(ret_sock == NMXP_SOCKET_OK && type != NMXP_MSG_READY) {
......@@ -397,7 +401,7 @@ NMXP_META_CHAN_LIST *nmxp_getMetaChannelList(char * hostname, int portnum, NMXP_
}
/* Receive Message */
ret_sock = nmxp_receiveMessage(naqssock, &type, &buffer, &length);
ret_sock = nmxp_receiveMessage(naqssock, &type, &buffer, &length, 0, &recv_errno);
nmxp_log(0, 1, "ret_sock = %d, type = %d, length = %d\n", ret_sock, type, length);
}
......@@ -410,7 +414,7 @@ NMXP_META_CHAN_LIST *nmxp_getMetaChannelList(char * hostname, int portnum, NMXP_
/* DAP Step 6: Receive Data until receiving a Ready message */
ret_sock = nmxp_receiveMessage(naqssock, &type, &buffer, &length);
ret_sock = nmxp_receiveMessage(naqssock, &type, &buffer, &length, 0, &recv_errno);
nmxp_log(0, 1, "ret_sock = %d, type = %d, length = %d\n", ret_sock, type, length);
while(ret_sock == NMXP_SOCKET_OK && type != NMXP_MSG_READY) {
......@@ -438,7 +442,7 @@ NMXP_META_CHAN_LIST *nmxp_getMetaChannelList(char * hostname, int portnum, NMXP_
}
/* Receive Message */
ret_sock = nmxp_receiveMessage(naqssock, &type, &buffer, &length);
ret_sock = nmxp_receiveMessage(naqssock, &type, &buffer, &length, 0, &recv_errno);
nmxp_log(0, 1, "ret_sock = %d, type = %d, length = %d\n", ret_sock, type, length);
}
......@@ -453,7 +457,7 @@ NMXP_META_CHAN_LIST *nmxp_getMetaChannelList(char * hostname, int portnum, NMXP_
nmxp_sendMessage(naqssock, NMXP_MSG_CHANNELINFOREQUEST, &channelInfoRequestBody, sizeof(NMXP_MSGBODY_CHANNELINFOREQUEST));
/* DAP Step 6: Receive Data until receiving a Ready message */
ret_sock = nmxp_receiveMessage(naqssock, &type, &buffer, &length);
ret_sock = nmxp_receiveMessage(naqssock, &type, &buffer, &length, 0, &recv_errno);
nmxp_log(0, 1, "ret_sock = %d, type = %d, length = %d\n", ret_sock, type, length);
while(ret_sock == NMXP_SOCKET_OK && type != NMXP_MSG_READY) {
......@@ -464,7 +468,7 @@ NMXP_META_CHAN_LIST *nmxp_getMetaChannelList(char * hostname, int portnum, NMXP_
nmxp_log(1, 0, "Key %d (%d) not found for %s!\n", iter->key, channelInfo->key, iter->name);
}
/* Receive Message */
ret_sock = nmxp_receiveMessage(naqssock, &type, &buffer, &length);
ret_sock = nmxp_receiveMessage(naqssock, &type, &buffer, &length, 0, &recv_errno);
nmxp_log(0, 1, "ret_sock = %d, type = %d, length = %d\n", ret_sock, type, length);
}
}
......@@ -508,7 +512,7 @@ int nmxp_raw_stream_seq_no_compare(const void *a, const void *b)
return ret;
}
void nmxp_raw_stream_init(NMXP_RAW_STREAM_DATA *raw_stream_buffer, int32_t max_tollerable_latency) {
void nmxp_raw_stream_init(NMXP_RAW_STREAM_DATA *raw_stream_buffer, int32_t max_tollerable_latency, int timeoutrecv) {
int j;
raw_stream_buffer->last_seq_no_sent = -1;
......@@ -517,6 +521,7 @@ void nmxp_raw_stream_init(NMXP_RAW_STREAM_DATA *raw_stream_buffer, int32_t max_t
* Suppose a packet can contain 1/4 secs of data */
raw_stream_buffer->max_tollerable_latency = max_tollerable_latency;
raw_stream_buffer->max_pdlist_items = max_tollerable_latency * 4;
raw_stream_buffer->timeoutrecv = timeoutrecv;
raw_stream_buffer->n_pdlist = 0;
raw_stream_buffer->pdlist = (NMXP_DATA_PROCESS **) malloc (raw_stream_buffer->max_pdlist_items * sizeof(NMXP_DATA_PROCESS *));
for(j=0; j<raw_stream_buffer->max_pdlist_items; j++) {
......@@ -551,34 +556,41 @@ int nmxp_raw_stream_manage(NMXP_RAW_STREAM_DATA *p, NMXP_DATA_PROCESS *a_pd, int
NMXP_DATA_PROCESS *pd = NULL;
if(a_pd) {
if(a_pd->packet_type == 33) {
nmxp_data_log(a_pd);
}
/* Allocate memory for pd and copy a_pd */
pd = (NMXP_DATA_PROCESS *) malloc (sizeof(NMXP_DATA_PROCESS));
memcpy(pd, a_pd, sizeof(NMXP_DATA_PROCESS));
if(a_pd->length > 0) {
pd->buffer = malloc(pd->length);
memcpy(pd->buffer, a_pd->buffer, a_pd->length);
} else {
pd->buffer = NULL;
}
if(a_pd->nSamp * sizeof(int) > 0) {
pd->pDataPtr = (int *) malloc(a_pd->nSamp * sizeof(int));
memcpy(pd->pDataPtr, a_pd->pDataPtr, a_pd->nSamp * sizeof(int));
} else {
pd->pDataPtr = NULL;
}
/*
if(a_pd->packet_type == 33 || a_pd->packet_type == 97) {
nmxp_data_log(a_pd);
}
*/
/* Allocate memory for pd and copy a_pd */
pd = (NMXP_DATA_PROCESS *) malloc (sizeof(NMXP_DATA_PROCESS));
memcpy(pd, a_pd, sizeof(NMXP_DATA_PROCESS));
if(a_pd->length > 0) {
pd->buffer = malloc(pd->length);
memcpy(pd->buffer, a_pd->buffer, a_pd->length);
} else {
pd->buffer = NULL;
}
if(a_pd->nSamp * sizeof(int) > 0) {
pd->pDataPtr = (int *) malloc(a_pd->nSamp * sizeof(int));
memcpy(pd->pDataPtr, a_pd->pDataPtr, a_pd->nSamp * sizeof(int));
} else {
pd->pDataPtr = NULL;
}
}
/* First time */
if(p->last_seq_no_sent == -1 && pd) {
p->last_seq_no_sent = pd->seq_no - 1;
p->last_sample_time = pd->time;
if(p->timeoutrecv == 0) {
p->last_seq_no_sent = pd->seq_no - 1;
p->last_sample_time = pd->time;
} else {
p->last_seq_no_sent = 0;
p->last_sample_time = 0;
}
nmxp_log(0, 1, "First time nmxp_raw_stream_manage().\n");
}
if(p->n_pdlist > 0) {
latency = nmxp_data_latency(p->pdlist[0]);
}
......@@ -641,7 +653,11 @@ int nmxp_raw_stream_manage(NMXP_RAW_STREAM_DATA *p, NMXP_DATA_PROCESS *a_pd, int
}
}
// TODO Condition for max tollerable latency
// Condition for time-out (pd is NULL)
if(!pd && p->n_pdlist > 0) {
p->last_seq_no_sent = p->pdlist[0]->seq_no - 1;
p->last_sample_time = p->pdlist[0]->time;
}
/* Manage array and execute func_pd() */
j=0;
......
......@@ -7,7 +7,7 @@
* Istituto Nazionale di Geofisica e Vulcanologia - Italy
* quintiliani@ingv.it
*
* $Id: nmxp_base.c,v 1.33 2007-10-07 14:11:23 mtheo Exp $
* $Id: nmxp_base.c,v 1.34 2007-10-07 18:13:39 mtheo Exp $
*
*/
......@@ -112,24 +112,37 @@ int nmxp_send_ctrl(int isock, void* buffer, int length)
}
int nmxp_recv_ctrl(int isock, void* buffer, int length)
int nmxp_recv_ctrl(int isock, void *buffer, int length, int timeoutsec, int *recv_errno )
{
int recvCount;
int recv_errno;
char recv_errno_str[200];
struct timeval timeo;
/*
struct timeval timeout;
socklen_t size_timeout = sizeof(timeout);
getsockopt(isock, SOL_SOCKET, SO_RCVTIMEO, &timeout, &size_timeout);
*/
if(timeoutsec > 0) {
timeo.tv_sec = timeoutsec;
timeo.tv_usec = 0;
if (setsockopt(isock, SOL_SOCKET, SO_RCVTIMEO, &timeo, sizeof(timeo)) < 0) {
perror("setsockopt SO_RCVTIMEO");
}
}
recvCount= recv(isock, (char*) buffer, length, MSG_WAITALL);
recv_errno = errno;
*recv_errno = errno;
timeo.tv_sec = 0;
timeo.tv_usec = 0;
if (setsockopt(isock, SOL_SOCKET, SO_RCVTIMEO, &timeo, sizeof(timeo)) < 0) {
perror("setsockopt SO_RCVTIMEO");
}
if (recvCount != length) {
switch(recv_errno) {
switch(*recv_errno) {
case EAGAIN : strcpy(recv_errno_str, "EAGAIN"); break;
case EBADF : strcpy(recv_errno_str, "EBADF"); break;
case ECONNREFUSED : strcpy(recv_errno_str, "ECONNREFUSED"); break;
......@@ -143,7 +156,7 @@ int nmxp_recv_ctrl(int isock, void* buffer, int length)
strcpy(recv_errno_str, "DEFAULT_NO_VALUE");
break;
}
nmxp_log(0, 1, "nmxp_recv_ctrl(): (recvCount != length) %d != %d - errno = %d (%s)\n", recvCount, length, recv_errno, recv_errno_str);
nmxp_log(0, 1, "nmxp_recv_ctrl(): (recvCount != length) %d != %d - errno = %d (%s)\n", recvCount, length, *recv_errno, recv_errno_str);
return NMXP_SOCKET_ERROR;
}
......@@ -164,12 +177,12 @@ int nmxp_sendHeader(int isock, NMXP_MSG_CLIENT type, int32_t length)
}
int nmxp_receiveHeader(int isock, NMXP_MSG_SERVER *type, int32_t *length)
int nmxp_receiveHeader(int isock, NMXP_MSG_SERVER *type, int32_t *length, int timeoutsec, int *recv_errno )
{
int ret ;
NMXP_MESSAGE_HEADER msg;
ret = nmxp_recv_ctrl(isock, &msg, sizeof(NMXP_MESSAGE_HEADER));
ret = nmxp_recv_ctrl(isock, &msg, sizeof(NMXP_MESSAGE_HEADER), timeoutsec, recv_errno);
*type = 0;
*length = 0;
......@@ -209,17 +222,17 @@ int nmxp_sendMessage(int isock, NMXP_MSG_CLIENT type, void *buffer, int32_t leng
}
int nmxp_receiveMessage(int isock, NMXP_MSG_SERVER *type, void **buffer, int32_t *length) {
int nmxp_receiveMessage(int isock, NMXP_MSG_SERVER *type, void **buffer, int32_t *length, int timeoutsec, int *recv_errno ) {
int ret;
*buffer = NULL;
*length = 0;
ret = nmxp_receiveHeader(isock, type, length);
ret = nmxp_receiveHeader(isock, type, length, timeoutsec, recv_errno);
if( ret == NMXP_SOCKET_OK) {
if (*length > 0) {
*buffer = malloc(*length);
ret = nmxp_recv_ctrl(isock, *buffer, *length);
ret = nmxp_recv_ctrl(isock, *buffer, *length, 0, recv_errno);
if(*type == NMXP_MSG_ERROR) {
nmxp_log(1,0, "Received ErrorMessage: %s\n", *buffer);
......@@ -227,7 +240,11 @@ int nmxp_receiveMessage(int isock, NMXP_MSG_SERVER *type, void **buffer, int32_t
}
} else {
nmxp_log(1,0, "Error in nmxp_receiveMessage()\n");
if(*recv_errno != EAGAIN) {
nmxp_log(1,0, "Error in nmxp_receiveMessage()\n");
} else {
nmxp_log(NMXP_LOG_WARN, 0, "Timeout receveing in nmxp_receiveMessage()\n");
}
}
return ret;
......
......@@ -7,13 +7,14 @@
* Istituto Nazionale di Geofisica e Vulcanologia - Italy
* quintiliani@ingv.it
*
* $Id: nmxptool.c,v 1.83 2007-10-07 14:11:03 mtheo Exp $
* $Id: nmxptool.c,v 1.84 2007-10-07 18:12:37 mtheo Exp $
*
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <nmxp.h>
......@@ -44,6 +45,7 @@
typedef struct {
int significant;
double last_time;
time_t last_time_call_raw_stream;
int32_t x_1;
NMXP_RAW_STREAM_DATA raw_stream_buffer;
} NMXPTOOL_CHAN_SEQ;
......@@ -84,8 +86,10 @@ int main (int argc, char **argv) {
int32_t connection_time;
int request_SOCKET_OK;
int i_chan, cur_chan = 0;
int to_cur_chan = 0;
int exitpdscondition;
int exitdapcondition;
time_t timeout_for_channel;
int span_interval = 10;
int time_to_sleep = 0;
......@@ -99,6 +103,8 @@ int main (int argc, char **argv) {
int32_t length;
int ret;
int recv_errno = 0;
char filename[500];
char station_code[20], channel_code[20], network_code[20];
......@@ -192,8 +198,9 @@ int main (int argc, char **argv) {
for(i_chan = 0; i_chan < channelList_subset->number; i_chan++) {
channelListSeq[i_chan].significant = 0;
channelListSeq[i_chan].last_time = 0.0;
channelListSeq[i_chan].last_time_call_raw_stream = 0;
channelListSeq[i_chan].x_1 = 0;
nmxp_raw_stream_init(&(channelListSeq[i_chan].raw_stream_buffer), params.max_tolerable_latency);
nmxp_raw_stream_init(&(channelListSeq[i_chan].raw_stream_buffer), params.max_tolerable_latency, params.timeoutrecv);
}
#ifdef HAVE_LIBMSEED
......@@ -359,7 +366,7 @@ int main (int argc, char **argv) {
}
/* DAP Step 6: Receive Data until receiving a Ready message */
ret = nmxp_receiveMessage(naqssock, &type, &buffer, &length);
ret = nmxp_receiveMessage(naqssock, &type, &buffer, &length, 0, &recv_errno);
nmxp_log(0, 1, "ret = %d, type = %d\n", ret, type);
while(ret == NMXP_SOCKET_OK && type != NMXP_MSG_READY) {
......@@ -427,7 +434,7 @@ int main (int argc, char **argv) {
}
/* Receive Data */
ret = nmxp_receiveMessage(naqssock, &type, &buffer, &length);
ret = nmxp_receiveMessage(naqssock, &type, &buffer, &length, 0, &recv_errno);
nmxp_log(0, 1, "ret = %d, type = %d\n", ret, type);
}
......@@ -574,21 +581,10 @@ int main (int argc, char **argv) {
#endif
#ifdef TEST_FOR_DOD
/*
struct timeval timeo;
timeo.tv_sec = 0;
timeo.tv_usec = 0;
if (setsockopt(naqssock, SOL_SOCKET, SO_RCVTIMEO, &timeo, sizeof(timeo)) < 0) {
perror("setsockopt SO_RCVTIMEO");
}
*/
#endif
while(exitpdscondition) {
/* Process Compressed or Decompressed Data */
pd = nmxp_receiveData(naqssock, channelList_subset, NETCODE_OR_CURRENT_NETWORK);
pd = nmxp_receiveData(naqssock, channelList_subset, NETCODE_OR_CURRENT_NETWORK, params.timeoutrecv, &recv_errno);
/* Log contents of last packet */
if(params.flag_logdata) {
......@@ -596,13 +592,35 @@ int main (int argc, char **argv) {
}
if(pd) {
/* Set cur_chan */
cur_chan = nmxp_chan_lookupKeyIndex(pd->key, channelList_subset);
/* Set cur_chan */
cur_chan = nmxp_chan_lookupKeyIndex(pd->key, channelList_subset);
}
/* Manage Raw Stream */
if(params.stc == -1) {
nmxp_raw_stream_manage(&(channelListSeq[cur_chan].raw_stream_buffer), pd, p_func_pd, n_func_pd);
/* cur_char is computed only for pd != NULL */
if(pd) {
nmxp_raw_stream_manage(&(channelListSeq[cur_chan].raw_stream_buffer), pd, p_func_pd, n_func_pd);
channelListSeq[cur_chan].last_time_call_raw_stream = nmxp_data_gmtime_now();
}
/* Check timeout for other channels */
if(params.timeoutrecv > 0) {
to_cur_chan = 0;
while(to_cur_chan < channelList_subset->number) {
timeout_for_channel = nmxp_data_gmtime_now() - channelListSeq[to_cur_chan].last_time_call_raw_stream;
if(channelListSeq[to_cur_chan].last_time_call_raw_stream != 0
&& timeout_for_channel >= params.timeoutrecv) {
nmxp_log(NMXP_LOG_WARN, 0, "Timeout for channel %s (%d sec.)\n",
channelList_subset->channel[to_cur_chan].name, timeout_for_channel);
nmxp_raw_stream_manage(&(channelListSeq[to_cur_chan].raw_stream_buffer), NULL, p_func_pd, n_func_pd);
channelListSeq[to_cur_chan].last_time_call_raw_stream = nmxp_data_gmtime_now();
}
to_cur_chan++;
}
}
} else {
if(pd) {
......@@ -817,13 +835,18 @@ int nmxptool_write_miniseed(NMXP_DATA_PROCESS *pd) {
int nmxptool_print_seq_no(NMXP_DATA_PROCESS *pd) {
int ret = 0;
char str_time[200];
nmxp_data_to_str(str_time, pd->time);
nmxp_log(NMXP_LOG_NORM_NO, 0, "Process %s.%s %2d %d %d lat. %.1fs\n",
nmxp_log(NMXP_LOG_NORM_NO, 0, "Process %s.%s.%s %2d %d %d %s %dpts lat. %.1fs\n",
pd->network,
pd->station,
pd->channel,
pd->packet_type,
pd->seq_no,
pd->oldest_seq_no,
str_time,
pd->nSamp,
nmxp_data_latency(pd)
);
......
......@@ -7,7 +7,7 @@
* Istituto Nazionale di Geofisica e Vulcanologia - Italy
* quintiliani@ingv.it
*
* $Id: nmxptool_getoptlong.c,v 1.33 2007-10-07 14:11:03 mtheo Exp $
* $Id: nmxptool_getoptlong.c,v 1.34 2007-10-07 18:12:37 mtheo Exp $
*
*/
......@@ -38,7 +38,8 @@ const NMXPTOOL_PARAMS NMXPTOOL_PARAMS_DEFAULT =
DEFAULT_RATE,
NULL,
DEFAULT_DELAY,
DEFAULT_MAX_TOLLERABLE_LATENCY,
DEFAULT_MAX_TOLERABLE_LATENCY,