example/thread-pool/psi.c
static int
dump_psi(INKCont contp)
{
  ContData *data;
  int psi_output_len;
  INKVIO input_vio;
  INKReturnCode retval;

  input_vio = INKVConnWriteVIOGet(contp);
  if (input_vio == INK_ERROR_PTR) {
    INKError("[dump_psi] Error while getting input vio");
    return 1;
  }

  data = INKContDataGet(contp);
  INKAssert(data->magic == MAGIC_ALIVE);

  /* If script exec succeded, copy its output to the downstream vconn */
  if (data->psi_success == 1) {
    psi_output_len = INKIOBufferReaderAvail(data->psi_reader);
    if (psi_output_len == INK_ERROR) {
      INKError("[dump_psi] Error while getting available bytes from reader");
      return 1;
    }

    if (psi_output_len > 0) {
      data->transform_bytes += psi_output_len;

      INKDebug(DBG_TAG, "Inserting %d bytes from include file", psi_output_len);
      retval = INKIOBufferCopy(INKVIOBufferGet(data->output_vio), data->psi_reader, psi_output_len, 0);
      if (retval == INK_ERROR) {
        INKError("[dump_psi] Error while copying include bytes to downstream VC");
        return 1;
      }

      /* Consume all the output data */
      retval = INKIOBufferReaderConsume(data->psi_reader, psi_output_len);
      if (retval == INK_ERROR) {
        INKError("[dump_psi] Error while consuming data from buffer");
        return 1;
      }

      /* Reenable the output connection so it can read the data we've produced. */
      retval = INKVIOReenable(data->output_vio);
      if (retval == INK_ERROR) {
        INKError("[dump_psi] Error while reenabling output VIO");
        return 1;
      }
    }
  }

  /* Change state to finish up reading upstream data */
  data->state = STATE_READ_DATA;
  return 0;
}
/*-------------------------------------------------------------------------
  dump_psi
  Dump the psi_output to the downstream vconnection.

  Input:
    contp      continuation for the current transaction
  Output :
  Return Value:
   0 if failure
   1 if success
  -------------------------------------------------------------------------*/
dump_psi
Dump the psi_output to the downstream vconnection.

contp      continuation for the current transaction
Output :
Return Value:
0 if failure
1 if success
dump_psi Dump the psi_output to the downstream vconnection . contp continuation for the current transaction Output : Return Value : 0 if failure 1 if success
static int
dump_psi(INKCont contp)
{
  ContData *data;
  int psi_output_len;
  INKVIO input_vio;
  INKReturnCode retval;
  input_vio = INKVConnWriteVIOGet(contp);
  if (input_vio == INK_ERROR_PTR) {
    INKError("[dump_psi] Error while getting input vio");
    return 1;
  }
  data = INKContDataGet(contp);
  INKAssert(data->magic == MAGIC_ALIVE);
  if (data->psi_success == 1) {
    psi_output_len = INKIOBufferReaderAvail(data->psi_reader);
    if (psi_output_len == INK_ERROR) {
      INKError("[dump_psi] Error while getting available bytes from reader");
      return 1;
    }
    if (psi_output_len > 0) {
      data->transform_bytes += psi_output_len;
      INKDebug(DBG_TAG, "Inserting %d bytes from include file", psi_output_len);
      retval = INKIOBufferCopy(INKVIOBufferGet(data->output_vio), data->psi_reader, psi_output_len, 0);
      if (retval == INK_ERROR) {
        INKError("[dump_psi] Error while copying include bytes to downstream VC");
        return 1;
      }
      retval = INKIOBufferReaderConsume(data->psi_reader, psi_output_len);
      if (retval == INK_ERROR) {
        INKError("[dump_psi] Error while consuming data from buffer");
        return 1;
      }
      retval = INKVIOReenable(data->output_vio);
      if (retval == INK_ERROR) {
        INKError("[dump_psi] Error while reenabling output VIO");
        return 1;
      }
    }
  }
  data->state = STATE_READ_DATA;
  return 0;
}
static int dump_psi ( INKCont contp ) { ContData * data ; int psi_output_len ; INKVIO input_vio ; INKReturnCode retval ; input_vio = INKVConnWriteVIOGet ( contp ) ; if ( input_vio == INK_ERROR_PTR ) { INKError ( " " ) ; return 1 ; } data = INKContDataGet ( contp ) ; INKAssert ( data -> magic == MAGIC_ALIVE ) ; if ( data -> psi_success == 1 ) { psi_output_len = INKIOBufferReaderAvail ( data -> psi_reader ) ; if ( psi_output_len == INK_ERROR ) { INKError ( " " ) ; return 1 ; } if ( psi_output_len > 0 ) { data -> transform_bytes += psi_output_len ; INKDebug ( DBG_TAG , " " , psi_output_len ) ; retval = INKIOBufferCopy ( INKVIOBufferGet ( data -> output_vio ) , data -> psi_reader , psi_output_len , 0 ) ; if ( retval == INK_ERROR ) { INKError ( " " ) ; return 1 ; } retval = INKIOBufferReaderConsume ( data -> psi_reader , psi_output_len ) ; if ( retval == INK_ERROR ) { INKError ( " " ) ; return 1 ; } retval = INKVIOReenable ( data -> output_vio ) ; if ( retval == INK_ERROR ) { INKError ( " " ) ; return 1 ; } } } data -> state = STATE_READ_DATA ; return 0 ; }
dump_psi
Dump the psi_output to the downstream vconnection.
dump_psi Dump the psi_output to the downstream vconnection .
/* If script exec succeded, copy its output to the downstream vconn */ /* Consume all the output data */ /* Reenable the output connection so it can read the data we've produced. */ /* Change state to finish up reading upstream data */