【问题标题】:How to solve the pty master write slave read. Master write the data master will also read?如何解决pty master write slave read。高手写数据高手也会读?
【发布时间】:2017-06-13 08:39:58
【问题描述】:
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;
    }   
}   

}

给master写数据,也读到自己写的数据。怎么办?

非常感谢。

【问题讨论】:

标签: c++ c linux pty


【解决方案1】:

你弄乱了你得到的 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 */
   }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-08-06
    • 2014-12-17
    • 1970-01-01
    • 2023-03-18
    • 2017-09-01
    • 1970-01-01
    • 2017-01-30
    • 1970-01-01
    相关资源
    最近更新 更多