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

int DaemonCore::Cancel_Pipe ( int  pipe_end  ) 

Not_Yet_Documented

Parameters:
pipe_end Not_Yet_Documented
Returns:
Not_Yet_Documented

Definition at line 1705 of file daemon_core.cpp.

Referenced by Close_Pipe().

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

      int i,j;

      i = -1;
      for (j=0;j<nPipe;j++) {
            if ( (*pipeTable)[j].index == index ) {
                  i = j;
                  break;
            }
      }

      if ( i == -1 ) {
            dprintf( D_ALWAYS,"Cancel_Pipe: called on non-registered pipe!\n");
            dprintf( D_ALWAYS,"Offending pipe end number %d\n", pipe_end );
            return FALSE;
      }

      // Remove entry at index i by moving the last one in the table here.

      // Clear any data_ptr which go to this entry we just removed
      if ( curr_regdataptr == &( (*pipeTable)[i].data_ptr) )
            curr_regdataptr = NULL;
      if ( curr_dataptr == &( (*pipeTable)[i].data_ptr) )
            curr_dataptr = NULL;

      // Log a message
      dprintf(D_DAEMONCORE,
                  "Cancel_Pipe: cancelled pipe end %d <%s> (entry=%d)\n",
                  pipe_end,(*pipeTable)[i].pipe_descrip, i );

      // Remove entry, move the last one in the list into this spot
      (*pipeTable)[i].index = -1;
      free_descrip( (*pipeTable)[i].pipe_descrip );
      (*pipeTable)[i].pipe_descrip = NULL;
      free_descrip( (*pipeTable)[i].handler_descrip );
      (*pipeTable)[i].handler_descrip = NULL;

#ifdef WIN32
      // we need to notify the PID-watcher thread that it should
      // no longer watch this pipe
      // note: we must acccess the deallocate flag in a thread-safe manner.
      ASSERT( (*pipeTable)[i].pentry );
      InterlockedExchange(&((*pipeTable)[i].pentry->deallocate),1L);
      if ((*pipeTable)[i].pentry->watcherEvent) {
            SetEvent((*pipeTable)[i].pentry->watcherEvent);
      }

      // call cancel on the PipeEnd, which won't return until the
      // PID-watcher is no longer using the object and it has been
      // marked as unregistered
      (*pipeTable)[i].pentry->pipeEnd->cancel();

      if ((*pipeTable)[i].in_handler) {
            // Cancel_Pipe is being called from the handler. when the
            // handler returns, the Driver needs to know whether to
            // call WatchPid on our PidEntry again. we set the pipeEnd
            // member of our PidEntry to NULL to tell it not to. the
            // Driver will deallocate the PidEntry then
            (*pipeTable)[i].pentry->pipeEnd = NULL;
      }
      else {
            // we're not in the handler so we can simply deallocate the
            // PidEntry now
            delete (*pipeTable)[i].pentry;
      }
#endif
      (*pipeTable)[i].pentry = NULL;
      if ( i < nPipe - 1 ) {
            // if not the last entry in the table, move the last one here
            (*pipeTable)[i] = (*pipeTable)[nPipe - 1];
            (*pipeTable)[nPipe - 1].index = -1;
            (*pipeTable)[nPipe - 1].pipe_descrip = NULL;
            (*pipeTable)[nPipe - 1].handler_descrip = NULL;
            (*pipeTable)[nPipe - 1].pentry = NULL;
      }
      nPipe--;

      return TRUE;
}


Generated by  Doxygen 1.6.0   Back to index