-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;
    }   
}   

}

Write data to the master, but also read the data to write their own. How to do?

thanks very much.

bob.smart
  • 23
  • 1
  • 5
  • 1
    Welcome to Stackoverflow! Please take some time to read [the help pages](http://stackoverflow.com/help), especially the sections named ["What topics can I ask about here?"](http://stackoverflow.com/help/on-topic) and ["What types of questions should I avoid asking?"](http://stackoverflow.com/help/dont-ask). Also please take the [tour](http://stackoverflow.com/tour) and read about [how to ask good questions](http://stackoverflow.com/help/how-to-ask). Lastly please learn how to create a [Minimal, Complete, and Verifiable Example](http://stackoverflow.com/help/mcve). – Markus Jun 13 '17 at 08:43
  • Looks like C. Why spamming the C++ tag? – too honest for this site Jun 13 '17 at 08:55
  • `0 && EPOLLIN` can be expressed much simpler ;) – tofro Jun 13 '17 at 08:59

1 Answers1

0

You are messing up the epoll_event structure you get which consists of an event field and a union containing the data. I suppose you want to do something like the following:

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 */
   }
}
tofro
  • 4,966
  • 11
  • 29