blob: 0b592e5316885cfffb5558dcdeee3d888222e7da
1 | /* |
2 | FUSE: Filesystem in Userspace |
3 | Copyright (C) 2001-2007 Miklos Szeredi <miklos@szeredi.hu> |
4 | |
5 | This program can be distributed under the terms of the GNU LGPLv2. |
6 | See the file COPYING.LIB |
7 | */ |
8 | |
9 | #include "config.h" |
10 | #include "fuse_lowlevel.h" |
11 | |
12 | #include <stdio.h> |
13 | #include <stdlib.h> |
14 | #include <errno.h> |
15 | |
16 | int fuse_session_loop(struct fuse_session *se) |
17 | { |
18 | int res = 0; |
19 | struct fuse_chan *ch = fuse_session_next_chan(se, NULL); |
20 | size_t bufsize = fuse_chan_bufsize(ch); |
21 | char *buf = (char *) malloc(bufsize); |
22 | if (!buf) { |
23 | fprintf(stderr, "fuse: failed to allocate read buffer\n"); |
24 | return -1; |
25 | } |
26 | |
27 | while (!fuse_session_exited(se)) { |
28 | struct fuse_chan *tmpch = ch; |
29 | res = fuse_chan_recv(&tmpch, buf, bufsize); |
30 | if (res == -EINTR) |
31 | continue; |
32 | if (res <= 0) |
33 | break; |
34 | fuse_session_process(se, buf, res, tmpch); |
35 | } |
36 | |
37 | free(buf); |
38 | fuse_session_reset(se); |
39 | return res < 0 ? -1 : 0; |
40 | } |
41 |