equal
deleted
inserted
replaced
23 size_t recv_size; |
23 size_t recv_size; |
24 |
24 |
25 // the buffer that we use to receive events |
25 // the buffer that we use to receive events |
26 char *recv_buf; |
26 char *recv_buf; |
27 }; |
27 }; |
|
28 |
|
29 // prototypes |
|
30 void evfuse_close (struct evfuse *ctx); |
28 |
31 |
29 static void _evfuse_ev_read (evutil_socket_t fd, short what, void *arg) { |
32 static void _evfuse_ev_read (evutil_socket_t fd, short what, void *arg) { |
30 struct evfuse *ctx = arg; |
33 struct evfuse *ctx = arg; |
31 struct fuse_chan *ch = ctx->chan; |
34 struct fuse_chan *ch = ctx->chan; |
32 int res; |
35 int res; |
56 |
59 |
57 // ok, wait for the next event |
60 // ok, wait for the next event |
58 return; |
61 return; |
59 |
62 |
60 error: |
63 error: |
61 // fail |
64 // close, but don't free |
62 evfuse_close(ctx); |
65 evfuse_close(ctx); |
63 } |
66 } |
64 |
67 |
65 struct evfuse *evfuse_new (struct event_base *evbase, struct fuse_args *args, struct fuse_lowlevel_ops *llops, void *cb_data) { |
68 struct evfuse *evfuse_new (struct event_base *evbase, struct fuse_args *args, struct fuse_lowlevel_ops *llops, void *cb_data) { |
66 struct evfuse *ctx = NULL; |
69 struct evfuse *ctx = NULL; |
102 |
105 |
103 // and then we wait |
106 // and then we wait |
104 return ctx; |
107 return ctx; |
105 |
108 |
106 error: |
109 error: |
107 free(ctx); |
110 evfuse_free(ctx); |
108 |
111 |
109 return NULL; |
112 return NULL; |
110 } |
113 } |
111 |
114 |
112 void evfuse_close (struct evfuse *ctx) { |
115 void evfuse_close (struct evfuse *ctx) { |
113 // remove our event |
116 if (ctx->ev) { |
114 if (event_del(ctx->ev)) |
117 // remove our event |
115 PWARNING("event_del"); |
118 if (event_del(ctx->ev)) |
|
119 PWARNING("event_del"); |
116 |
120 |
117 // remove the chan |
121 ctx->ev = NULL; |
118 fuse_session_remove_chan(ctx->chan); |
122 } |
119 |
|
120 // destroy the session |
|
121 fuse_session_destroy(ctx->session); |
|
122 |
123 |
123 // unmount |
124 if (ctx->session) { |
124 fuse_unmount(ctx->mountpoint, ctx->chan); |
125 // remove the chan |
125 |
126 fuse_session_remove_chan(ctx->chan); |
|
127 |
|
128 // destroy the session |
|
129 fuse_session_destroy(ctx->session); |
|
130 |
|
131 ctx->session = NULL; |
|
132 } |
|
133 |
|
134 if (ctx->chan) { |
|
135 // unmount |
|
136 fuse_unmount(ctx->mountpoint, ctx->chan); |
|
137 |
|
138 ctx->chan = NULL; |
|
139 } |
|
140 |
126 // free |
141 // free |
127 free(ctx->recv_buf); |
142 free(ctx->recv_buf); ctx->recv_buf = NULL; |
128 free(ctx->mountpoint); |
143 free(ctx->mountpoint); ctx->mountpoint = NULL; |
129 free(ctx); |
|
130 } |
144 } |
131 |
145 |
|
146 void evfuse_free (struct evfuse *ctx) { |
|
147 if (ctx) { |
|
148 evfuse_close(ctx); |
|
149 |
|
150 free(ctx); |
|
151 } |
|
152 } |
|
153 |