コード例 #1
0
ファイル: logger.c プロジェクト: Azleal/sslsplit
/*
 * Logger thread main function.
 */
static void *
logger_thread(void *arg)
{
	logger_t *logger = arg;
	logbuf_t *lb;

	while ((lb = thrqueue_dequeue(logger->queue))) {
		logbuf_write_free(lb, logger->write);
	}

	return NULL;
}
コード例 #2
0
ファイル: logbuf.c プロジェクト: amarnathpg/sslsplit
/*
 * Write content of logbuf using writefunc and free all buffers.
 * Returns -1 on errors and sets errno according to write().
 * Returns total of bytes written by 1 .. n write() calls on success.
 */
ssize_t
logbuf_write_free(logbuf_t *lb, writefunc_t writefunc)
{
	ssize_t rv1, rv2;

	rv1 = writefunc(lb->fd, lb->buf, lb->sz);
	free(lb->buf);
	if (lb->next) {
		if (rv1 == -1) {
			logbuf_free(lb->next);
		} else {
			lb->next->fd = lb->fd;
			rv2 = logbuf_write_free(lb->next, writefunc);
		}
	}
	free(lb);
	if (rv1 == -1 || rv2 == -1)
		return -1;
	else
		return rv1 + rv2;
}