Lines 46-51
Link Here
|
46 |
#include <stdio.h> |
46 |
#include <stdio.h> |
47 |
#include <stdlib.h> |
47 |
#include <stdlib.h> |
48 |
#include <unistd.h> |
48 |
#include <unistd.h> |
|
|
49 |
#include "stdio.h" |
49 |
|
50 |
|
50 |
#ifndef INFTIM |
51 |
#ifndef INFTIM |
51 |
#define INFTIM -1 |
52 |
#define INFTIM -1 |
Lines 69-75
Link Here
|
69 |
if (select_result == -1 && errno == EINTR) { |
70 |
if (select_result == -1 && errno == EINTR) { |
70 |
continue; |
71 |
continue; |
71 |
} |
72 |
} |
72 |
|
73 |
|
73 |
if (select_result == -1) { |
74 |
if (select_result == -1) { |
74 |
err_sys("poll failed\n"); |
75 |
err_sys("poll failed\n"); |
75 |
} |
76 |
} |
Lines 109-118
Link Here
|
109 |
|
110 |
|
110 |
#else |
111 |
#else |
111 |
|
112 |
|
|
|
113 |
#define FRAGSIZ 1000 |
114 |
|
112 |
int loop(int master_fd) { |
115 |
int loop(int master_fd) { |
113 |
ssize_t n; |
116 |
ssize_t n; |
114 |
char buf[BUFSIZ]; |
117 |
char buf[FRAGSIZ]; |
115 |
struct pollfd fds[2]; |
118 |
struct pollfd fds[2]; |
|
|
119 |
|
120 |
struct buffer to_master; |
121 |
to_master.offset = 0; |
122 |
to_master.length = 0; |
116 |
|
123 |
|
117 |
fds[0].fd = STDIN_FILENO; |
124 |
fds[0].fd = STDIN_FILENO; |
118 |
fds[0].events = POLLIN; |
125 |
fds[0].events = POLLIN; |
Lines 135-163
Link Here
|
135 |
err_sys("poll() failed in main_loop"); |
142 |
err_sys("poll() failed in main_loop"); |
136 |
} |
143 |
} |
137 |
|
144 |
|
138 |
if (fds[0].revents & POLLIN) { |
|
|
139 |
if ((n = read(STDIN_FILENO, buf, BUFSIZ)) == -1) { |
140 |
err_sys("read from stdin failed"); |
141 |
} |
142 |
|
143 |
if (n == 0) { |
144 |
#ifdef __CYGWIN__ |
145 |
// On Windows when calling process is killed, |
146 |
// POLLIN flag is set, not POLLHUP. |
147 |
// So behave as if we have received POLLHUP in this case... |
148 |
close(master_fd); |
149 |
return 1; |
150 |
#endif |
151 |
break; |
152 |
} |
153 |
|
154 |
if (writen(master_fd, buf, n) == -1) { |
155 |
err_sys("write to master failed\n"); |
156 |
} |
157 |
} |
158 |
|
159 |
if (fds[1].revents & POLLIN) { |
145 |
if (fds[1].revents & POLLIN) { |
160 |
if ((n = read(master_fd, buf, BUFSIZ)) == -1) { |
146 |
if ((n = read(master_fd, buf, FRAGSIZ)) == -1) { |
161 |
#ifdef __CYGWIN__ |
147 |
#ifdef __CYGWIN__ |
162 |
// On Windows master_fd is invalid here |
148 |
// On Windows master_fd is invalid here |
163 |
// (bug #252202) |
149 |
// (bug #252202) |
Lines 177-182
Link Here
|
177 |
} |
163 |
} |
178 |
} |
164 |
} |
179 |
|
165 |
|
|
|
166 |
if (to_master.offset != to_master.length) { |
167 |
int nwritten = writen_no_block(master_fd, &to_master); |
168 |
if (nwritten == -1) { |
169 |
err_sys("write to master failed\n"); |
170 |
} |
171 |
} else if (fds[0].revents & POLLIN) { |
172 |
if ((n = read(STDIN_FILENO, to_master.buf, FRAGSIZ)) == -1) { |
173 |
err_sys("read from stdin failed"); |
174 |
} |
175 |
|
176 |
if (n == 0) { |
177 |
#ifdef __CYGWIN__ |
178 |
// On Windows when calling process is killed, |
179 |
// POLLIN flag is set, not POLLHUP. |
180 |
// So behave as if we have received POLLHUP in this case... |
181 |
close(master_fd); |
182 |
return 1; |
183 |
#endif |
184 |
break; |
185 |
} |
186 |
|
187 |
to_master.offset = 0; |
188 |
to_master.length = n; |
189 |
|
190 |
int nwritten = writen_no_block(master_fd, &to_master); |
191 |
if (nwritten == -1) { |
192 |
err_sys("write to master failed\n"); |
193 |
} |
194 |
} |
195 |
|
180 |
if (fds[1].revents & POLLHUP) { |
196 |
if (fds[1].revents & POLLHUP) { |
181 |
break; |
197 |
break; |
182 |
} |
198 |
} |