Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. blocking pipe write

blocking pipe write

Scheduled Pinned Locked Moved C / C++ / MFC
help
2 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    A T I F
    wrote on last edited by
    #1

    I am trying to have a overlapped blocking pipe write so that I can have either data sent signal or a timeout signal... The code I have written is as follows DWORD dwMode = PIPE_READMODE_MESSAGE | PIPE_WAIT; BOOL bSuccess = ::SetNamedPipeHandleState(m_hPipe, &dwMode, NULL, NULL); and my pipe write function have code OVERLAPPED op = {0}; op.hEvent = CreateEvent(NULL, TRUE, FALSE, NULL); bSuccess = ::WriteFile(m_hPipe, lpBufferPos, dwToWrite, &dwNumberOfBytesWritten, &op); if(bSuccess) { return TRUE; } else { m_dwLastError = ::GetLastError(); if(m_dwLastError == ERROR_IO_PENDING) { switch(WaitForSingleObject(op.hEvent, m_dwTimeOut)) { case WAIT_OBJECT_0: return TRUE; break; case WAIT_TIMEOUT: m_dwLastError = ::GetLastError(); return FALSE; case WAIT_FAILED: m_dwLastError = ::GetLastError(); return FALSE; break; } } else { return FALSE; } } } The problem that I am facing is that all my Write to pipe function calls keeps returning with TRUE code and the corresponding first Read call in the child process remains locked at the WaitForSingleObject call and then after some write pipe operation in the parent process Read returns with "More data is available" error. Can anyone direct me what I am doing wrong.

    A 1 Reply Last reply
    0
    • A A T I F

      I am trying to have a overlapped blocking pipe write so that I can have either data sent signal or a timeout signal... The code I have written is as follows DWORD dwMode = PIPE_READMODE_MESSAGE | PIPE_WAIT; BOOL bSuccess = ::SetNamedPipeHandleState(m_hPipe, &dwMode, NULL, NULL); and my pipe write function have code OVERLAPPED op = {0}; op.hEvent = CreateEvent(NULL, TRUE, FALSE, NULL); bSuccess = ::WriteFile(m_hPipe, lpBufferPos, dwToWrite, &dwNumberOfBytesWritten, &op); if(bSuccess) { return TRUE; } else { m_dwLastError = ::GetLastError(); if(m_dwLastError == ERROR_IO_PENDING) { switch(WaitForSingleObject(op.hEvent, m_dwTimeOut)) { case WAIT_OBJECT_0: return TRUE; break; case WAIT_TIMEOUT: m_dwLastError = ::GetLastError(); return FALSE; case WAIT_FAILED: m_dwLastError = ::GetLastError(); return FALSE; break; } } else { return FALSE; } } } The problem that I am facing is that all my Write to pipe function calls keeps returning with TRUE code and the corresponding first Read call in the child process remains locked at the WaitForSingleObject call and then after some write pipe operation in the parent process Read returns with "More data is available" error. Can anyone direct me what I am doing wrong.

      A Offline
      A Offline
      A T I F
      wrote on last edited by
      #2

      PS> what I need is a blocking write with a timeout so that if no read is performed for a specified time the thread unlocks.

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups