Hello,
I'm writing a very simple server/client chat. At the moment I have no way of determining when data arrives in the receive buffer.
This is how the send/receive part of the chat currently looks like:
This code is very primitive, I was looking for some means to determine when data were available on the listening side. After some reading about select()/poll() and performance issues I decided to try Kqueue() instead. I did only find a few example uses of Kqueue()
but this is what I tried:
Unfortunately this didn't work out very well, and I still don't think I got it right because return still has to be pressed for reading and printing data from the buffer.
How can I improve this?
Ideas and comments are welcome.
I'm writing a very simple server/client chat. At the moment I have no way of determining when data arrives in the receive buffer.
This is how the send/receive part of the chat currently looks like:
Code:
.
.
.
for(;;){
fgets(sendbuffer,sizeof sendbuf,stdin);
send(acceptfd,sendbuffer,sizeof sendbuffer,0);
recv(socketfd,recvbuff,sizeof recvbuff,0);
printf("%s",recvbuff);
}
but this is what I tried:
Code:
struct kevent events;
struct kevent changes;
int new_event;
EV_SET(&changes,sockfd,EVFILT_READ,EV_ADD | EV_ENABLE,0,0,0);
for(;;){
new_event = kevent(kq,&changes,1,&events,1,NULL);
if(events.flags & EVFILT_READ){
// call recv..
}
else ...
//call fgets and send
}
Unfortunately this didn't work out very well, and I still don't think I got it right because return still has to be pressed for reading and printing data from the buffer.
How can I improve this?
Ideas and comments are welcome.