libfuse: remove fuse_chan_bufsize()
[fuse.git] / lib / fuse_session.c
blobb8687a4e12f03657fa009bb7344e43bab2c23115
1 /*
2 FUSE: Filesystem in Userspace
3 Copyright (C) 2001-2007 Miklos Szeredi <miklos@szeredi.hu>
5 This program can be distributed under the terms of the GNU LGPLv2.
6 See the file COPYING.LIB
7 */
9 #include "fuse_i.h"
10 #include "fuse_misc.h"
12 #include <stdio.h>
13 #include <stdlib.h>
14 #include <string.h>
15 #include <assert.h>
16 #include <errno.h>
18 struct fuse_chan {
19 struct fuse_chan_ops op;
21 struct fuse_session *se;
23 int fd;
26 struct fuse_session *fuse_session_new(void *data)
28 struct fuse_session *se = (struct fuse_session *) malloc(sizeof(*se));
29 if (se == NULL) {
30 fprintf(stderr, "fuse: failed to allocate session\n");
31 return NULL;
34 memset(se, 0, sizeof(*se));
35 se->data = data;
37 return se;
40 void fuse_session_add_chan(struct fuse_session *se, struct fuse_chan *ch)
42 assert(se->ch == NULL);
43 assert(ch->se == NULL);
44 se->ch = ch;
45 ch->se = se;
48 void fuse_session_remove_chan(struct fuse_chan *ch)
50 struct fuse_session *se = ch->se;
51 if (se) {
52 assert(se->ch == ch);
53 se->ch = NULL;
54 ch->se = NULL;
58 struct fuse_chan *fuse_session_chan(struct fuse_session *se)
60 return se->ch;
63 void fuse_session_process_buf(struct fuse_session *se,
64 const struct fuse_buf *buf, struct fuse_chan *ch)
66 se->process_buf(se->data, buf, ch);
69 int fuse_session_receive_buf(struct fuse_session *se, struct fuse_buf *buf,
70 struct fuse_chan *ch)
72 return se->receive_buf(se, buf, ch);
75 int fuse_chan_clearfd(struct fuse_chan *ch)
77 int fd = ch->fd;
78 ch->fd = -1;
79 return fd;
82 void fuse_session_destroy(struct fuse_session *se)
84 se->destroy(se->data);
85 if (se->ch != NULL)
86 fuse_chan_destroy(se->ch);
87 free(se);
90 void fuse_session_exit(struct fuse_session *se)
92 se->exited = 1;
95 void fuse_session_reset(struct fuse_session *se)
97 se->exited = 0;
100 int fuse_session_exited(struct fuse_session *se)
102 return se->exited;
105 void *fuse_session_data(struct fuse_session *se)
107 return se->data;
110 struct fuse_chan *fuse_chan_new(struct fuse_chan_ops *op, int fd)
112 struct fuse_chan *ch = (struct fuse_chan *) malloc(sizeof(*ch));
113 if (ch == NULL) {
114 fprintf(stderr, "fuse: failed to allocate channel\n");
115 return NULL;
118 memset(ch, 0, sizeof(*ch));
119 ch->op = *op;
120 ch->fd = fd;
122 return ch;
125 int fuse_chan_fd(struct fuse_chan *ch)
127 return ch->fd;
130 struct fuse_session *fuse_chan_session(struct fuse_chan *ch)
132 return ch->se;
135 void fuse_chan_destroy(struct fuse_chan *ch)
137 fuse_session_remove_chan(ch);
138 if (ch->op.destroy)
139 ch->op.destroy(ch);
140 free(ch);