Commit 53ddf346 by jim

Unify timeouts

git-svn-id: https://bucket.mit.edu/svn/nilm/acquisition/ethstream@8321 ddd99763-3ecb-0310-9145-efcb8ce7c51f
parent b0be6473
Showing with 14 additions and 13 deletions
......@@ -5,4 +5,6 @@
#define CONVERT_VOLTS 1
#define CONVERT_HEX 2
#define TIMEOUT 5 /* Timeout for connect/send/recv, in seconds */
#endif
......@@ -25,8 +25,6 @@
#include "netutil.h"
#include "ethstream.h"
#define NERDJACK_TIMEOUT 5 /* Timeout for connect/send/recv, in seconds */
#define NERD_HEADER_SIZE 8
#define MAX_SOCKETS 32
......@@ -312,7 +310,7 @@ int nerdjack_detect(char *ipAddress)
recvfrom_timeout(receivesock, incomingData, sizeof(incomingData), 0,
(struct sockaddr *)&sFromAddr, &lFromLen,
&(struct timeval) {
.tv_sec = NERDJACK_TIMEOUT})) {
.tv_sec = TIMEOUT})) {
close(receivesock);
return -1;
}
......@@ -341,14 +339,14 @@ int nerd_get_version(const char *address)
/* Send request */
ret = send_all_timeout(fd_command, "VERS", 4, 0, &(struct timeval) {
.tv_sec = NERDJACK_TIMEOUT});
.tv_sec = TIMEOUT});
if (ret < 0) {
verb("short send %d\n", (int)ret);
return -1;
}
ret = recv_all_timeout(fd_command, buf, 200, 0, &(struct timeval) {
.tv_sec = NERDJACK_TIMEOUT});
.tv_sec = TIMEOUT});
nerd_close_conn(fd_command);
......@@ -380,14 +378,14 @@ int nerd_send_command(const char *address, void *command, int length)
/* Send request */
ret = send_all_timeout(fd_command, command, length, 0, &(struct timeval) {
.tv_sec = NERDJACK_TIMEOUT});
.tv_sec = TIMEOUT});
if (ret < 0 || ret != length) {
verb("short send %d\n", (int)ret);
return -1;
}
ret = recv_all_timeout(fd_command, buf, 3, 0, &(struct timeval) {
.tv_sec = NERDJACK_TIMEOUT});
.tv_sec = TIMEOUT});
nerd_close_conn(fd_command);
......
......@@ -24,8 +24,7 @@
#include "ue9error.h"
#include "util.h"
#include "netutil.h"
#define UE9_TIMEOUT 5 /* Timeout for connect/send/recv, in seconds */
#include "ethstream.h"
/* Fill checksums in data buffers, with "normal" checksum format */
void ue9_checksum_normal(uint8_t * buffer, size_t len)
......@@ -183,7 +182,7 @@ int ue9_command(int fd, uint8_t * out, uint8_t * in, int inlen)
/* Send request */
ret = send_all_timeout(fd, out, outlen, 0, &(struct timeval) {
.tv_sec = UE9_TIMEOUT});
.tv_sec = TIMEOUT});
if (ret < 0 || ret != outlen) {
verb("short send %d\n", (int)ret);
return -1;
......@@ -197,7 +196,7 @@ int ue9_command(int fd, uint8_t * out, uint8_t * in, int inlen)
/* Receive result */
ret = recv_all_timeout(fd, in, inlen, 0, &(struct timeval) {
.tv_sec = UE9_TIMEOUT});
.tv_sec = TIMEOUT});
if (ret < 0 || ret != inlen) {
verb("short recv %d\n", (int)ret);
return -1;
......@@ -399,12 +398,14 @@ int ue9_open(const char *host, int port)
/* Connect */
if (connect_timeout(fd, (struct sockaddr *)&address, sizeof(address),
&(struct timeval) {
.tv_sec = UE9_TIMEOUT}) < 0) {
.tv_sec = TIMEOUT}) < 0) {
verb("connection to %s:%d failed: %s\n",
inet_ntoa(address.sin_addr), port, compat_strerror(errno));
return -1;
}
debug("Connected to port %d\n", htons(port));
return fd;
}
......@@ -650,7 +651,7 @@ ue9_stream_data(int fd, int channels, ue9_stream_cb_t callback, void *context)
for (;;) {
/* Receive data */
ret = recv_all_timeout(fd, buf, 46, 0, &(struct timeval) {
.tv_sec = UE9_TIMEOUT});
.tv_sec = TIMEOUT});
/* Verify packet format */
if (ret != 46) {
......
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 sign in to comment