example/thread-pool/psi.c
static int
parse_data(INKCont contp, INKIOBufferReader input_reader, int avail, int *toconsume, int *towrite)
{
  ContData *data;
  int nparse = 0;
  int status;

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

  if (data->parse_state == PARSE_SEARCH) {

    /* Search for the start pattern */
    status = strsearch_ioreader(input_reader, PSI_START_TAG, &nparse);
    switch (status) {
    case STR_FAIL:
      /* We didn't found the pattern */
      *toconsume = avail;
      *towrite = avail;
      data->parse_state = PARSE_SEARCH;
      return 0;
    case STR_PARTIAL:
      /* We need to read some more data */
      *toconsume = nparse;
      *towrite = nparse;
      data->parse_state = PARSE_SEARCH;
      return 0;
    case STR_SUCCESS:
      /* We found the start_pattern, let's go ahead */
      data->psi_filename_len = 0;
      data->psi_filename[0] = '\0';
      data->parse_state = PARSE_EXTRACT;
      break;
    default:
      INKAssert(!"strsearch_ioreader returned unexpected status");
    }
  }


  /* And now let's extract the filename */
  status = strextract_ioreader(input_reader, nparse + PSI_START_TAG_LEN,
                               PSI_END_TAG, data->psi_filename, &data->psi_filename_len);
  switch (status) {
  case STR_FAIL:
    /* We couldn't extract a valid filename */
    *toconsume = nparse;
    *towrite = nparse;
    data->parse_state = PARSE_SEARCH;
    return 0;
  case STR_PARTIAL:
    /* We need to read some more data */
    *toconsume = nparse;
    *towrite = nparse;
    data->parse_state = PARSE_EXTRACT;
    return 0;
  case STR_SUCCESS:
    /* We got a valid filename */
    *toconsume = nparse + PSI_START_TAG_LEN + data->psi_filename_len + PSI_END_TAG_LEN;
    *towrite = nparse;
    data->parse_state = PARSE_SEARCH;
    return 1;
  default:
    INKAssert(!"strextract_ioreader returned bad status");
  }

}
/*-------------------------------------------------------------------------
  parse_data
  Search for psi filename in the data.

  Input:
    contp   continuation for the current transaction
    reader  reader on the iobuffer that contains data
    avail   amount of data available in the iobuffer
  Output:
    towrite    amount of data in the iobuffer that can be written
               to the downstream vconnection
    toconsume  amount of data in the iobuffer to consume
  Return Value:
    0   if no psi filename found
    1  if a psi filename was found
  -------------------------------------------------------------------------*/
parse_data
Search for psi filename in the data.

contp   continuation for the current transaction
reader  reader on the iobuffer that contains data
avail   amount of data available in the iobuffer
Output:
towrite    amount of data in the iobuffer that can be written
to the downstream vconnection
toconsume  amount of data in the iobuffer to consume
Return Value:
0   if no psi filename found
1  if a psi filename was found
parse_data Search for psi filename in the data . contp continuation for the current transaction reader reader on the iobuffer that contains data avail amount of data available in the iobuffer Output : towrite amount of data in the iobuffer that can be written to the downstream vconnection toconsume amount of data in the iobuffer to consume Return Value : 0 if no psi filename found 1 if a psi filename was found
static int
parse_data(INKCont contp, INKIOBufferReader input_reader, int avail, int *toconsume, int *towrite)
{
  ContData *data;
  int nparse = 0;
  int status;
  data = INKContDataGet(contp);
  INKAssert(data->magic == MAGIC_ALIVE);
  if (data->parse_state == PARSE_SEARCH) {
    status = strsearch_ioreader(input_reader, PSI_START_TAG, &nparse);
    switch (status) {
    case STR_FAIL:
      *toconsume = avail;
      *towrite = avail;
      data->parse_state = PARSE_SEARCH;
      return 0;
    case STR_PARTIAL:
      *toconsume = nparse;
      *towrite = nparse;
      data->parse_state = PARSE_SEARCH;
      return 0;
    case STR_SUCCESS:
      data->psi_filename_len = 0;
      data->psi_filename[0] = '\0';
      data->parse_state = PARSE_EXTRACT;
      break;
    default:
      INKAssert(!"strsearch_ioreader returned unexpected status");
    }
  }
  status = strextract_ioreader(input_reader, nparse + PSI_START_TAG_LEN,
                               PSI_END_TAG, data->psi_filename, &data->psi_filename_len);
  switch (status) {
  case STR_FAIL:
    *toconsume = nparse;
    *towrite = nparse;
    data->parse_state = PARSE_SEARCH;
    return 0;
  case STR_PARTIAL:
    *toconsume = nparse;
    *towrite = nparse;
    data->parse_state = PARSE_EXTRACT;
    return 0;
  case STR_SUCCESS:
    *toconsume = nparse + PSI_START_TAG_LEN + data->psi_filename_len + PSI_END_TAG_LEN;
    *towrite = nparse;
    data->parse_state = PARSE_SEARCH;
    return 1;
  default:
    INKAssert(!"strextract_ioreader returned bad status");
  }
}
static int parse_data ( INKCont contp , INKIOBufferReader input_reader , int avail , int * toconsume , int * towrite ) { ContData * data ; int nparse = 0 ; int status ; data = INKContDataGet ( contp ) ; INKAssert ( data -> magic == MAGIC_ALIVE ) ; if ( data -> parse_state == PARSE_SEARCH ) { status = strsearch_ioreader ( input_reader , PSI_START_TAG , & nparse ) ; switch ( status ) { case STR_FAIL : * toconsume = avail ; * towrite = avail ; data -> parse_state = PARSE_SEARCH ; return 0 ; case STR_PARTIAL : * toconsume = nparse ; * towrite = nparse ; data -> parse_state = PARSE_SEARCH ; return 0 ; case STR_SUCCESS : data -> psi_filename_len = 0 ; data -> psi_filename [ 0 ] = ' \0 ' ; data -> parse_state = PARSE_EXTRACT ; break ; default : INKAssert ( ! " " ) ; } } status = strextract_ioreader ( input_reader , nparse + PSI_START_TAG_LEN , PSI_END_TAG , data -> psi_filename , & data -> psi_filename_len ) ; switch ( status ) { case STR_FAIL : * toconsume = nparse ; * towrite = nparse ; data -> parse_state = PARSE_SEARCH ; return 0 ; case STR_PARTIAL : * toconsume = nparse ; * towrite = nparse ; data -> parse_state = PARSE_EXTRACT ; return 0 ; case STR_SUCCESS : * toconsume = nparse + PSI_START_TAG_LEN + data -> psi_filename_len + PSI_END_TAG_LEN ; * towrite = nparse ; data -> parse_state = PARSE_SEARCH ; return 1 ; default : INKAssert ( ! " " ) ; } }
parse_data
Search for psi filename in the data.
parse_data Search for psi filename in the data .
/* Search for the start pattern */ /* We didn't found the pattern */ /* We need to read some more data */ /* We found the start_pattern, let's go ahead */ /* And now let's extract the filename */ /* We couldn't extract a valid filename */ /* We need to read some more data */ /* We got a valid filename */