File: rbreader.c

package info (click to toggle)
libqb 0.11.1-2
  • links: PTS
  • area: main
  • in suites: jessie, jessie-kfreebsd, wheezy
  • size: 2,804 kB
  • ctags: 1,689
  • sloc: ansic: 15,630; sh: 11,355; makefile: 271
file content (71 lines) | stat: -rw-r--r-- 1,941 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/*
 * Copyright (C) 2012 Red Hat, Inc.
 *
 * Author: Angus Salkeld <asalkeld@redhat.com>
 *
 * libqb is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 2.1 of the License, or
 * (at your option) any later version.
 *
 * libqb is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with libqb.  If not, see <http://www.gnu.org/licenses/>.
 */

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <signal.h>

#include <qb/qbdefs.h>
#include <qb/qbrb.h>
#include <qb/qbutil.h>
#include <qb/qblog.h>

#define BUFFER_CHUNK_SIZE (50*50*10)
static qb_ringbuffer_t *rb = NULL;
static int keep_reading = QB_TRUE;


static void sigterm_handler(int32_t num)
{
	qb_log(LOG_INFO, "signal %d", num);
	keep_reading = QB_FALSE;
}

int32_t main(int32_t argc, char *argv[])
{
	ssize_t num_read;
	int8_t buffer[BUFFER_CHUNK_SIZE];

	signal(SIGINT, sigterm_handler);

	qb_log_init("rbreader", LOG_USER, LOG_EMERG);
	qb_log_ctl(QB_LOG_SYSLOG, QB_LOG_CONF_ENABLED, QB_FALSE);
	qb_log_filter_ctl(QB_LOG_STDERR, QB_LOG_FILTER_ADD,
			  QB_LOG_FILTER_FILE, "*", LOG_INFO);
	qb_log_ctl(QB_LOG_STDERR, QB_LOG_CONF_ENABLED, QB_TRUE);

	rb = qb_rb_open("tester", BUFFER_CHUNK_SIZE * 3,
			QB_RB_FLAG_SHARED_PROCESS | QB_RB_FLAG_CREATE, 0);

	if (rb == NULL) {
		qb_perror(LOG_ERR, "failed to create ringbuffer");
		return -1;
	}
	while (keep_reading) {
		num_read = qb_rb_chunk_read(rb, buffer,
					    BUFFER_CHUNK_SIZE, 5500);
		if (num_read < 0) {
			qb_perror(LOG_ERR, "nothing to read");
		}
	}
	qb_rb_close(rb);
	return 0;
}