Sign in Join

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

Mailing lists / fpc-pascal / 2010-05

Re: fpc-pascal Digest, Vol 71, Issue 50

2 messages · 2 people ·

Reply by email Subscribe to this list Your subscription

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

Hartmut Eilers

Hallo Henry,

thank you for your fast response.
Sorry to say, that I don't understand what you suggest. Could you explain it a bit more ?

Thanks a lot
Hartmut

Show quoted text 28 lines
> I have the following code which I want to port to Windows, but > I have no idea how the functionality of SelectText may be done > in Windows. I googled a lot but unfortunately I found nothing > that helped me out. How is something like that handled under > Windows ? > >        {$I-} >                if debug then writeLOG('Sock2Text'); >                Sock2Text(sock,sin,sout); >                if debug then writeLOG('reset'); >                reset(sin); >                //if debug then writeLOG('rewrite'); >                //rewrite(sout); >        {$I+} >                if debug then WriteLOG('Reading requests...'); >                if (SelectText(sin,10000)>0) then begin >                        Addr_len:=SizeOf(cli_addr); >                        csock:=accept(sock, cli_addr,Addr_len); >                        Sock2Text(csock,ccsin,ccsout); >                        reset(ccsin); >                        rewrite(ccsout); >                        process_request; You can probably get the same effect by using overlapped i/o on the file and one of the wait functions, like WaitForSingleObject. Henry
Henry Vermaak
to Hartmut Eilers
Hartmut Eilers wrote 5 lines
Hallo Henry, thank you for your fast response. Sorry to say, that I don't understand what you suggest. Could you explain it a bit more ?

SelectText monitors a file descriptor for input (or output) to become ready for up to the timeout you specify. You can probably get the same effect on win32 by opening the file specifying an overlapped structure, which will enable you to do async i/o. The a call to readfile will return immediately, at which point you can call WaitForSingleObject with a timeout. You can check the result to see if anything was read during the timeout specified.

More info here:

http://msdn.microsoft.com/en-us/library/ms686358%28v=VS.85%29.aspx

If you have other calls to select (on file descriptors), you might want to consider using something like libevent, which solves these things in a cross platform way. Or if you're brave you can look at cygwin's implementation of select (
http://www.cygwin.com/cygwin-ug-net/highlights.html#ov-hi-select ).

Henry