473,394 Members | 1,761 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Overlapped IO problem on x64

Hi.

I have a C# app that uses named pipes via InteropServices. I have no
problems running on a 32-bit machine, or when targeting x86 architecture, but
it fails on a 64-bit machine when targeting x64 or AnyCPU.
The problem appears to be that ReadFile() sets lpNumberOfBytesRead to 0,
even though the receive buffer contains the data I'm expecting.
Is this a known issue, or am I just doing something dumb?
I can provide a small test app via email if needed.
Thanks,

-Nick
Nov 6 '08 #1
7 4581
Good morning Nick,

I appreciate it if you can send the test app to my mailbox:
ji****@microsoft.com, and this will give me a clearer picture of the
symptom and I will try to figure out the reason. Thanks

Jialiang Ge (ji****@online.microsoft.com, remove 'online.')
Microsoft Online Community Support

=================================================
Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
ms****@microsoft.com.

This posting is provided "AS IS" with no warranties, and confers no rights.
=================================================

Nov 6 '08 #2
Hi Jialiang.

Thanks for your reply.
I don't seem to be able to send you email. Here's the bounce message:

<ji****@microsoft.com>:
216.32.181.22 does not like recipient.
Remote host said: 554 <ji****@microsoft.com>: Recipient address rejected:
Access denied
Giving up on 216.32.181.22.

-Nick
""Jialiang Ge [MSFT]"" wrote:
Good morning Nick,

I appreciate it if you can send the test app to my mailbox:
ji****@microsoft.com, and this will give me a clearer picture of the
symptom and I will try to figure out the reason. Thanks

Jialiang Ge (ji****@online.microsoft.com, remove 'online.')
Microsoft Online Community Support

=================================================
Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
ms****@microsoft.com.

This posting is provided "AS IS" with no warranties, and confers no rights.
=================================================

Nov 6 '08 #3
My appology, Nick. I typed my mail address wrong. It should be
ji****@microsoft.com.

Best Regards,
Jialiang Ge (ji****@online.microsoft.com, remove 'online.')
Microsoft Online Community Support

=================================================
Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
ms****@microsoft.com.

This posting is provided "AS IS" with no warranties, and confers no rights.
=================================================

Nov 7 '08 #4
That seems to be working, thanks. Check your email...

-Nick
""Jialiang Ge [MSFT]"" wrote:
My appology, Nick. I typed my mail address wrong. It should be
ji****@microsoft.com.

Best Regards,
Jialiang Ge (ji****@online.microsoft.com, remove 'online.')
Microsoft Online Community Support

=================================================
Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
ms****@microsoft.com.

This posting is provided "AS IS" with no warranties, and confers no rights.
=================================================

Nov 7 '08 #5
Hello Nick

Thank you for the sample. I spent the past four hours on this issue.
Although I have not figured out the cause of the symptom, I'd like to
update you about my current research results.

1. I debugged your sample in x64 and x86 machines and noticed that the
_OVERLAPPED struct's Internal and InternalHigh values were set differently:

x64:

