flat assembler
Message board for the users of flat assembler.

Index > Windows > non-blocking STDIN read / find number of bytes in buffer

Author
Thread Post new topic Reply to topic
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid
i want to read characters which are buffered in STDIN, without blocking app ti let user type a line. or find out how many bytes are buffered, to prevent reading more.

do you know about some way to do this?


Last edited by vid on 01 Nov 2006, 17:55; edited 1 time in total
Post 31 Oct 2006, 12:30
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid
got it!
it's PeekNamedPipe (pretty self-explaining name, eh?)

now i just need same for linux (kernel call) :/
Post 31 Oct 2006, 13:24
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid
got it!
it should be enough to set O_NONBLOCK before reading and clear it afterwards.

hehe, i'm posting 3 times in a row, might be some kind of disease Wink
Post 31 Oct 2006, 13:34
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
shoorick



Joined: 25 Feb 2005
Posts: 1605
Location: Ukraine
shoorick
self-service
Post 31 Oct 2006, 14:02
View user's profile Send private message Visit poster's website Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid
SHIT!!! PeekNamedPipe doesn't work with STDIN.

any ideas?
Post 01 Nov 2006, 17:55
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
chris



Joined: 05 Jan 2006
Posts: 62
Location: China->US->China->?
chris
I think here is right place to go:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/base/console_functions.asp

as for non-blocking read from console, there is a C/C++ lib function _getch_nolock() as you can find in:
http://msdn2.microsoft.com/zh-tw/library/236adc23.aspx
Post 02 Nov 2006, 03:28
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid
chris: thanks, but i have studied console functions already. getc()_closk() is not what i want too, i know how to do that. problem is that getc_lock() still blocks when there is nothing in input buffer (from previous read).

anyway, it seems that win just doesn't support this. I can go without it, but this way my routines will be quite uneffective on win32. (well... little more effective than libc maybe).
Post 02 Nov 2006, 11:43
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
cod3b453



Joined: 25 Aug 2004
Posts: 619
cod3b453
Not sure if this is what you want but heres some code:

Code:
STD_INPUT_HANDLE equ 0xFFFFFFF6
ENABLE_LINE_INPUT equ 0x00000002
;...
hConI dd 0
Buffer rb 256
BufferSize dd ($ - Buffer)
BytesRead dd 0
;...
invoke [hConI],GetStdHandle,STD_INPUT_HANDLE                    ; Get console handle
mov [hConI],eax                                                 ;
invoke SetConsoleMode,[hConI],ENABLE_LINE_INPUT                 ; Set input to line input
                                                                ; This makes ReadConsoleA
                                                                ; only return when the user
                                                                ; presses enter
invoke ReadConsoleA,[hConI],Buffer,BufferSize,BytesRead,NULL    ; Read line into Buffer up to
                                                                ; BufferSize bytes, put bytes
                                                                ; written into BytesRead  

    


Or are you trying to do something else?
Post 02 Nov 2006, 12:08
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid
again not it Wink
Post 02 Nov 2006, 12:22
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar.

Powered by rwasa.