diff options
author | Jim Newsome <jnewsome@andrew.cmu.edu> | 2010-08-18 14:09:55 -0400 |
---|---|---|
committer | Gerd Hoffmann <kraxel@redhat.com> | 2011-05-25 15:17:57 +0200 |
commit | 228c005729e813376a3aea7dc7c6e69e4895ad39 (patch) | |
tree | a563966ab0a67fc00e8144b2343e4c7a02aaf246 | |
parent | 853d7d850ef838831289c34bd42bb99a01e072b1 (diff) | |
download | amtterm-228c005729e813376a3aea7dc7c6e69e4895ad39.tar.gz |
block when waiting for socket data
-rw-r--r-- | redir.c | 8 |
1 files changed, 8 insertions, 0 deletions
@@ -24,6 +24,7 @@ #include <string.h> #include <ctype.h> #include <errno.h> +#include <fcntl.h> #include "tcp.h" #include "redir.h" @@ -254,6 +255,7 @@ int redir_sol_recv(struct redir *r) { unsigned char msg[64]; int count, len, bshift; + int flags; len = r->buf[8] + (r->buf[9] << 8); count = r->blen - 10; @@ -270,7 +272,13 @@ int redir_sol_recv(struct redir *r) count = sizeof(msg); if (count > len) count = len; + /* temporarily switch to blocking. the actual data may not be + ready yet, but should be here Real Soon Now. */ + flags = fcntl(r->sock,F_GETFL); + fcntl(r->sock,F_SETFL, flags & (~O_NONBLOCK)); count = read(r->sock, msg, count); + fcntl(r->sock,F_SETFL, flags); + switch (count) { case -1: snprintf(r->err, sizeof(r->err), "read(socket): %s", strerror(errno)); |