KERNEL32!_OVERLAPPED
+0x000 Internal : 0x103
+0x008 InternalHigh : 0 ' always 0
+0x010 Offset : 0
+0x014 OffsetHigh : 0
+0x010 Pointer : (null)
+0x018 hEvent : 0x00000000`00000220

x86:

KERNEL32!_OVERLAPPED
+0x000 Internal : 0
+0x004 InternalHigh : 0x10 ' this is the right value.
+0x008 Offset : 0
+0x00c OffsetHigh : 0
+0x008 Pointer : (null)
+0x010 hEvent : 0x000001f8

"Internal" holds the processed I/O's error code. Both 0x103 and 0 mean that
the operation is successful (SUCCEEDED(Internal) == TRUE). However, I feel
that there must be some meaning behind 0x103. I am asking the OS team about
it and hope this can give some insights of the cause.

2. I also discussed the issue with the .NET team. They reminded me that we
added the built-in managed pipe APIs in .NET 3.5 (see System.IO.Pipes
http://msdn.microsoft.com/en-us/libr...io.pipes.aspx), so we
recommend just using that instead of rolling our own support for pipes.
Doing low-level async I/O in managed code is very hard.

In addition, the .NET team tells me that NativeOverlapped should work just
fine on both architectures.

3. I suspected that the problem here is that we are not pinning the object
containing the NativeOverlapped. CAsyncHelper is not blittable
(http://msdn.microsoft.com/en-us/library/75dwhxf7.aspx), and thus cannot be
pinned. I manually pinned the NativeOverlapped struct inside it and
allocate a GCHandle on the ManualResetEvent object, but it does not work
out the problem. I'm still researching in this aspect.

4. Another suggestion we'd give is to look at binding the pipe to the
ThreadPool (via ThreadPool.BindHandle) and using Overlapped instead of
using NativeOverlapped directly. This makes the pinning stuff somewhat
easier, and gives a much nicer completion model.

Best Regards,
Jialiang Ge
Microsoft Online Community Support

=================================================
Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
ms****@microsoft.com.

This posting is provided "AS IS" with no warranties, and confers no rights.
=================================================

Nov 11 '08 #6
Hello Nick

I'm reminded that System.IO.FileStream.BeginRead/Write is implemented by
using the NativeOverlapped struct, thus NativeOverlapped should work for
x64 platform. I then checked the source code of
System.IO.FileStream.BeginRead/Write, and found that it uses the
NativeOverlapped struct in this way:

// Create a managed overlapped class
// We will set the file offsets later
Overlapped overlapped = new Overlapped(0, 0, IntPtr.Zero, asyncResult);

// Pack the Overlapped class, and store it in the async result
NativeOverlapped* intOverlapped;
if (userCallback != null)
intOverlapped = overlapped.Pack(IOCallback, bytes);
else
intOverlapped = overlapped.UnsafePack(null, bytes);

Overlapped.Pack packs an instance of System.Threading.Overlapped into a
NativeOverlapped struct. The unmanaged pointer returned by this method can
be passed to the operating system in overlapped I/O operations. The
NativeOverlapped structure is fixed in physical memory until Unpack is
called. This is much safer than directly creating a NativeOverlapped struct
in that Overlapped.Pack manages the complex pinning logic for us.

Based on this finding, I updated your code to use Overlapped.Pack. I've
sent the new project to your mailbox. The test project has been tested in
my Windows 2003 x64 box, and it works fine. Please try it on your side and
let me know the result.

Have a very nice day!

Best Regards,
Jialiang Ge (ji****@online.microsoft.com, remove 'online.')
Microsoft Online Community Support

=================================================
Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
ms****@microsoft.com.

This posting is provided "AS IS" with no warranties, and confers no rights.
=================================================
Nov 11 '08 #7
Hi Jialiang.

Thanks for the obviously considerable effort you put into finding this
solution! This appears to solve the problem completely.
Thanks again for a truly great job!

-Nick
""Jialiang Ge [MSFT]"" wrote:
Hello Nick

I'm reminded that System.IO.FileStream.BeginRead/Write is implemented by
using the NativeOverlapped struct, thus NativeOverlapped should work for
x64 platform. I then checked the source code of
System.IO.FileStream.BeginRead/Write, and found that it uses the
NativeOverlapped struct in this way:

// Create a managed overlapped class
// We will set the file offsets later
Overlapped overlapped = new Overlapped(0, 0, IntPtr.Zero, asyncResult);

// Pack the Overlapped class, and store it in the async result
NativeOverlapped* intOverlapped;
if (userCallback != null)
intOverlapped = overlapped.Pack(IOCallback, bytes);
else
intOverlapped = overlapped.UnsafePack(null, bytes);

Overlapped.Pack packs an instance of System.Threading.Overlapped into a
NativeOverlapped struct. The unmanaged pointer returned by this method can
be passed to the operating system in overlapped I/O operations. The
NativeOverlapped structure is fixed in physical memory until Unpack is
called. This is much safer than directly creating a NativeOverlapped struct
in that Overlapped.Pack manages the complex pinning logic for us.

Based on this finding, I updated your code to use Overlapped.Pack. I've
sent the new project to your mailbox. The test project has been tested in
my Windows 2003 x64 box, and it works fine. Please try it on your side and
let me know the result.

Have a very nice day!

Best Regards,
Jialiang Ge (ji****@online.microsoft.com, remove 'online.')
Microsoft Online Community Support

=================================================
Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
ms****@microsoft.com.

This posting is provided "AS IS" with no warranties, and confers no rights.
=================================================
Nov 11 '08 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: yamadora1999 | last post by:
hi :) http://groups.google.com/groups?q=author:dmost%40magna.com.au&hl=ko&lr=&ie=UTF-8&selm=8pguo8%24bbl%241%40nnrp1.deja.com&rnum=3 GetQueuedCompletionStatus is return new OVERLAPPED yet. i...
5
by: Michelle Kinsey-Clinton | last post by:
Hello, I am writing an ASP app which is giving me some very frustrating errors. They appear intermittently, no real pattern to them, and often go away if you reload, or back up a few pages and...
3
by: AmyAdmin | last post by:
I am running windows 2000 with IIS 5.0 and I have ASP and .NET apps running on that server, and I've been getting the error message in my event viewer: DCom got error "Overlapped I/O operation is...
1
by: Lewap | last post by:
Hi! I have a problem: Function CreateNamedPipe (a piece of source below) called in a NT service I get an error 997 - Overlapped I/O operation is in progress. When I run the same code as...
1
by: donna rigas | last post by:
Hi - I'm using overlapped i/o on Windows 98 and on XP and am getting different results. Here's the code snippet: // read the command id and the message length BOOL rc;...
2
by: CeZaR | last post by:
Hi, What does the "overlapped" word means in windows programming? I've read about overlapped structures, functions?! What does it mean? Thanks!
1
by: dvestal | last post by:
I'm trying to use Overlapped I/O from C#, and utterly failing. I've tried to boil down my code to as simple an example as possible, in hopes that you people can point to where I'm going wrong. ...
4
by: Eric Renken | last post by:
I am trying to do an Overlapped ReadFile on a HID device and it just isn't working for me. The WaitForSingleObject keeps giving me an error "The system cannot find the file specified." This...
0
by: Ingenious | last post by:
Hi I am reading data from device in overlapped way. i am able to read the data correctly with WaitforMultipleObject() but now i want to use HasOverlappedIoCompleted () to inceraese the speed...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.