Lines Matching defs:dfile

52 nul_terminate(perf_datafile_t *dfile)
56 data = isc_buffer_used(&dfile->data);
63 perf_datafile_t *dfile;
66 dfile = isc_mem_get(mctx, sizeof(*dfile));
67 if (dfile == NULL)
70 dfile->mctx = mctx;
71 MUTEX_INIT(&dfile->lock);
72 dfile->pipe_fd = -1;
73 dfile->is_file = ISC_FALSE;
74 dfile->size = 0;
75 dfile->cached = ISC_FALSE;
76 dfile->maxruns = 1;
77 dfile->nruns = 0;
78 dfile->read_any = ISC_FALSE;
79 isc_buffer_init(&dfile->data, dfile->databuf, BUFFER_SIZE);
81 dfile->fd = STDIN_FILENO;
83 dfile->fd = open(filename, O_RDONLY);
84 if (dfile->fd < 0)
86 if (fstat(dfile->fd, &buf) == 0 && S_ISREG(buf.st_mode)) {
87 dfile->is_file = ISC_TRUE;
88 dfile->size = buf.st_size;
91 nul_terminate(dfile);
93 return dfile;
99 perf_datafile_t *dfile;
103 dfile = *dfilep;
106 if (dfile->fd >= 0 && dfile->fd != STDIN_FILENO)
107 close(dfile->fd);
108 MUTEX_DESTROY(&dfile->lock);
109 isc_mem_put(dfile->mctx, dfile, sizeof(*dfile));
113 perf_datafile_setpipefd(perf_datafile_t *dfile, int pipe_fd)
115 dfile->pipe_fd = pipe_fd;
119 perf_datafile_setmaxruns(perf_datafile_t *dfile, unsigned int maxruns)
121 dfile->maxruns = maxruns;
125 reopen_file(perf_datafile_t *dfile)
127 if (dfile->cached) {
128 isc_buffer_first(&dfile->data);
130 if (lseek(dfile->fd, 0L, SEEK_SET) < 0)
132 isc_buffer_clear(&dfile->data);
133 nul_terminate(dfile);
138 read_more(perf_datafile_t *dfile)
145 if (!dfile->is_file && dfile->pipe_fd >= 0) {
146 result = perf_os_waituntilreadable(dfile->fd, dfile->pipe_fd,
152 isc_buffer_compact(&dfile->data);
153 data = isc_buffer_used(&dfile->data);
154 size = isc_buffer_availablelength(&dfile->data);
156 n = read(dfile->fd, data, size);
160 isc_buffer_add(&dfile->data, n);
161 nul_terminate(dfile);
163 if (dfile->is_file &&
164 isc_buffer_usedlength(&dfile->data) == dfile->size)
165 dfile->cached = ISC_TRUE;
171 read_one_line(perf_datafile_t *dfile, isc_buffer_t *lines)
179 cur = isc_buffer_current(&dfile->data);
186 nrem = isc_buffer_remaininglength(&dfile->data);
188 if (! dfile->cached) {
189 result = read_more(dfile);
193 if (isc_buffer_remaininglength(&dfile->data) == 0) {
194 dfile->nruns++;
197 if (isc_buffer_remaininglength(&dfile->data) > nrem)
202 isc_buffer_forward(&dfile->data, curlen);
203 if (isc_buffer_remaininglength(&dfile->data) > 0)
204 isc_buffer_forward(&dfile->data, 1);
221 perf_datafile_next(perf_datafile_t *dfile, isc_buffer_t *lines,
227 LOCK(&dfile->lock);
229 if (dfile->maxruns > 0 && dfile->maxruns == dfile->nruns) {
234 result = read_one_line(dfile, lines);
236 if (!dfile->read_any) {
240 if (dfile->maxruns != dfile->nruns) {
241 reopen_file(dfile);
242 result = read_one_line(dfile, lines);
249 dfile->read_any = ISC_TRUE;
254 result = read_one_line(dfile, lines);
256 dfile->maxruns != dfile->nruns) {
257 reopen_file(dfile);
267 UNLOCK(&dfile->lock);
272 perf_datafile_nruns(const perf_datafile_t *dfile)
274 return dfile->nruns;