Commit 59e4aa2c authored by Jochen Roessner's avatar Jochen Roessner

fehlendes FD_ZERO ergaenzt

parent 0b4f680e
......@@ -30,7 +30,7 @@
#include <netdb.h>
#define MAXTRY 5
#define MAXTRYOPENCLOSE 10
#define MAXTRYOPENCLOSE 8
#define TIMEWAIT 3
#define I2C_DATAOFFSET 4
//#define DEBUG
......@@ -174,12 +174,15 @@ i2c_open(const char *device, int addr)
return 0; /* schlug fehl */
}
FD_SET(0, &fds);
timeout.tv_sec = 5;
timeout.tv_usec = 0;
FD_ZERO(&fds);
FD_SET(handle->sock, &fds);
timeout.tv_sec = 0;
timeout.tv_usec = 500000;
select(handle->sock+1, &fds, NULL, NULL, &timeout);
#if defined(DEBUG) || defined(OPENDEBUG)
fprintf(stderr,"select returned, tv_sec=%u, tv_used=%u\n", timeout.tv_sec, timeout.tv_usec);
#endif
if(FD_ISSET(handle->sock, &fds) == 1){
readlen = read(handle->sock, ((unsigned char *) &i2cpacket_rx), sizeof(struct i2c_packet_write_rx));
if (readlen == sizeof(struct i2c_packet_write_rx) && i2cpacket_rx.seqnum == 0
......@@ -190,6 +193,7 @@ i2c_open(const char *device, int addr)
#endif
}
}
}while(handle->maxdatapaketlen == 0 && maxtry++ < MAXTRYOPENCLOSE);
if (maxtry >= MAXTRYOPENCLOSE){
#if defined(DEBUG) || defined(OPENDEBUG)
......@@ -275,10 +279,11 @@ i2c_send(struct i2cdev *handle, const unsigned char *data, int len)
if(write(handle->sock, i2cpacket_tx, aktlen + sizeof(struct i2c_packet_write_tx)) != aktlen + sizeof(struct i2c_packet_write_tx))
return -1; /* schlug fehl */
/* empfange die antwort */
FD_SET(0, &fds);
FD_SET(handle->sock, &fds);
timeout.tv_sec = TIMEWAIT;
timeout.tv_usec = 0;
FD_ZERO(&fds);
FD_SET(handle->sock, &fds);
select(handle->sock+1, &fds, NULL, NULL, &timeout);
if(FD_ISSET(handle->sock, &fds) == 1){
......@@ -367,10 +372,11 @@ i2c_recv(struct i2cdev *handle, unsigned char *buf, int len)
return -1; /* schlug fehl */
}
/* empfange die daten */
FD_SET(0, &fds);
FD_SET(handle->sock, &fds);
timeout.tv_sec = TIMEWAIT;
timeout.tv_usec = 0;
FD_ZERO(&fds);
FD_SET(handle->sock, &fds);
select(handle->sock+1, &fds, NULL, NULL, &timeout);
if(FD_ISSET(handle->sock, &fds) == 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