Logo Search packages:      
Sourcecode: condor version File versions  Download package

int DaemonCore::Close_Pipe ( int  pipe_end  ) 

Close an anonymous pipe. This function will also call Cancel_Pipe() on behalf of the caller if the pipe_end had been registed via Register_Pipe().

Definition at line 1809 of file daemon_core.cpp.

References Cancel_Pipe().

Referenced by Cancel_And_Close_All_Pipes(), Close_FD(), Close_Stdin_Pipe(), and Create_Process().

{
      int index = pipe_end - PIPE_INDEX_OFFSET;
      if (pipeHandleTableLookup(index) == FALSE) {
            dprintf(D_ALWAYS, "Close_Pipe on invalid pipe end: %d\n", pipe_end);
            EXCEPT("Close_Pipe error");
      }

      // First, call Cancel_Pipe on this pipefd.
      int i,j;
      i = -1;
      for (j=0;j<nPipe;j++) {                                    
            if ( (*pipeTable)[j].index == index ) {
                  i = j;
                  break;
            }
      }
      if ( i != -1 ) {
            // We now know that this pipe end is registed.  Cancel it.
            int result = Cancel_Pipe(pipe_end);
            // ASSERT that it did not fail, because the only reason it should
            // fail is if it is not registered.  And we already checked that.
            ASSERT( result == TRUE );
      }

      // Now, close the pipe.
      int retval = TRUE;
#if defined(WIN32)
      WritePipeEnd* wpe = dynamic_cast<WritePipeEnd*>((*pipeHandleTable)[index]);
      if (wpe && wpe->needs_delayed_close()) {
            // We can't close this pipe yet, because it has an incomplete
            // overalapped write and we need to let it finish. Start a
            // thread to complete the operation then close the pipe
            CloseHandle((HANDLE)_beginthreadex(NULL, 0,
                        pipe_close_thread,
                        wpe, 0, NULL));
      }
      else {
            // no outstanding I/O - just delete the object (which
            // will close the pipe)
            delete (*pipeHandleTable)[index];
      }
#else
      int pipefd = (*pipeHandleTable)[index];
      if ( close(pipefd) < 0 ) {
            dprintf(D_ALWAYS,
                  "Close_Pipe(pipefd=%d) failed, errno=%d\n",pipefd,errno);
            retval = FALSE;  // probably a bad fd
      }
#endif

      // remove from the pipe handle table
      pipeHandleTableRemove(index);

      if (retval == TRUE) {
            dprintf(D_DAEMONCORE,
                        "Close_Pipe(pipe_end=%d) succeeded\n",pipe_end);
      }

      return retval;
}


Generated by  Doxygen 1.6.0   Back to index