2017-06-13 62 views
-2
void epoll_func(epoll_event event){ 
char str[BUFSIZE] = {'\0'}; 
int c =0; 

if(event.data.fd == connfd && EPOLLIN){ 
    while(true){ 
     c = read(connfd, str, BUFSIZE); 

     write(1, str, c); 
     if(c<BUFSIZE) 
      break; 
    } 
}else if(event.data.fd == 0 && EPOLLIN){ 
    while(true){ 
     c = read(0, str, BUFSIZE); 

     send(connfd, str, c, 0); 
     if(c<BUFSIZE) 
      break; 
    } 
} 

}如何解决pty主写入从机读取。主写数据的高手也会读?

写数据到主机,也读出的数据写自己。怎么做?

非常感谢。

+1

欢迎来到Stackoverflow!请花些时间阅读[帮助页面](http://stackoverflow.com/help),尤其是名为[“我可以问些什么话题?”]的章节(http://stackoverflow.com/help/)讨论话题)和[“我应该避免问什么类型的问题?”](http://stackoverflow.com/help/dont-ask)。请参阅[tour](http://stackoverflow.com/tour)并阅读[如何提出良好问题](http://stackoverflow.com/help/how-to-ask)。最后,请学习如何创建[最小,完整和可验证示例](http://stackoverflow.com/help/mcve)。 – Markus

+0

看起来像C.为什么滥发C++标签? – Olaf

+0

'0 && EPOLLIN'可以表示得更简单;) – tofro

回答

0

你搞砸了你得到的epoll_event结构,它包含一个事件字段和一个包含数据的union。我想你想要做的事情如下:

struct epoll_event e; 

uint32_t e_type = e.events; 
int fd = e.data.fd; 

if (fd == myfd) { 
    if (events && EPOLLIN)) { 
     /* my watched fd and can be read from */ 
    } 
    if (events && EPOLLOUT) { 
     /* my watched fd and can be written to */ 
    } 
}