Skip to main content
gamedev.net
🔒 Locked

Stdin behaviour

Started by md_lasalle Feb 21, 2007 at 8:32 AM 1 replies 400+ views
Original Post
md_lasalle
md_lasalle
hey all! I'm having problem understanding what happens on my game server under Linux ( doesnt happen in win32 ) The server is setuped like that : 1) a thread running the game logic ( game server itself ) 2) a thread running the console ( to get user inputs blocking on cin.getline ) After a certain time, the game reacts as if someone was at the server console, and holding the Enter key indefinitly. Thus, making my server lock threads forever since it is always receiving inputs from the console. The input is an empty string. What is the REAL good way of getting input stdin WITH SPACES without getting any stdin corruption? Any suggestions or different approach are welcomed. Thanks
Bregma
Bregma
Do you check the status of cin after the getline returns? An empty string sounds like the file has been closed or there is some other error condition. ANy I/O can fail or obtain an error state. You always need to check.

--smw
Stephen M. Webb
Professional Free Software Developer
md_lasalle
md_lasalle
thank you i'll check for that

but could it happen even if no one is inputing ? like getline returns for some reason ( an error maybe ) even if i did not input anything ?

i read somewhere that stdin in Linux is like socket # 0 , do you think i can somehow get a socket of 0 after i created a new one ? and then close it thus corrupting stdin ?

Any lights on this would be greatly appreciated, thank you

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.