[posix] [pipe] add IPC for POSIX and add pipe for it

This commit is contained in:
Meco Man 2021-12-07 02:18:58 -05:00 committed by Bernard Xiong
parent 3b007a7bbc
commit 7ff976dab3
5 changed files with 33 additions and 24 deletions

View File

@ -5,10 +5,6 @@ config RT_USING_DEVICE_IPC
default y default y
if RT_USING_DEVICE_IPC if RT_USING_DEVICE_IPC
config RT_PIPE_BUFSZ
int "Set pipe buffer size"
default 512
config RT_USING_SYSTEM_WORKQUEUE config RT_USING_SYSTEM_WORKQUEUE
bool "Using system default workqueue" bool "Using system default workqueue"
default n default n

View File

@ -15,12 +15,6 @@
#include <rtthread.h> #include <rtthread.h>
#include <rtdevice.h> #include <rtdevice.h>
#ifndef RT_PIPE_BUFSZ
#define PIPE_BUFSZ 512
#else
#define PIPE_BUFSZ RT_PIPE_BUFSZ
#endif
struct rt_pipe_device struct rt_pipe_device
{ {
struct rt_device parent; struct rt_device parent;

View File

@ -13,7 +13,7 @@
#include <stdint.h> #include <stdint.h>
#include <sys/errno.h> #include <sys/errno.h>
#ifdef RT_USING_POSIX_DEVIO #if defined(RT_USING_POSIX_DEVIO) && defined(RT_USING_POSIX_PIPE)
#include <dfs_file.h> #include <dfs_file.h>
#include <dfs_posix.h> #include <dfs_posix.h>
#include <poll.h> #include <poll.h>
@ -320,9 +320,9 @@ static const struct dfs_file_ops pipe_fops =
RT_NULL, RT_NULL,
pipe_fops_poll, pipe_fops_poll,
}; };
#endif /* RT_USING_POSIX_DEVIO */ #endif /* defined(RT_USING_POSIX_DEVIO) && defined(RT_USING_POSIX_PIPE) */
rt_err_t rt_pipe_open(rt_device_t device, rt_uint16_t oflag) static rt_err_t rt_pipe_open(rt_device_t device, rt_uint16_t oflag)
{ {
rt_pipe_t *pipe = (rt_pipe_t *)device; rt_pipe_t *pipe = (rt_pipe_t *)device;
rt_err_t ret = RT_EOK; rt_err_t ret = RT_EOK;
@ -350,7 +350,7 @@ __exit:
return ret; return ret;
} }
rt_err_t rt_pipe_close(rt_device_t device) static rt_err_t rt_pipe_close(rt_device_t device)
{ {
rt_pipe_t *pipe = (rt_pipe_t *)device; rt_pipe_t *pipe = (rt_pipe_t *)device;
@ -368,7 +368,7 @@ rt_err_t rt_pipe_close(rt_device_t device)
return RT_EOK; return RT_EOK;
} }
rt_size_t rt_pipe_read(rt_device_t device, rt_off_t pos, void *buffer, rt_size_t count) static rt_size_t rt_pipe_read(rt_device_t device, rt_off_t pos, void *buffer, rt_size_t count)
{ {
uint8_t *pbuf; uint8_t *pbuf;
rt_size_t read_bytes = 0; rt_size_t read_bytes = 0;
@ -396,7 +396,7 @@ rt_size_t rt_pipe_read(rt_device_t device, rt_off_t pos, void *buffer, rt_size_t
return read_bytes; return read_bytes;
} }
rt_size_t rt_pipe_write(rt_device_t device, rt_off_t pos, const void *buffer, rt_size_t count) static rt_size_t rt_pipe_write(rt_device_t device, rt_off_t pos, const void *buffer, rt_size_t count)
{ {
uint8_t *pbuf; uint8_t *pbuf;
rt_size_t write_bytes = 0; rt_size_t write_bytes = 0;
@ -424,7 +424,7 @@ rt_size_t rt_pipe_write(rt_device_t device, rt_off_t pos, const void *buffer, rt
return write_bytes; return write_bytes;
} }
rt_err_t rt_pipe_control(rt_device_t dev, int cmd, void *args) static rt_err_t rt_pipe_control(rt_device_t dev, int cmd, void *args)
{ {
return RT_EOK; return RT_EOK;
} }
@ -479,9 +479,9 @@ rt_pipe_t *rt_pipe_create(const char *name, int bufsz)
rt_free(pipe); rt_free(pipe);
return RT_NULL; return RT_NULL;
} }
#ifdef RT_USING_POSIX_DEVIO #if defined(RT_USING_POSIX_DEVIO) && defined(RT_USING_POSIX_PIPE)
dev->fops = (void*)&pipe_fops; dev->fops = (void*)&pipe_fops;
#endif /* RT_USING_POSIX_DEVIO */ #endif
return pipe; return pipe;
} }
@ -529,7 +529,7 @@ int rt_pipe_delete(const char *name)
return result; return result;
} }
#ifdef RT_USING_POSIX_DEVIO #if defined(RT_USING_POSIX_DEVIO) && defined(RT_USING_POSIX_PIPE)
int pipe(int fildes[2]) int pipe(int fildes[2])
{ {
rt_pipe_t *pipe; rt_pipe_t *pipe;
@ -539,7 +539,7 @@ int pipe(int fildes[2])
rt_snprintf(dname, sizeof(dname), "pipe%d", pipeno++); rt_snprintf(dname, sizeof(dname), "pipe%d", pipeno++);
pipe = rt_pipe_create(dname, PIPE_BUFSZ); pipe = rt_pipe_create(dname, RT_USING_POSIX_PIPE_SIZE);
if (pipe == RT_NULL) if (pipe == RT_NULL)
{ {
return -1; return -1;
@ -567,7 +567,7 @@ int mkfifo(const char *path, mode_t mode)
{ {
rt_pipe_t *pipe; rt_pipe_t *pipe;
pipe = rt_pipe_create(path, PIPE_BUFSZ); pipe = rt_pipe_create(path, RT_USING_POSIX_PIPE_SIZE);
if (pipe == RT_NULL) if (pipe == RT_NULL)
{ {
return -1; return -1;
@ -575,4 +575,4 @@ int mkfifo(const char *path, mode_t mode)
return 0; return 0;
} }
#endif /* RT_USING_POSIX_DEVIO */ #endif /* defined(RT_USING_POSIX_DEVIO) && defined(RT_USING_POSIX_PIPE) */

View File

@ -55,4 +55,6 @@ if RT_USING_PTHREADS
default 8 default 8
endif endif
source "$RTT_DIR/components/libc/posix/ipc/Kconfig"
endmenu endmenu

View File

@ -0,0 +1,17 @@
menu "Interprocess Communication (IPC)"
config RT_USING_POSIX_PIPE
bool "Enable pipe and FIFO"
select RT_USING_POSIX_FS
select RT_USING_POSIX_DEVIO
select RT_USING_POSIX_POLL
default n
config RT_USING_POSIX_PIPE_SIZE
int "Set pipe buffer size"
depends on RT_USING_POSIX_PIPE
default 512
comment "Socket is in the 'Network' category"
endmenu