aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVadim Troshchinskiy <vtroshchinskiy@qindel.com>2015-05-20 15:47:45 +0200
committerMike Gabriel <mike.gabriel@das-netzwerkteam.de>2015-09-28 07:53:06 +0200
commit8d9e8f70b25a1e2a14b79168e74056f146430a34 (patch)
tree363241c70a6e8db46a4f5b28043e496efa747a37
parent1fe33b710be26a013090c6c14ae3846940154cab (diff)
downloadnx-libs-8d9e8f70b25a1e2a14b79168e74056f146430a34.tar.gz
nx-libs-8d9e8f70b25a1e2a14b79168e74056f146430a34.tar.bz2
nx-libs-8d9e8f70b25a1e2a14b79168e74056f146430a34.zip
Fix negotiation in stage 10 error
Problem fixed by adding a select() call to implement a timeout, and retrying writes if needed.
-rw-r--r--nxcomp/Loop.cpp38
1 files changed, 37 insertions, 1 deletions
diff --git a/nxcomp/Loop.cpp b/nxcomp/Loop.cpp
index f25aed353..0ab0dd988 100644
--- a/nxcomp/Loop.cpp
+++ b/nxcomp/Loop.cpp
@@ -8100,16 +8100,52 @@ int ReadRemoteData(int fd, char *buffer, int size, char stop)
int WriteLocalData(int fd, const char *buffer, int size)
{
int position = 0;
+ int ret = 0;
+ fd_set writeSet;
+ struct timeval selectTs = {30, 0};
while (position < size)
{
+
+ // A write to a non-blocking socket may fail with EAGAIN. The problem is
+ // that cache data is done in several writes, and there's no easy way
+ // to handle failure without rewriting a significant amount of code.
+ //
+ // Bailing out of the outer loop would result in restarting the sending
+ // of the entire cache list, which would confuse the other side.
+
+ FD_ZERO(&writeSet);
+ FD_SET(fd, &writeSet);
+
+ ret = select(fd+1, NULL, &writeSet, NULL, &selectTs);
+
+ #ifdef DEBUG
+ *logofs << "Loop: WriteLocalData: select() returned with a code of " << ret << " and remaining timeout of "
+ << selectTs.tv_sec << " sec, " << selectTs.tv_usec << "usec\n" << logofs_flush;
+ #endif
+
+ if ( ret < 0 )
+ {
+ *logofs << "Loop: Error in select() when writing data to FD#" << fd << ": " << strerror(EGET()) << "\n" << logofs_flush;
+
+ if ( EGET() == EINTR )
+ continue;
+
+ return -1;
+ }
+ else if ( ret == 0 )
+ {
+ *logofs << "Loop: Timeout expired in select() when writing data to FD#" << fd << ": " << strerror(EGET()) << "\n" << logofs_flush;
+ return -1;
+ }
+
int result = write(fd, buffer + position, size - position);
getNewTimestamp();
if (result <= 0)
{
- if (result < 0 && EGET() == EINTR)
+ if (result < 0 && (EGET() == EINTR || EGET() == EAGAIN || EGET() == EWOULDBLOCK))
{
continue;
}