mirror of
https://github.com/linuxkit/linuxkit.git
synced 2025-07-22 18:41:37 +00:00
nc-vsock: Keep going until both fds read EOF.
Rather than exiting when the first read hits EOF, ignoring any remaining data going the other way. Signed-off-by: Ian Campbell <ian.campbell@docker.com>
This commit is contained in:
parent
ce5c85f7c1
commit
a9784a5fe0
@ -215,9 +215,12 @@ static int xfer_data(int in_fd, int out_fd)
|
|||||||
if (out_fd == STDIN_FILENO) out_fd = STDOUT_FILENO;
|
if (out_fd == STDIN_FILENO) out_fd = STDOUT_FILENO;
|
||||||
|
|
||||||
nbytes = read(in_fd, buf, sizeof(buf));
|
nbytes = read(in_fd, buf, sizeof(buf));
|
||||||
if (nbytes <= 0) {
|
if (nbytes < 0) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
if (nbytes == 0) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
remaining = nbytes;
|
remaining = nbytes;
|
||||||
while (remaining > 0) {
|
while (remaining > 0) {
|
||||||
@ -252,21 +255,25 @@ static int xfer_data(int in_fd, int out_fd)
|
|||||||
send_ptr += nbytes;
|
send_ptr += nbytes;
|
||||||
remaining -= nbytes;
|
remaining -= nbytes;
|
||||||
}
|
}
|
||||||
return 0;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void main_loop(int fds[2])
|
static void main_loop(int fds[2])
|
||||||
{
|
{
|
||||||
fd_set rfds;
|
fd_set rfds;
|
||||||
int nfds = fds[fds[0] > fds[1] ? 0 : 1] + 1;
|
int nfds = fds[fds[0] > fds[1] ? 0 : 1] + 1;
|
||||||
|
bool rfd0 = true, rfd1 = true; /* Which fd's are readable */
|
||||||
|
|
||||||
set_nonblock(fds[0], true);
|
set_nonblock(fds[0], true);
|
||||||
set_nonblock(fds[1], true);
|
set_nonblock(fds[1], true);
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
|
if (!rfd0 && !rfd1)
|
||||||
|
return;
|
||||||
|
|
||||||
FD_ZERO(&rfds);
|
FD_ZERO(&rfds);
|
||||||
FD_SET(fds[0], &rfds);
|
if (rfd0) FD_SET(fds[0], &rfds);
|
||||||
FD_SET(fds[1], &rfds);
|
if (rfd1) FD_SET(fds[1], &rfds);
|
||||||
|
|
||||||
if (select(nfds, &rfds, NULL, NULL, NULL) < 0) {
|
if (select(nfds, &rfds, NULL, NULL, NULL) < 0) {
|
||||||
if (errno == EINTR) {
|
if (errno == EINTR) {
|
||||||
@ -277,15 +284,19 @@ static void main_loop(int fds[2])
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (FD_ISSET(fds[0], &rfds)) {
|
if (rfd0 && FD_ISSET(fds[0], &rfds)) {
|
||||||
if (xfer_data(fds[0], fds[1]) < 0) {
|
switch (xfer_data(fds[0], fds[1])) {
|
||||||
return;
|
case -1: return;
|
||||||
|
case 0: rfd0 = false; break;
|
||||||
|
case 1: break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (FD_ISSET(fds[1], &rfds)) {
|
if (rfd1 && FD_ISSET(fds[1], &rfds)) {
|
||||||
if (xfer_data(fds[1], fds[0]) < 0) {
|
switch (xfer_data(fds[1], fds[0])) {
|
||||||
return;
|
case -1: return;
|
||||||
|
case 0: rfd1 = false; break;
|
||||||
|
case 1: break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user