diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2008-02-10 19:05:56 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2008-02-10 19:05:56 +0000 |
commit | 9304d6ea92f7fc1529669800b75456d549cf1bfc (patch) | |
tree | 00da66527fe91e0410bd024e485300cba746a048 /miscutils/microcom.c | |
parent | 991a1da14806eefd1c6fc8fc1c0c3d2b90af6f24 (diff) | |
download | busybox-w32-9304d6ea92f7fc1529669800b75456d549cf1bfc.tar.gz busybox-w32-9304d6ea92f7fc1529669800b75456d549cf1bfc.tar.bz2 busybox-w32-9304d6ea92f7fc1529669800b75456d549cf1bfc.zip |
microcom: read more than 1 byte from device, if possible
Diffstat (limited to 'miscutils/microcom.c')
-rw-r--r-- | miscutils/microcom.c | 30 |
1 files changed, 16 insertions, 14 deletions
diff --git a/miscutils/microcom.c b/miscutils/microcom.c index 817ef55ac..63b07fd69 100644 --- a/miscutils/microcom.c +++ b/miscutils/microcom.c | |||
@@ -63,7 +63,7 @@ int microcom_main(int argc, char **argv) | |||
63 | char *opt_d; | 63 | char *opt_d; |
64 | char *opt_t; | 64 | char *opt_t; |
65 | unsigned opts; | 65 | unsigned opts; |
66 | opt_complementary = "=1"; /* exactly one arg should be there */ | 66 | opt_complementary = "=1"; // exactly one arg should be there |
67 | opts = getopt32(argv, "Xs:d:t:", &opt_s, &opt_d, &opt_t); | 67 | opts = getopt32(argv, "Xs:d:t:", &opt_s, &opt_d, &opt_t); |
68 | 68 | ||
69 | // apply options | 69 | // apply options |
@@ -141,36 +141,38 @@ int microcom_main(int argc, char **argv) | |||
141 | signalled = 0; | 141 | signalled = 0; |
142 | nfd = 2; | 142 | nfd = 2; |
143 | while (!signalled && safe_poll(pfd, nfd, timeout) > 0) { | 143 | while (!signalled && safe_poll(pfd, nfd, timeout) > 0) { |
144 | char c; | ||
145 | if (pfd[0].revents) { | ||
146 | serial_ready: | ||
147 | // read from device -> write to stdout | ||
148 | if (safe_read(sfd, &c, 1) > 0) | ||
149 | write(STDOUT_FILENO, &c, 1); | ||
150 | // else { EOF/error - what to do? } | ||
151 | } | ||
152 | if (pfd[1].revents) { | 144 | if (pfd[1].revents) { |
153 | pfd[1].revents = 0; | 145 | char c; |
154 | // read from stdin -> write to device | 146 | // read from stdin -> write to device |
155 | if (safe_read(STDIN_FILENO, &c, 1) < 1) { | 147 | if (safe_read(STDIN_FILENO, &c, 1) < 1) { |
156 | // don't poll stdin anymore if we got EOF/error | 148 | // don't poll stdin anymore if we got EOF/error |
149 | pfd[1].revents = 0; | ||
157 | nfd--; | 150 | nfd--; |
158 | continue; | 151 | goto check_stdin; |
159 | } | 152 | } |
160 | // do we need special processing? | 153 | // do we need special processing? |
161 | if (!(opts & OPT_X)) { | 154 | if (!(opts & OPT_X)) { |
162 | // ^@ sends Break | 155 | // ^@ sends Break |
163 | if (VINTR == c) { | 156 | if (VINTR == c) { |
164 | tcsendbreak(sfd, 0); | 157 | tcsendbreak(sfd, 0); |
165 | continue; | 158 | goto check_stdin; |
166 | } | 159 | } |
167 | // ^X exits | 160 | // ^X exits |
168 | if (24 == c) | 161 | if (24 == c) |
169 | break; | 162 | break; |
170 | } | 163 | } |
171 | write(sfd, &c, 1); | 164 | write(sfd, &c, 1); |
172 | if (delay >= 0 && safe_poll(pfd, 1, delay) > 0) | 165 | if (delay >= 0) |
173 | goto serial_ready; | 166 | safe_poll(pfd, 1, delay); |
167 | } | ||
168 | check_stdin: | ||
169 | if (pfd[0].revents) { | ||
170 | ssize_t len; | ||
171 | // read from device -> write to stdout | ||
172 | len = safe_read(sfd, bb_common_bufsiz1, sizeof(bb_common_bufsiz1)); | ||
173 | if (len > 0) | ||
174 | full_write(STDOUT_FILENO, bb_common_bufsiz1, len); | ||
175 | // else { EOF/error - what to do? } | ||
174 | } | 176 | } |
175 | } | 177 | } |
176 | 178 | ||