|
The way I understand Overlapped or async . I/O is the following
In the Server or Dos Program (in my case) I do a CreateNamePipe
Create The hEvent via CreateEvent for the hEvent which is part of Overlapped stucture
I then do a Connectnamed pipe waiting for the Client (in My case Windows Program ..started with CreateProcess)
to connect
In the Client (my Windows program) does A CreateFile which effectivly establishes the connection
with FILE_FLAGGED_OVERLAPPED making this a async./overlapped connection
It was my understanding that If my Windows program were to do a WriteFile that hEvent of the Overlapped
structure would be signaled and that is Why I thought it was A KernelObject that had to be shared by the
Client (Dos Console) when doing the ReadFile or Have A WaitForSingleObject withe shared hEvent just before
the ReadFile
|
|
|
|
|
ForNow wrote: making this a async./overlapped connection
It's not the connection that is asynchronous/overlapped....
it's individual I/O operations that can be executed asynchronously/overlapped.
The client end knows nothing about your server's overlapped operations
and vice versa.
When you do an overlapped I/O operation, you're essentially just queuing the operation
for completion asynchronously relative to the thread starting the operation.
When your server does an overlapped ConnectNamedPipe(), the event you pass in
your overlapped struct is used to signal the completion of that operation only, which
is when a client connects with CreateFile() or CallNamedPipe(). The system will
signal the event.
The server then could then call ReadFile() overlapped/asynchronously to read data
from the client, in which case you could use the event to know when the read operation
is complete. Again, the system signals the event.
An overlapped structure holds a context for each operation (and anything else you
want to put in there).
How you manage the overlapped structs and their lifetime is up to you. The system just passes
them around (e.g. you get the same LPOVERLAPPED back in GetOverlappedResult()).
Make sense? There's nothing about any of this requiring an endpoint to have the other
end's event handles or overlapped structs. The client could use synchronous I/O while
the server uses asynchronous I/O, or whatever combination you want.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Thankx
Do I use the same hEvent from the ConnectNamedPipe for Readfile Writefile ???
Does the Overlapped with hEvent Haver to be In Global Storage I would think it would be a good Idea if Readfile and
Writefile use it it should n't be on the Stack of any routine
Thankx Again
|
|
|
|
|
ForNow wrote: Do I use the same hEvent from the ConnectNamedPipe for Readfile Writefile ???
You can. It depends on how you plan to use the event and how many outstanding
operations you plan on having at any given time.
Typically, you'd use the event if you have an I/O completion thread (or threads)
that waits for the signalled event(s) and processes the completed I/O operation.
In that case, you only need one event per completion-handler thread.
If you're not using completion handler threads then you don't need the event
at all - you can poll for completion with GetOverlappedResult().
Note that with ConnectNamedPipe() you'd probably want/need to use a handler thread -
essentially a "listener" thread listening for incoming client connections.
You need to manage the lifetime of the overlapped structs as well as any event handles you create.
For the event handles, the handle is stored in the OVERLAPPED struct so you only need to
free it when you're no longer using the struct object.
For the OVERLAPPED structures themselves - you may need only one or many depending on
how you're handling your I/O. You can even implement a pre-created pool of them.
FWIW, you can wrap OVERLAPPED structs in any structure you want to, as long as you pass
a pointer to the OVERLAPPED struct to functions that use it. That's handy for keeping
things like allocated I/O buffers with an OVERLAPPED struct.
Example: I have used something similar to this for read/write I/O...
#pragma pack( push, MY_OVERLAPPEDpack, 1 )
struct MY_OVERLAPPED
{
OVERLAPPED Overlapped;
SomeClass *pOwnerObject;
DWORD DataBufferLength;
BYTE *pDataBuffer;
};
#pragma pack( pop, MY_OVERLAPPEDpack)
typedef CTypedPtrList<cptrlist,> MY_OVERLAPPEDPtrList;
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
BTW do you work for MicroSoft What Does MicroSoft MVP imply ???
Thanx Again Going to give it a shot
|
|
|
|
|
|
ForNow wrote: I would think so ...
Why? An endpoint knows NOTHING about the use of overlapped I/O
on the other end.
ForNow wrote: Do I have Share the hEvent Kernel Object which is part othe Overlapped Structure
No
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Hi all. I'm implementing a macro that I need to have take multiple parameters.
Let's say I'm implementing a printf macro. (I know. I know. Just run with me for the example. )
#define PRINT(str,...) printf(str,__VAR_ARGS__);
Well, obviously, someone could invoke the macro thusly:
PRINT("My name is %s and I am %i years old.", szName, iAge);
After doing some research, I found __VAR_ARGS__ on gamedev.net. Just one problem: Visual Studio 2008 is not aware for __VAR_ARGS__.
Am I misspelling __VAR_ARGS__ or something?
What header file is __VAR_ARGS__ (or its correctly spelled version!!) defined?
K, thanks!
|
|
|
|
|
varargs.h by any chance?
|
|
|
|
|
Well, actually, I think I figured it out.
It's: __VA_ARGS__
#define PRINT(str,...) printf(str, __VA_ARGS__); //not __VAR_ARGS__ lose the first 'R'.
|
|
|
|
|
indeed, however vaargs.h won't cut it.
|
|
|
|
|
hehe. Yeah, I'm still searching for where __VA_ARGS__ *is* defined. I wonder if it's hardcoded into the compiler itself. The C99 standard says it should be supported - whether MS supports it or not I'm truly not at liberty to say until I've tested my still compiling application. (~700K lines).
|
|
|
|
|
I searched for varargs.h and only my WinARM and cygwin directories have those files.
Still searching the tree for __VA_ARGS__.
|
|
|
|
|
Hi, my folder C:\Program Files\Microsoft Visual Studio 9.0\VC\include
holds a varargs.h file containing definitions for _VA_LIST, va_start(ap), va_arg(ap,t), and more.
Yes, __VA_ARGS__ seems not to be there, I think you're right the compiler knows all about that one without any include file.
[ADDED]
Their documentation[^] knows about it; and you could test it with a much smaller program...
[/ADDED]
modified on Tuesday, December 9, 2008 1:09 PM
|
|
|
|
|
/hug
See, this is why I love The Code Project!
Thank you, Luc!
|
|
|
|
|
Looking at this page about variadic macros[^], it should be __VA_ARGS__?
You won't find it in any header file, though, because it's something built into the pre-processor.
|
|
|
|
|
i need help wrapping text for a clistctrl
i'm using either ownerdraw or customdraw to draw the items with multiple lines
my only problem is setting the individual row heights
i tried using ownerdraw + measureitem but that sets the heights of all the rows
any suggestions? thanks
|
|
|
|
|
|
that solution was for a ctreectrl
i'm now working on a clistctrl
i've been looking around and i dont think clistctrl has that iIntegral value to change the individual heights
|
|
|
|
|
oops
led mike
|
|
|
|
|
|
imagine a struct declared as follows:-
typedef struct
{
int integerArray[];
} testStruct;
I can instantiate like this:-
testStruct a = {
{1,2,3}
};
Which is all well and good. But, if the struct declaration is changed to an int* member:-
typedef struct
{
int *integerArray;
} testStruct;
How can I now instantiate it so that integerArray points to my array of {1,2,3} ??
in gcc, you can cast {1,2,3} to (int *), as follows:-
testStruct a = {
(int *){1,2,3}
};
But msvc doesn't allow that. Is there another way to make this instantiation?
thanks
Jon
|
|
|
|
|
Jon Hulatt wrote: Is there another way to make this instantiation?
How about:
testStruct a = { new int(1), new int(2), new int(3) };
"Love people and use things, not love things and use people." - Unknown
"The brick walls are there for a reason...to stop the people who don't want it badly enough." - Randy Pausch
|
|
|
|
|
Very clever, anyway I suspect he wants the allocation to happen onto the stack.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
How do we programmatically come to know whether an executable is digitally signed or not?
Is the signature in the form of section or a structure?
If it is like a structure then is there any document structure for it.
Does the size of the signature stored stored anywhere?
I am having two samples of same dll viz. signed and unsigned.
I find the difference in windiff only at the end of the files.
Thanks & Regards,
K. Sushilkumar.
|
|
|
|