Skip to content
Snippets Groups Projects
Commit 1e5b97ae authored by Alessio Igor Bogani's avatar Alessio Igor Bogani
Browse files

Make code more reliable

parent 48babcab
No related branches found
No related tags found
No related merge requests found
......@@ -508,8 +508,12 @@ void Socket2::write(const Tango::DevVarCharArray *argin)
int olength;
while (bytes_total < bytes_to_write) {
if (! wait_for(WRITE))
int s = select(WRITE);
if (s == 0)
goto timeout;
else if (s < 0)
goto error;
else { /* s > 0 */ }
ssize_t bytes_written = _write(
fd, argin_data.data() + bytes_total,
......@@ -763,8 +767,12 @@ void Socket2::_read(size_t bytes_to_read)
size_t bytes_total = data.size();
while (bytes_total < bytes_to_read) {
if (! wait_for(READ))
goto timeout;
int s = select(READ);
if (s == 0)
goto timeout;
else if (s < 0)
goto error;
else { /* s > 0 */ }
size_t count = min((size_t)max(input_queue_length(), 0), sizeof(buffer));
ssize_t bytes_readed = proto == UDP?
......@@ -784,7 +792,7 @@ void Socket2::_read(size_t bytes_to_read)
}
return;
error:
check_state(false);
check_state(true);
sleep(tout);
timeout:
Tango::Except::throw_exception(
......@@ -851,7 +859,7 @@ void Socket2::check_state(bool forcing)
reconnections += 1;
}
bool Socket2::wait_for(event_type et)
int Socket2::select(event_type et)
{
if (multiplexing == SLEEP) {
timeval twait;
......@@ -868,8 +876,8 @@ bool Socket2::wait_for(event_type et)
FD_ZERO(&errorfds);
FD_ZERO(&readfds);
FD_ZERO(&writefds);
FD_SET(fd, &errorfds);
FD_SET(fd, &errorfds);
switch (et) {
case WRITE:
FD_SET(fd, &writefds);
......@@ -879,27 +887,28 @@ bool Socket2::wait_for(event_type et)
break;
}
int select_ret = select(fd + 1, &readfds,
int select_ret = ::select(fd + 1, &readfds,
&writefds, &errorfds, &tout);
if (FD_ISSET(fd, &errorfds)) {
assert(false);
return -1;
}
if (select_ret > 0) {
if (FD_ISSET(fd, &errorfds))
return false;
if (et == READ && FD_ISSET(fd, &readfds))
return true;
return select_ret;
if (et == WRITE && FD_ISSET(fd, &writefds))
return true;
return select_ret;
assert(false);
return false;
return -1;
} else if (select_ret == 0) {
return false;
return select_ret;
} else { // select_ret < 0
ERROR_STREAM << "Select() error " << select_ret
<< " not handled:" << strerror(errno) << endl;
return false;
return select_ret;
}
assert(false);
return false;
return -1;
}
void Socket2::resolve()
......
......@@ -268,7 +268,7 @@ public:
ssize_t _write(int, const void*, size_t);
void _read(size_t);
void check_state(bool);
bool wait_for(event_type);
int select(event_type);
void resolve();
/*----- PROTECTED REGION END -----*/ // Socket2::Additional Method prototypes
};
......
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