U++ framework
Do not panic. Ask here before giving up.

Home » Community » Newbie corner » Stopping ReadStdIn() function
Re: Stopping ReadStdIn() function [message #57045 is a reply to message #57043] Mon, 17 May 2021 18:24 Go to previous message
Xemuth is currently offline  Xemuth
Messages: 387
Registered: August 2018
Location: France
Senior Member
Hello again Oblivion, I like the tiemout approach. here is what I did :
String ReadCmd(int timeout)
{
	String r;
	int time = msecs();
	
	while(msecs(time) < timeout){
		int c = 0;
		int n = read(STDIN_FILENO, (char*) &c, 1);
		if(c == '\n')
			break;
		if(n > 0) {
			r.Cat(c);
			time = msecs();
		}
	}
	return r.GetCount() ? r : String::GetVoid();
}

It now work perfectly. Thanks for your precious help !

[Updated on: Mon, 17 May 2021 18:29]

Report message to a moderator

 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: static
Next Topic: my TCP client/server don't work correctly
Goto Forum:
  


Current Time: Wed Oct 07 16:45:43 GMT+2 2026

Total time taken to generate the page: 0.04212 seconds