K
Klaus
Hi,
I would like to write a non blocking single threaded application in
Linux, that:
1.) acts as a single client TCP server. (no forks)
A user should be able to connect to a port, and send a command
2.) reads data from stdin
Reading via the socket and stdin should be non blocking.
Therefore I guess, that I should use the select() (or perhaps poll())
command.
I do know how to use select() as soon as a client has connected,
but I don't know how to wait ( listen() ) and still be able to treat
input from stdin.
Any hints?
Thanks in advance and bye
Klaus
This is a pseudo sceleton of a main function:
main(){
int clientconnected=0;
while(!end){
if(!clientconnected){
select_call(stdin,listensocket); // THAT'S WHERE I NEED
// HELP
if(datafromstdin){
treatstdin();
}
if(listendata_available){
sock=accept(listensocket,...);
clientconnected=1;
}
} else {
select_call(stdin_socket);
ifif(datafromstdin){
treatstdin();
}
if (datafromsocket){
treatsocketdata();
}
}
}
}
I would like to write a non blocking single threaded application in
Linux, that:
1.) acts as a single client TCP server. (no forks)
A user should be able to connect to a port, and send a command
2.) reads data from stdin
Reading via the socket and stdin should be non blocking.
Therefore I guess, that I should use the select() (or perhaps poll())
command.
I do know how to use select() as soon as a client has connected,
but I don't know how to wait ( listen() ) and still be able to treat
input from stdin.
Any hints?
Thanks in advance and bye
Klaus
This is a pseudo sceleton of a main function:
main(){
int clientconnected=0;
while(!end){
if(!clientconnected){
select_call(stdin,listensocket); // THAT'S WHERE I NEED
// HELP
if(datafromstdin){
treatstdin();
}
if(listendata_available){
sock=accept(listensocket,...);
clientconnected=1;
}
} else {
select_call(stdin_socket);
ifif(datafromstdin){
treatstdin();
}
if (datafromsocket){
treatsocketdata();
}
}
}
}