From: Kouichi Hirabayashi <[email protected]>
Subject: [FreeBSD-users-jp 94053] Re: umodem で PICC18F2550 にアクセスすると不安定
Date: Thu, 15 Nov 2012 06:31:48 +0900
>> open()に O_NONBLOCK を与えないと、open()がブロッ
>> クされ、termios 関係の設定に進むことができなかったので、
>> O_NONBLOCK を追加しました。
>
> /dev/ttyU0 でなく、/dev/cuaU0 を使うとどうなりますか?
あぁ、たしかに call out ですね。/dev/cuaU0 だと open()がブロックされな
くなりました。
read()から帰ってこなくなり、ttyin でブロックされています。
kohi@sh$ ps alxwwp 29573
UID PID PPID CPU PRI NI VSZ RSS MWCHAN STAT TT TIME COMMAND
0 29573 29070 0 44 0 5832 968 ttyin I+ 0 0:00.00 ./test10
$ diff -u test8.c test10.c
--- test8.c 2012-11-13 20:31:49.000000000 +0900
+++ test10.c 2012-11-15 19:58:22.000000000 +0900
@@ -6,7 +6,6 @@
#include <termios.h>
#include <unistd.h>
#include <sys/ioctl.h>
-#include <sys/select.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/uio.h>
@@ -22,13 +21,11 @@
ssize_t n;
char *tmesg,
rmesg[16];
- fd_set fds;
struct termios tios;
- struct timeval timeout;
for (i = 0; ; i++) {
printf("i = %d\n", i);
- if ( (fd = open("/dev/ttyU0", O_RDWR | O_NONBLOCK) ) < 0) {
+ if ( (fd = open("/dev/cuaU0", O_RDWR) ) < 0) {
err(1, "open()");
}
if (ioctl(fd, TIOCEXCL) < 0) {
@@ -53,33 +50,13 @@
if (tcsetattr(fd, TCSADRAIN, &tios) < 0) {
err(1, "tcsetattr()");
}
- FD_ZERO(&fds);
- FD_SET(fd, &fds);
- timeout.tv_sec = 1;
- timeout.tv_usec = 0;
tmesg = "BARH\r\n";
tlen = strlen(tmesg);
- if ( (n = select(fd + 1, NULL, &fds, NULL, &timeout) ) < 0) {
- err(1, "select() for write()");
- } else if (n == 0) {
- fprintf(stderr, "select() for write() timeout.\n");
- close(fd);
- sleep(PAUSE);
- exit(1);
- }
if (write(fd, tmesg, tlen) < 0) {
err(1, "write()");
}
- FD_ZERO(&fds);
- FD_SET(fd, &fds);
- if ( (n = select(fd + 1, &fds, NULL, NULL, &timeout) ) < 0) {
- err(1, "select() for read()");
- } else if (n == 0) {
- fprintf(stderr, "select() for read() timeout.\n");
- close(fd);
- sleep(PAUSE);
- exit(1);
- }
+ printf("back from write()\n");
+ sleep(PAUSE); /* required... */
bzero(rmesg, 16);
if ( (n = read(fd, rmesg, 15) ) < 0) {
err(1, "read()");
---
kkdlabs.jp, featuring Koh-ichi Ito as just another DNS freak in town.