-
Notifications
You must be signed in to change notification settings - Fork 507
/
pipe_file_handler.c
99 lines (75 loc) · 1.59 KB
/
pipe_file_handler.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#ifndef PHP_WIN32
#include <stdlib.h>
#include <stdio.h>
#include <unistd.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