From 345a54fceaa73261630fc7fdd49a756c4d8fb04f Mon Sep 17 00:00:00 2001 From: shaojinchun Date: Mon, 8 Feb 2021 16:40:07 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E5=BD=93dfs=E7=B3=BB?= =?UTF-8?q?=E7=BB=9F=E4=BF=AE=E6=94=B9=E5=90=8E,=20channel=E7=9A=84dfs=5Ff?= =?UTF-8?q?d=E4=B8=AD=E7=9A=84fnode=E6=B2=A1=E6=9C=89=E7=94=B3=E8=AF=B7?= =?UTF-8?q?=E7=A9=BA=E9=97=B4=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/lwp/lwp_ipc.c | 41 ++++++++++++++++++++++++++++++++-------- 1 file changed, 33 insertions(+), 8 deletions(-) diff --git a/components/lwp/lwp_ipc.c b/components/lwp/lwp_ipc.c index f9d2fcab99..c6141b42b8 100644 --- a/components/lwp/lwp_ipc.c +++ b/components/lwp/lwp_ipc.c @@ -899,33 +899,44 @@ int lwp_channel_open(int fdt_type, const char *name, int flags) { int fd; rt_channel_t ch = RT_NULL; + struct dfs_fd *d; fd = _chfd_alloc(fdt_type); /* allocate an IPC channel descriptor */ if (fd == -1) { goto quit; } + d = lwp_fd_get(fdt_type, fd); + d->fnode = (struct dfs_fnode *)rt_malloc(sizeof(struct dfs_fnode)); + if (!d->fnode) + { + _chfd_free(fd, fdt_type); + fd = -1; + goto quit; + } + ch = rt_raw_channel_open(name, flags); if (ch) { - struct dfs_fd *d; - - d = lwp_fd_get(fdt_type, fd); - + rt_memset(d->fnode, 0, sizeof(struct dfs_fnode)); + rt_list_init(&d->fnode->list); d->fnode->type = FT_USER; d->fnode->path = NULL; + d->fnode->fullpath = NULL; d->fnode->fops = &channel_fops; d->fnode->flags = O_RDWR; /* set flags as read and write */ d->fnode->size = 0; d->pos = 0; + d->fnode->ref_count = 1; /* set socket to the data of dfs_fd */ d->fnode->data = (void *)ch; } else { + rt_free(d->fnode); _chfd_free(fd, fdt_type); fd = -1; } @@ -954,14 +965,28 @@ static rt_channel_t fd_2_channel(int fdt_type, int fd) rt_err_t lwp_channel_close(int fdt_type, int fd) { rt_channel_t ch; + struct dfs_fd *d; + + d = lwp_fd_get(fdt_type, fd); + if (!d) + { + return -RT_EIO; + } + + if (!d->fnode) + { + return -RT_EIO; + } ch = fd_2_channel(fdt_type, fd); - if (ch) + rt_free(d->fnode); + if (!ch) { - _chfd_free(fd, fdt_type); - return rt_raw_channel_close(ch); + return -RT_EIO; } - return -RT_EIO; + _chfd_free(fd, fdt_type); + + return rt_raw_channel_close(ch); } rt_err_t lwp_channel_send(int fdt_type, int fd, rt_channel_msg_t data) -- Gitee