Re: problem with addInput

View: New views
2 Messages — Rating Filter:   Alert me  

Parent Message unknown Re: problem with addInput

by Jeroen van der Zijp-5 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Monday 02 November 2009, you wrote:

> Hi Jeroen,
>
> I'm using fox toolkit on MS VC 6.
> I'm facing some problem with addInput() function.
>
> I've done the following
> 1. opened a file descriptor (FILE *) using fopen function.
> 2. Linked the file descriptor to an ID_FILE using addInput with flags
> INPUT_READ|INPUT_WRITE|INPUT_EXCEPT
> 3. added code in message map to link SEL_IO_WRITE and ID_FILE to a function
> OnFile
> 4. added button. on pressing the button, some data is written on the file.
>
> When data s being written on the file, I am expecting the function OnFile to
> be called, but that is not the case.
>
> I am attaching a copy the VC workspace. Please let me know whats wrong.
>
> Thanks and regards,
> -Kranthi
>


Kranthi,

No, this wouldn't work on Windows. And neither would it work on Linux.

First, when you call fopen(), the caller doesn't get an operating system
handle, but a pointer (FILE*).  A FILE is a C-library thing which performs
buffered I/O.

To get a file handle, you will need to call open() (unbuffered I/O) or fish
the file handle from FILE* by calling fileno().

This would be enough on Linux.



However, on Windows, POSIX is itself another layour on top of the WIN32 API.
The POSIX layer on Windows does *not* return WIN32 kernel handles!!

To be able to wait on a HANDLE using addInput(), you should pass a NT kernel
handle, such as something returned directly by WIN32 APIs, not POSIX APIs.

Internally, FOX uses MsgWaitForMultipleObjects() as the system call to wait
on various handles.  All these handles have to be WIN32 kernel handles, such
as are returned by WIN32 system calls (e.g. CreateEvent, CreateThread, etc).

Doing asynchronous I/O is possible on Windows, but its not so straightforward;
in fact, I'd recommend instead to create a separate I/O thread, let the I/O
thread do simple synchronous I/O, and let the main thread wait on the I/O thread
instead.

But if you absolutely insist... The first thing is to forget about POSIX system
calls, and instead use WIN32 API's exclusively.

In a nutshell, you can't actually wait on a file handle under Windows; you must
associate an Event object with a particular file I/O operarion through an OVERLAPPED
structure passed along with ReadFile or ReadFileEx.

I won't type up the entire story here on how to do it; first, it would take rather
long, and second, its been done by more knowledgable people already.

If you want to get the entire scoop, surf over to MSDN and search for:

        "Synchronization and Overlapped Input and Output"

I also recommend "Code Guru" as a source for example code dealing with all sorts
of Windows programming issues.


        Hope this helps,


                        - Jeroen

------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
Foxgui-users mailing list
Foxgui-users@...
https://lists.sourceforge.net/lists/listinfo/foxgui-users

Parent Message unknown Re: problem with addInput

by Jeroen van der Zijp-5 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Tuesday 03 November 2009, Kranthi Kiran wrote:

> Hi Jeroen,
>
> Thank you for the quick response. Now my plan of using addInput seems too
> good to be true :). Also, It would be really nice if you can put this
> information along with the documentation of addInput(). ( there seems to be
> lot of scope for confusion for naive programmers like me)
>
> One more question I had, If I open a socket on on VC 6, using
>
> serverSocket =socket(AF_INET,SOCK_STREAM,0);
>  can addInput bind serverSocket variable to an ID.

For sockets, it'll also have to be an event.  The asynchronous stuff on
Windows requires you to associate an Event object with the socket (pipe,
file ..) I/O.

Microsoft does provide a ton of information about this stuff, in their
on-line MSDN library documentation.  If you have VC++, you may have already
installed the online docs on your machine during installation.

Just remember, FOX's addInput() uses MsgWaitForMultipleObjects underneath;
thus, any HANDLE that can be watched my {Msg}WaitForMultipleObjects can also
be passed to app->addInput().

What you're looking for is WSAxxxx API's in the MSDN Windows docs. It helps
to read the overviews a bit to get an idea how things are structured.

Also good sources: Code Project and Code Guru websites (I believe I've already
mentioned the latter).


Good luck...





                - Jeroen


--
+----------------------------------------------------------------------------+
| Copyright (C) 17:40 11/ 3/2009 Jeroen van der Zijp.   All Rights Reserved. |
+----------------------------------------------------------------------------+

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Foxgui-users mailing list
Foxgui-users@...
https://lists.sourceforge.net/lists/listinfo/foxgui-users