Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2011-12

Re: How to poll for a byte in Input?

3 messages · 2 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

tcoq

I have found and tried WaitForSingleObject, using the following syntax:

ThereIsACharacterToRead :=   WaitForSingleObject(StdInputHandle,0) = 0;
While ThereIsACharacterToRead do
begin
  aByte := InputStream.ReadByte;
  ThereIsACharacterToRead :=   WaitForSingleObject(StdInputHandle,0) = 0;
end;

However, WaitForSingleObject always gives back 0, meaning there should be information. My logging tells me that information arrives at least 500ms afterwards and that ReadByte waits for it. Something is not working. Thierry

----- Mail Original -----
De: "tcoq"
À: "FPC-Pascal users discussions"
Envoyé: Vendredi 9 Décembre 2011 17h56:13 GMT +01:00 Amsterdam / Berlin / Berne / Rome / Stockholm / Vienne Objet: Re: [fpc-pascal] How to poll for a byte in Input?

On windows, I did not find WaitForSingleObject, which is actually going to wait for the file. However I found ReadFileEx in the Windows API, which is an asynchronous read on the file. I'll try using that.

----- Mail Original -----
De: "Michael Van Canneyt"
À: "FPC-Pascal users discussions"
Envoyé: Vendredi 9 Décembre 2011 16h57:47 GMT +01:00 Amsterdam / Berlin / Berne / Rome / Stockholm / Vienne Objet: Re: [fpc-pascal] How to poll for a byte in Input?

...

You must use fpSelect() or Poll on the handle on linux/unix. On windows, you'll need to WaitForObject() or so on the file handle.

Michael.

Michael Van Canneyt
to tcoq
tcoq wrote 12 lines
I have found and tried WaitForSingleObject, using the following syntax: ThereIsACharacterToRead := WaitForSingleObject(StdInputHandle,0) = 0; While ThereIsACharacterToRead do begin aByte := InputStream.ReadByte; ThereIsACharacterToRead := WaitForSingleObject(StdInputHandle,0) = 0; end; However, WaitForSingleObject always gives back 0, meaning there should be information. My logging tells me that information arrives at least 500ms afterwards and that ReadByte waits for it. Something is not working.

I do not think this is correct if the timeout is zero. You should specify a timeout.

Michael.

tcoq
to Michael Van Canneyt

Thanks Michael,
I also tried with a 20 ms delay. No success. Still investigating. ----- Mail Original -----
De: "Michael Van Canneyt"
À: "FPC-Pascal users discussions"
Envoyé: Vendredi 9 Décembre 2011 22h51:01 GMT +01:00 Amsterdam / Berlin / Berne / Rome / Stockholm / Vienne Objet: Re: [fpc-pascal] How to poll for a byte in Input?

...

I do not think this is correct if the timeout is zero. You should specify a timeout.

Michael.