bigbiff bigbiff | 9c75405 | 2013-01-09 09:09:08 -0500 | [diff] [blame] | 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 "fuse_lowlevel.h" |
| 10 | |
| 11 | #include <stdio.h> |
| 12 | #include <stdlib.h> |
| 13 | #include <errno.h> |
| 14 | |
| 15 | int fuse_session_loop(struct fuse_session *se) |
| 16 | { |
| 17 | int res = 0; |
| 18 | struct fuse_chan *ch = fuse_session_next_chan(se, NULL); |
| 19 | size_t bufsize = fuse_chan_bufsize(ch); |
| 20 | char *buf = (char *) malloc(bufsize); |
| 21 | if (!buf) { |
| 22 | fprintf(stderr, "fuse: failed to allocate read buffer\n"); |
| 23 | return -1; |
| 24 | } |
| 25 | |
| 26 | while (!fuse_session_exited(se)) { |
| 27 | struct fuse_chan *tmpch = ch; |
Dees_Troy | e34c133 | 2013-02-06 19:13:00 +0000 | [diff] [blame] | 28 | struct fuse_buf fbuf = { |
| 29 | .mem = buf, |
| 30 | .size = bufsize, |
| 31 | }; |
| 32 | |
| 33 | res = fuse_session_receive_buf(se, &fbuf, &tmpch); |
| 34 | |
bigbiff bigbiff | 9c75405 | 2013-01-09 09:09:08 -0500 | [diff] [blame] | 35 | if (res == -EINTR) |
| 36 | continue; |
| 37 | if (res <= 0) |
| 38 | break; |
Dees_Troy | e34c133 | 2013-02-06 19:13:00 +0000 | [diff] [blame] | 39 | |
| 40 | fuse_session_process_buf(se, &fbuf, tmpch); |
bigbiff bigbiff | 9c75405 | 2013-01-09 09:09:08 -0500 | [diff] [blame] | 41 | } |
| 42 | |
| 43 | free(buf); |
| 44 | fuse_session_reset(se); |
| 45 | return res < 0 ? -1 : 0; |
| 46 | } |