Re: Why is my overlapped WriteFile getting blocked? (repost)

From: Old Fart (oldfart_at_newsgroups.nospam)
Date: 06/21/04


Date: Mon, 21 Jun 2004 10:12:58 -0700

Quick update. I just tried again on a relatively virgin copy of XP
Professional and the problem did not occur. It appears to be something we
are installing that triggers the problem. Wish me luck in finding the
culprit.

"Yan-Hong Huang[MSFT]" <yhhuang@online.microsoft.com> wrote in message
news:7YOdXq1VEHA.3484@cpmsftngxa10.phx.gbl...
> Hello,
>
> Ray discussed it to me and I am looking into this issue.
>
> Based on my understanding, now the issue is: You are using overlapped IO
in named pipe programming. However, you found that if using . in
> pipe name, WriteFile could return immediately. However, if using machine
name in pipe name, WriteFile won't return when the server side is
> not reading pipe. The main concern here is that WriteFile doesn't return
immediately, which we feel it shoud be. Right?
>
> I tested it on my side. However, I didn't reproduce the problem. Here are
my testing steps for your reference:
>
> Let's start with that NPServer and NPClient sample in Platform SDK.
>
> 1) In NPServer, in ServerProc function, we just add a sleep:
> TellAll(""); // Forces a paint, draws a red
spool
> // and name for this client.
>
> // Do loop which basically reads
from
> // this specific client, and then
> // uses TellAll() to broadcast the
> // message to all the connected
> // clients.
> do{
> Sleep(5000); ///////////// we added code here
> // Read the pipe.
> retCode = ReadFile (hPipe, inBuf, PLEASE_READ, &bytesRead,
&OverLapRd);
> ...
>
> 2) In client side, in NPClient, in ClientDlgProc function, in IDB_SEND, we
revised the code as the following:
> sendBuf[OUT_BUF_SIZE - 1] = '\0'; // null terminate it
>
> // Do the overlapped write.
> SendMessage (GetDlgItem (hWndClient, IDD_EDITREAD),
> EM_REPLACESEL,
> 0, (LONG_PTR)"beginning writing pipe...");
> // Add a new line.
> SendMessage (GetDlgItem (hWndClient, IDD_EDITREAD),
> EM_REPLACESEL,
> 0, (LONG_PTR)"\r\n");
>
> retCode = WriteFile (hPipe, sendBuf, PLEASE_WRITE,
> &bytesWritten, &OverLapWrt);
> if (!retCode)
> {
> lastError = GetLastError();
> // If Error = IO_PENDING, wait til
> // the event signals success.
> if (lastError == ERROR_IO_PENDING)
> {
> SendMessage (GetDlgItem (hWndClient, IDD_EDITREAD),
> EM_REPLACESEL,
> 0, (LONG_PTR)"Now we are in ERROR_IO_PENGING...");
> // Add a new line.
> SendMessage (GetDlgItem (hWndClient, IDD_EDITREAD),
> EM_REPLACESEL,
> 0, (LONG_PTR)"\r\n");
> WaitForSingleObject (hEventWrt, (DWORD)-1);
> SendMessage (GetDlgItem (hWndClient, IDD_EDITREAD),
> EM_REPLACESEL,
> 0, (LONG_PTR)"Now we are leaving ERROR_IO_PENGING...");
> // Add a new line.
> SendMessage (GetDlgItem (hWndClient, IDD_EDITREAD),
> EM_REPLACESEL,
> 0, (LONG_PTR)"\r\n");
> }
> else
> {
> SendMessage (GetDlgItem (hWndClient, IDD_EDITREAD),
> EM_REPLACESEL,
> 0, (LONG_PTR)"This time we don't enter
ERROR_IO_PENGING...");
> // Add a new line.
> SendMessage (GetDlgItem (hWndClient, IDD_EDITREAD),
> EM_REPLACESEL,
> 0, (LONG_PTR)"\r\n");
> }
> }
>
> So we run the test sample, the log in the client window is:
>
> beginning writing pipe...
> Now we are in ERROR_IO_PENGING...
> Now we are leaving ERROR_IO_PENGING...
> test1: 1
> beginning writing pipe...
> Now we are in ERROR_IO_PENGING...
> Now we are leaving ERROR_IO_PENGING...
> test1: 1
> beginning writing pipe...
> Now we are in ERROR_IO_PENGING...
> Now we are leaving ERROR_IO_PENGING...
> test1: 1
> beginning writing pipe...
> Now we are in ERROR_IO_PENGING...
> Now we are leaving ERROR_IO_PENGING...
> test1: 1
> beginning writing pipe...
> Now we are in ERROR_IO_PENGING...
> Now we are leaving ERROR_IO_PENGING...
> test1: 1
>
> So in my test, all the writing operation enters error_io_pending block and
then after 5 seconds, it gets returned data and print out the result. I
> did test with . and machine name. All have the same result.
>
> If the above test has any different part from yours, could you please
point it out? Or you can email me one repro sample and I am glad to test
> it on my side. If we can reproduce it, I will contact product group on it.
You can reach me by removing online from my email address here.
>
> Also, I noticed that you added a (repost) in the post title. I not not
sure of why you didn't get a response former since you didn't mention the
title
> of the former post. In order to receive response timely, I high recommend
you post questions by using your MSDN subsciber no spam email
> alias.
>
> Thanks vey much. If you have any more concerns, please feel free to post
here.
>
> Best regards,
> Yanhong Huang
> Microsoft Community Support
>
> Get Secure! ¨C www.microsoft.com/security
> This posting is provided "AS IS" with no warranties, and confers no
rights.
>



Relevant Pages

  • Re: Why is my overlapped WriteFile getting blocked? (repost)
    ... The "server bug" was that it was never ... the client would connect to the named pipe ... and get blocked on the first WriteFile. ... I ran both the client and server on the same PC and opened the client pipe ...
    (microsoft.public.win32.programmer.networks)
  • Re: asynchronously writing to a file, a cheap way?
    ... your typical asynchronous route for writing to a file, ... performance when the processing server is running. ... end of the pipe doesn't need to be running. ... I you already have a thread pool or IOCP that you can use t handle the ...
    (microsoft.public.win32.programmer.kernel)
  • Re: Why is my overlapped WriteFile getting blocked? (repost)
    ... run the client on Win2K and the server on XP, ... 3622687: Calling WriteFile ... > pipe name, WriteFile could return immediately. ...
    (microsoft.public.win32.programmer.networks)
  • Re: Running a command-line program and reading/writing its stdin/stdout/stderr
    ... > The reason it fails is that the 2 ends of the pipe are not ... one is only good for writing, the other only for reading. ... The reason why i begun writing this program (that is only at its early ...
    (comp.os.linux.development.apps)
  • Re: Why is my overlapped WriteFile getting blocked? (repost)
    ... now the issue is: You are using overlapped IO in named pipe programming. ... In client side, in NPClient, in ClientDlgProc function, in IDB_SEND, we revised the code as the following: ... beginning writing pipe... ... Now we are leaving ERROR_IO_PENGING... ...
    (microsoft.public.win32.programmer.networks)