xref: /third_party/libfuse/lib/fuse_loop.c (revision 6881f68f)
16881f68fSopenharmony_ci/*
26881f68fSopenharmony_ci  FUSE: Filesystem in Userspace
36881f68fSopenharmony_ci  Copyright (C) 2001-2007  Miklos Szeredi <miklos@szeredi.hu>
46881f68fSopenharmony_ci
56881f68fSopenharmony_ci  Implementation of the single-threaded FUSE session loop.
66881f68fSopenharmony_ci
76881f68fSopenharmony_ci  This program can be distributed under the terms of the GNU LGPLv2.
86881f68fSopenharmony_ci  See the file COPYING.LIB
96881f68fSopenharmony_ci*/
106881f68fSopenharmony_ci
116881f68fSopenharmony_ci#include "fuse_config.h"
126881f68fSopenharmony_ci#include "fuse_lowlevel.h"
136881f68fSopenharmony_ci#include "fuse_i.h"
146881f68fSopenharmony_ci
156881f68fSopenharmony_ci#include <stdio.h>
166881f68fSopenharmony_ci#include <stdlib.h>
176881f68fSopenharmony_ci#include <errno.h>
186881f68fSopenharmony_ci
196881f68fSopenharmony_ciint fuse_session_loop(struct fuse_session *se)
206881f68fSopenharmony_ci{
216881f68fSopenharmony_ci	int res = 0;
226881f68fSopenharmony_ci	struct fuse_buf fbuf = {
236881f68fSopenharmony_ci		.mem = NULL,
246881f68fSopenharmony_ci	};
256881f68fSopenharmony_ci
266881f68fSopenharmony_ci	while (!fuse_session_exited(se)) {
276881f68fSopenharmony_ci		res = fuse_session_receive_buf_int(se, &fbuf, NULL);
286881f68fSopenharmony_ci
296881f68fSopenharmony_ci		if (res == -EINTR)
306881f68fSopenharmony_ci			continue;
316881f68fSopenharmony_ci		if (res <= 0)
326881f68fSopenharmony_ci			break;
336881f68fSopenharmony_ci
346881f68fSopenharmony_ci		fuse_session_process_buf_int(se, &fbuf, NULL);
356881f68fSopenharmony_ci	}
366881f68fSopenharmony_ci
376881f68fSopenharmony_ci	free(fbuf.mem);
386881f68fSopenharmony_ci	if(res > 0)
396881f68fSopenharmony_ci		/* No error, just the length of the most recently read
406881f68fSopenharmony_ci		   request */
416881f68fSopenharmony_ci		res = 0;
426881f68fSopenharmony_ci	if(se->error != 0)
436881f68fSopenharmony_ci		res = se->error;
446881f68fSopenharmony_ci	fuse_session_reset(se);
456881f68fSopenharmony_ci	return res;
466881f68fSopenharmony_ci}
47