2012-08-07 47 views
1

我有一个伪终端奴隶给我一个读/写错误资源暂时不可用(11)。我一直无法解决这个问题,但直到一个星期前,我不知道任何pty的。所以,我可能会错过一些明显的东西。伪终端(pty)报告资源暂时不可用

从我读过的内容来看,这可能是由于在非阻塞的pty上调用read()造成的。但是,当我检查F_GETFL后面的open() slave pty时,该值表明它是一个阻塞文件描述符。

F_GETFL的输出显示O_NONBLOCK标志为禁止,O_RDWR标志被允许:

printf("F_GETFL: %x\n", fcntl(slavefd, F_GETFL)); // outputs F_GETFL: 2 

我甚至试过治疗slavefd为非阻塞文件使用select()来决定当它准备。但是,每次都只是超时。

那么,为什么read() errno设置为资源暂时不可用如果slavefd被设成阻塞? F_GETFL的标志看起来是否正确?我还可以尝试缩小这个问题的原因吗?

更新:(详细信息)

我不知道,但我觉得pty从属设备节点正在被pppd不知何故被锁定。我被告知你可以回显到pty slave,这似乎是正确的,除非pppd正在使用它。

更新2:(添加的代码)

​​

此更新显示我如何打开从设备。由于我正在使用此应用程序进行调试,因此我只是直接使用argv[1]

问题迎刃而解:

,我试图将读/写正在由pppd的改性的从节点。当pppd控制一个tty/pty设备时,它将行纪律N_TTY更改为N_PPP。这意味着当您将open()然后read()write()添加到从节点时,将使用PPP中间驱动程序而不是TTY驱动程序。所以,read()write()归结为一个完全不同的功能。看着N_PPP驱动程序,我发现了以下内容。这回答了我为什么要退回EAGAIN的问题。

/* 
* Read does nothing - no data is ever available this way. 
* Pppd reads and writes packets via /dev/ppp instead. 
*/ 
static ssize_t 
ppp_asynctty_read(struct tty_struct *tty, struct file *file, 
      unsigned char __user *buf, size_t count) 
{ 
    return -EAGAIN; 
} 

/* 
* Write on the tty does nothing, the packets all come in 
* from the ppp generic stuff. 
*/ 
static ssize_t 
     ppp_asynctty_write(struct tty_struct *tty, struct file *file, 
      const unsigned char *buf, size_t count) 
{ 
    return -EAGAIN; 
} 
+0

您是否设置了接收超时? (设置setsockopt) – craig65535 2012-08-07 18:34:34

+0

我试过你的建议,但我遇到了错误'套接字操作在非套接字(88)' – rkyser 2012-08-07 19:03:06

+0

对不起,如果我不清楚。我只是想知道是否有超时设置,因为这是read()可以返回EAGAIN的另一种情况。但看起来情况并非如此。 – craig65535 2012-08-07 19:06:45

回答

1

,我试图将读/写正在由pppd的改性的从节点。当pppd控制一个tty/pty设备时,它将行纪律N_TTY更改为N_PPP。这意味着当您将open()然后read()write()添加到从节点时,将使用PPP中间驱动程序而不是TTY驱动程序。所以,read()write()归结为一个完全不同的功能。看着N_PPP驱动程序,我发现了以下内容。这回答了我为什么要退回EAGAIN的问题。

/* 
* Read does nothing - no data is ever available this way. 
* Pppd reads and writes packets via /dev/ppp instead. 
*/ 
static ssize_t 
ppp_asynctty_read(struct tty_struct *tty, struct file *file, 
      unsigned char __user *buf, size_t count) 
{ 
    return -EAGAIN; 
} 

/* 
* Write on the tty does nothing, the packets all come in 
* from the ppp generic stuff. 
*/ 
static ssize_t 
     ppp_asynctty_write(struct tty_struct *tty, struct file *file, 
      const unsigned char *buf, size_t count) 
{ 
    return -EAGAIN; 
} 
相关问题