- #1
James889
- 192
- 1
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 is very primitive, i would like to use kqueue() to decide when data is available on the listening socket. So i looked at a few examples of how to use kqueue but i didn't get it working properly. This is what i tried..
unfortunately this didn't work out very well, i still have to press return for reading and printing data from the buffer.
Any suggestions?
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);
}
This is very primitive, i would like to use kqueue() to decide when data is available on the listening socket. So i looked at a few examples of how to use kqueue but i didn't get it working properly. 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, i still have to press return for reading and printing data from the buffer.
Any suggestions?