'epoll echo server problem - The message sent by the client printed in the server terminal
I write this epoll echo server , when the client send a message it get the message back, but the same message is printed in the server terminal also, i dont do that but the message is printed in the server side, what is the problem please. thank you
this is my code: (sock_ is the lestening socket)
while(true){
int status = epoll_wait(fds, events, MAX_EVENTS,-1);
if(status>0){
for(int i =0; i<status;++i){
if(events[i].data.fd == sock_){
SOCKET new_sock = do_accept(sock_);
ev.data.fd=new_sock;
ev.events= EPOLLIN | EPOLLOUT;
epoll_ctl(fds, EPOLL_CTL_ADD, new_sock, &ev);
}else{
if(events[i].events&EPOLLIN and events[i].data.fd != sock_){
SOCKET scok = events[i].data.fd;
BYTES in = do_recv(scok);
if(in == 0){
close(events[i].data.fd);
epoll_ctl(fds, EPOLL_CTL_DEL, events[i].data.fd, &events[i]);
}
if(events[i].events&EPOLLOUT){
SOCKET scok = events[i].data.fd;
do_send(scok);
}
}
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
