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