18 Star 98 Fork 30

liexusong / php-beast

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
pipe_file_handler.c 1.57 KB
一键复制 编辑 原始数据 按行查看 历史
xusong.lie 提交于 2017-03-22 21:12 . fix bugs
#ifndef PHP_WIN32
#include <stdlib.h>
#include <stdio.h>
#include "file_handler.h"
struct pipe_handler_ctx {
int fd[2];
};
int pipe_handler_check()
{
return 64 * 1024;
}
int pipe_handler_open(struct file_handler *self)
{
struct pipe_handler_ctx *ctx = self->ctx;
if (pipe(ctx->fd) == -1) {
ctx->fd[0] = -1;
ctx->fd[1] = -1;
return -1;
}
return 0;
}
int pipe_handler_write(struct file_handler *self, char *buf, int size)
{
struct pipe_handler_ctx *ctx = self->ctx;
if (write(ctx->fd[1], buf, size) == size) {
return 0;
}
return -1;
}
int pipe_handler_rewind(struct file_handler *self)
{
return 0;
}
FILE *pipe_handler_get_fp(struct file_handler *self)
{
return NULL;
}
int pipe_handler_get_fd(struct file_handler *self)
{
struct pipe_handler_ctx *ctx = self->ctx;
int retval;
retval = ctx->fd[0];
close(ctx->fd[1]); /* Closed write pipe */
ctx->fd[0] = -1;
ctx->fd[1] = -1;
return retval;
}
int pipe_handler_destroy(struct file_handler *self)
{
struct pipe_handler_ctx *ctx = self->ctx;
if (ctx->fd[0] != -1)
close(ctx->fd[0]);
if (ctx->fd[1] != -1)
close(ctx->fd[1]);
ctx->fd[0] = -1;
ctx->fd[1] = -1;
return 0;
}
static struct pipe_handler_ctx _ctx = {
{-1, -1}
};
struct file_handler pipe_handler = {
"pipe",
BEAST_FILE_HANDLER_FD,
&_ctx,
pipe_handler_check,
pipe_handler_open,
pipe_handler_write,
pipe_handler_rewind,
pipe_handler_get_fd,
pipe_handler_get_fp,
pipe_handler_destroy
};
#endif
C
1
https://gitee.com/liexusong/php-beast.git
git@gitee.com:liexusong/php-beast.git
liexusong
php-beast
php-beast
master

搜索帮助