|
The logic is correct as WAIT_OBJECT_0 , WAIT_OBJECT_0 +1, ... are basically a constants and with switch it is valid to select between constants. However if your application is a high data rate app then be careful with the "linear search" of the WaitForMultipleObjects() function! It is actually documented (check its msdn page) that this function always returns the FIRST signaled handle from the array. This means if you have a "hyperactive" handle near the beginning of the array then the rest of the handles at higher indexes will starve. One technique to defend against this is "rotating" items in the array (or maybe a more fair algorithm is moving the currently signaled handle to the end of the array...).
In case of Overlapped IO I would rather suggest using an IO completion port (shortly: IOCP) that isn't hard to plumb on top of your existing overlapped code, the difficult part is the overlapped IO that is ready in your case.
|
|
|
|
|
Thanks R.M.
pasztorpisti,
When I look at the MSDN page for WaitForMultipleObjects() I do not find that warning. I have seen one topic with two pages that someone found and I did not. Maybe this is one.
However, I think I understand your linear search comment. This will be an almost exclusively output utility. The first N events for the Wait function will be on the lines of, Start running, Stop running, start and stop logging, etc. They will be infrequently used. I plan on 16 events for buffers to be sent out, an arbitrary starting number. The app that sends the data will use them in a strictly circular fashion. It will load the address of a buffer to send and trigger an event. The TCP/IP code in the thread will send the next buffer, the next item whose address is not zero.
When an I/O completes, the event will be triggered, and the address set to zero. These events and addresses will be closely monitored to determine the average backlog of the outgoing data and to determine how well this keeps up with the incoming data. The high data rate stream is 12 megabits per second and there can be multiple stream of it from two or more sources.
I have another app that runs with blocking TCP/IP code and it works, but the blocking I/O causes some difficulties. Now I am researching and designing how I will put the TCP/IP part in a separate thread. I wrote a test app that just starts the thread and get the start/stop/end messages to it. Now for the TCP part.
Thank you for your time
If you work with telemetry, please check this bulletin board: www.irigbb.com
|
|
|
|
|
Here is that paragraph from the msdn doc:
"When bWaitAll is FALSE, this function checks the handles in the array in order starting with index 0, until one of the objects is signaled. If multiple objects become signaled, the function returns the index of the first handle in the array whose object was signaled."
This means, if your first handle is very active then your WaitForMultipleObjects() has good chances to return the first handle even if there are other similarly active signaled handles at higher indexes. You may not even notice this on a strong machines but this behavior may happen only on some slower machines with less cores... Even in that case it isn't really a "BUG", its just starvation that is about as hard to debug as timing related thread-sync issues. Although the paragraph in the msdn doc is not a warning underlined with multiple red lines it is something that can cause you a lot of headaches if your app starts to misbehave just in some special hard-to-reproduce circumstances.
|
|
|
|
|
Now, I have a ActiveX.
And I want to create a SDI, while clicking a button in the activex.
How to do that?
Thanks,
Lux
|
|
|
|
|
I need atlbase.h.
I have Windows 8.1 x64 with VC++ 2008 Express.
How can I get this file? Where is this file?
|
|
|
|
|
ATL[^] is only provided with the purchased versions of Visual Studio, not the Express Editions.
|
|
|
|
|
|
|
VC++ 2010 is not giving any option to add web service/web reference.
how can it achive??
|
|
|
|
|
|
VC++ 2010 wizard do not show Add WEB Reference/Service option when i select MFC project. this option was avaiable in previous version of IDE.
attached link is not useful info for my problem..
|
|
|
|
|
|
Recently,
I'm using the Ribbon XML to build a button in Word 2007.but i need to custom the image of button.
so,I find something form the url: http://msdn.microsoft.com/en-us/library/office/dd548011(v=office.12).aspx[^]
keywords:OnLoadImage
question: It's only use VBA to solve the problem,I'm realy don't know how to use c++ to solve this.
Please help me and give me some suggestions!
best wash!
|
|
|
|
|
Hi,
Has anyone used unit testing for ATL project?
I am currently exploring ALM in VS 2010 ,Is it really worth the efforts?
jigar
|
|
|
|
|
Windows 7, Visual Studio, C++, MFC and non console type applications that have no windows
Given:
WCHAR destination[ 60 ]
WCHAR source[ 60 ]
Presume: destination has 20 characters to be retained.
What is the best method of copying all the characters that will fit from source into destination?
Easy enough for ASCII, but difficult for this WCHAR novice.
Thanks for your time
If you work with telemetry, please check this bulletin board: http://www.bkelly.ws/irig_106/
|
|
|
|
|
Just use the wcscpy [^] function. There are wide versions of all the character manipulation functions.
Veni, vidi, abiit domum
|
|
|
|
|
Refer back to the OP. The strings have the same maximum length. String destination already has 20 characters so 60 more will not fit.
Function wcscpy() has only two arguments, destination and source. We can write the destination in the format: destination[20] to start there, but there is no way to specify that only 39 of the source characters are to be copied.
However, having seen that, I then found wcscpy_s() with three arguments. We can specify destination[ 20 ], then specify the second argument would be 40.
We can generalize this with a calculated length. But I am unsure about the right functions to use with WCHAR to get the max length and to get the current length. I will try to find that and post again.
Thanks for your time
If you work with telemetry, please check this bulletin board: http://www.bkelly.ws/irig_106/
|
|
|
|
|
|
Yes, you are so right. Found the page, got the function, using it.
Thank you for taking the time to reply.
Thanks for your time
If you work with telemetry, please check this bulletin board: http://www.bkelly.ws/irig_106/
|
|
|
|
|
Not sure what you mean by 20 characters needing to be retained. No need to walk the string one-by-one...
wcsncpy_s(destination, 60, source, 20);
Will take the first 20 characters of source and copy them to destination. But if you must walk it one-by-one are several ways...
for(i=0; i < 60; i++)
{
WCHAR *current = &source + (sizeof(WCHAR) * i);
destination[i] = *current;
WCHAR current = source[i];
destination[i] = current;
}
I'd never declare a variable in a loop like that, so it's just for illustration. Anyway, you can do whatever logic you want to skip the first 20 chars in destination at that point.
Jeremy Falcon
|
|
|
|
|
Windows 7, Visual Studio 2008,C++, TCP/IP
Please describe what “overlapped” means in terms of Windows sockets I/O. I found some pages but they describe how to use it rather than what it really is.
Full Motivation
My application will perform high data rate TCP/IP output, and it will be rather bursty. It will call the send function several times in rapid function.
Will the use of the overlapped mode provide an advantage?
My presumption is that the app can initiate TCP/IP output on multiple buffers and each becomes an almost completely separate I/O function.
More Info
The app will send out what I call messages. Each message can have its own unique buffer containing all the packet overhead and data. Message A (of A through Z) will very seldom be sent twice in a single burst. I can arrange for an array or structure of messages A through Z keeping them completely separate from each other. Using that, I am thinking that the overlapped option will be useful.
From this Microsoft web page:
http://msdn.microsoft.com/en-us/library/windows/desktop/ms740087(v=vs.85).aspx
My reading of the last four or so paragraphs, indicates that overlapped will facilitate the fast and bursty I/O needed.
Further reading leads me to tentatively conclude that the app can call WSAGetOverlappedResult passing in the address of each specific buffer (along with other goodies) and the return value will indicate if the I/O has completed to the point that the app can re-write that buffer without fear of any data being lost.
Bonus Question
In the web page for WSAGetOverlappedResult, the minimum supported client is Windows 2000 Professional [desktop apps only]. Does that include Windows XP Pro and Windows 7?
I see there is more to this and am studying the help page on WSAGetOverlappedResult and WSAOVERLAPPED structure. (Hmmm, event handle. That looks helpful, as in WaitForMultipleObjects())
Conclusion
I don’t ask for all the details, just a basic explanation and comment as to if I am going down a viable and/or a good path.
Thanks for your time
If you work with telemetry, please check this bulletin board: http://www.bkelly.ws/irig_106/
|
|
|
|
|
bkelly13 wrote: Please describe what “overlapped” means in terms of Windows sockets I/O. It means that the operations will run asynchronously, leaving your application free to do other work. You then need to go back at some other point to check whether the operation has completed, and if so, was it successful.
bkelly13 wrote: Does that include Windows XP Pro and Windows 7? Yes, see http://en.wikipedia.org/wiki/Comparison_of_Microsoft_Windows_versions[^].
bkelly13 wrote: if I am going down a viable and/or a good path. Always a difficult one to answer since it depends on so many factors. It would appear to be a sensible choice, but you would need to run some tests for yourself to be sure.
Veni, vidi, abiit domum
|
|
|
|
|
Hello Richard,
In at least one MSDN help page about socket functions, they write that overlapped is not the same as sync and async. They work together but are not the same. As I interpret the pages:
Overlapped means having multiple buffers submitted for I/O at one time. The app can, for example post four sends with four separate addresses (addresses of buffers to send). After the four posts it can be the case that none of them have been signaled as complete. The operating system will then signal each of the four I/Os as being complete some time later. The application must not disturb those buffers until each one has been signaled as complete.
As each one is signaled complete, the application can re-use that buffer, but not until then.
In the WSASend function argument six is structure WSAOVERLAPPED. We can use WSASend and other TCP/IO functions with async but without overlapped. Or with overlapped.
Is my interpretation correct, as far as it goes?
Thanks for your time
If you work with telemetry, please check this bulletin board: http://www.bkelly.ws/irig_106/
modified 20-Jan-14 12:17pm.
|
|
|
|
|
bkelly13 wrote: Is my interpretation correct, as far as it goes? That is my understanding of it. Maybe this whitepaper[^] will help to clarify it.
Veni, vidi, abiit domum
|
|
|
|
|
Hello Richard,
In that article, the second paragraph in the section titles Overlapped I/O, is a sentence that beings with:
Quote: If you use the SO_RCVBUF and SO_SNDBUF option to set zero TCP stack receive and send buffer, ....
I think I understand the remainder of the paragraph as saying: We can call the send or receive function telling the OS and the TCP part of the OS, to use the buffer we have supplied as the buffer to output/input the data. That saves the OS/TCP code from performing a copy of the data. This reduces the total number of CPU cycles dedicated to performing my I/O operation. It also means, as I noted earlier, our app cannot touch that buffer until the send/receive is complete.
That said, just what does that quoted part of the sentence mean? "... to set zero TCP stack ..." That appears to be just a simple case of not very good choice of words. On the other hand, I may be missing something important.
Thanks for your time
If you work with telemetry, please check this bulletin board: http://www.bkelly.ws/irig_106/
|
|
|
|
|