/* * status = readerGetRecord(&out_rwrec, &out_probe, flow_processor); * * Invoked by input_mode_type->get_record_fn(); */ static fp_get_record_result_t readerGetRecord( rwRec *out_rwrec, const skpc_probe_t **out_probe, flow_proc_t *fproc) { skPDUSource_t *pdu_src = (skPDUSource_t*)fproc->flow_src; const char *filename; if (0 == skPDUSourceGetGeneric(pdu_src, out_rwrec)) { /* got a record */ *out_probe = fproc->probe; /* When reading from a file, should only stop at the end of a * file. */ return FP_RECORD; } /* At end of file */ /* print stats for file */ readerPrintStats(fproc); /* archive file if requested */ filename = skpcProbeGetFileSource(fproc->probe); archiveDirectoryInsertOrRemove(filename, NULL); /* We can stop here. */ return FP_END_STREAM; }
/* * status = readerGetRecord(&out_rwrec, &out_probe, flow_processor); * * Invoked by input_mode_type->get_record_fn(); */ static fp_get_record_result_t readerGetRecord( rwRec *out_rwrec, const skpc_probe_t **out_probe, flow_proc_t *fproc) { static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; skstream_t *fcfile; const char *filename; fp_get_record_result_t retVal = FP_GET_ERROR; int rv; pthread_mutex_lock(&mutex); /* If we don't have a source, get a file from the directory poller * and start processing it. */ if (fproc->flow_src == NULL) { switch (readerGetNextValidFile(fproc)) { case 0: /* Success */ break; case -1: /* Error getting file name (maybe in shutdown?) */ goto END; case -2: /* Error opening file */ default: /* Unexpected value */ retVal = FP_FATAL_ERROR; goto END; } } fcfile = (skstream_t*)fproc->flow_src; /* Assume we can get a record from the probe. */ retVal = FP_RECORD; *out_probe = fproc->probe; /* Try to get a record */ rv = skStreamReadRecord(fcfile, out_rwrec); if (rv) { /* get failed: either at EOF or got an error. */ if (rv != SKSTREAM_ERR_EOF) { skStreamPrintLastErr(fcfile, rv, &WARNINGMSG); } retVal = FP_FILE_BREAK; *out_probe = NULL; /* Print results for the file we just processed. */ filename = skStreamGetPathname(fcfile); INFOMSG("Processed file %s, %" PRIu64 " records.", filename, skStreamGetRecordCount(fcfile)); skStreamClose(fcfile); /* Either archive the file or remove it */ archiveDirectoryInsertOrRemove(filename, NULL); /* All done with the flow source */ skStreamDestroy(&fcfile); fproc->flow_src = NULL; fproc->probe = NULL; } END: pthread_mutex_unlock(&mutex); return retVal; }