Timed Password Cancel

how i delete a post
Last edited on
little things:
just return 3, exit(3) is not useful.

unistd locks you on unix for no good reason. take that out unless you find something you simply
cannot do without it.

c++ version is <cstdlib>

and now your question...
getline is blocking. All C++ standard I/O is blocking, and you often have to use OS specific libraries to get around that.
What that means is that getline will wait on a line of text, so even if you had a timer in place, it would lock out the time-out functionality.
you can sort of rig it two ways:
you can use threads, where you have a thread that reads the input. If it times out, you can kill this thread and then shut down / time out that way.
if threading is too much for you, you can also just get the time AFTER the user provides input. If they were too slow, you ignore the input and exit. Problem is, if your time out is 20 seconds and they take 2 hours to type it in, it still waits the 2 hours...

I think there may be some clever rewire of stdin that can make this work, but I have not done it... you can try pointing the stdin stream to a different device that does not block, but honestly the easy way out is some sort of nonblocking library (windows has plenty, I do not know the unix ones).

this SO topic has a short example of a threaded solution:
https://stackoverflow.com/questions/6171132/non-blocking-console-input-c
this may be hard to follow, but timeout is a variable name, and he also could use return instead of exit.
Last edited on
Registered users can post here. Sign in or register to post.