Skip to content

Commit 946cfca

Browse files
committed
Fix flush splitting
1 parent 2461ed3 commit 946cfca

File tree

2 files changed

+21
-10
lines changed

2 files changed

+21
-10
lines changed

sapi/fpm/fpm/fpm_stdio.c

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ static void fpm_stdio_child_said(struct fpm_event_s *ev, short which, void *arg)
122122
struct fpm_child_s *child;
123123
int is_stdout;
124124
struct fpm_event_s *event;
125-
int in_buf = 0, pos, start;
125+
int in_buf = 0, cmd_pos = 0, pos, start;
126126
int read_fail = 0, create_log_stream;
127127
struct zlog_stream *log_stream;
128128

@@ -163,6 +163,7 @@ static void fpm_stdio_child_said(struct fpm_event_s *ev, short which, void *arg)
163163
}
164164

165165
while (1) {
166+
stdio_read:
166167
in_buf = read(fd, buf, max_buf_size - 1);
167168
if (in_buf <= 0) { /* no data */
168169
if (in_buf == 0 || (errno != EAGAIN && errno != EWOULDBLOCK)) {
@@ -171,21 +172,33 @@ static void fpm_stdio_child_said(struct fpm_event_s *ev, short which, void *arg)
171172
}
172173
break;
173174
}
174-
175-
for (start = 0, pos = 0; pos < in_buf; pos++) {
175+
start = 0;
176+
if (cmd_pos > 0) {
177+
if (!memcmp(buf, &FPM_STDIO_CMD_FLUSH[cmd_pos], sizeof(FPM_STDIO_CMD_FLUSH) - cmd_pos)) {
178+
zlog_stream_finish(log_stream);
179+
start = cmd_pos;
180+
}
181+
cmd_pos = 0;
182+
}
183+
for (pos = 0; pos < in_buf; pos++) {
176184
switch (buf[pos]) {
177185
case '\n':
178186
zlog_stream_str(log_stream, buf + start, pos - start);
179187
zlog_stream_finish(log_stream);
180188
start = pos + 1;
181189
break;
182190
case '\0':
183-
if (pos + sizeof(FPM_STDIO_CMD_FLUSH) <= in_buf &&
184-
!memcmp(buf + pos, FPM_STDIO_CMD_FLUSH, sizeof(FPM_STDIO_CMD_FLUSH))) {
191+
if (pos + sizeof(FPM_STDIO_CMD_FLUSH) <= in_buf) {
192+
if (!memcmp(buf + pos, FPM_STDIO_CMD_FLUSH, sizeof(FPM_STDIO_CMD_FLUSH))) {
193+
zlog_stream_str(log_stream, buf + start, pos - start);
194+
zlog_stream_finish(log_stream);
195+
start = pos + sizeof(FPM_STDIO_CMD_FLUSH);
196+
pos = start - 1;
197+
}
198+
} else if (!memcmp(buf + pos, FPM_STDIO_CMD_FLUSH, in_buf - pos)) {
199+
cmd_pos = in_buf - pos;
185200
zlog_stream_str(log_stream, buf + start, pos - start);
186-
zlog_stream_finish(log_stream);
187-
start = pos + sizeof(FPM_STDIO_CMD_FLUSH);
188-
pos = start - 1;
201+
goto stdio_read;
189202
}
190203
break;
191204
}

sapi/fpm/tests/log-bwp-msg-flush-split.phpt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,5 +44,3 @@ Done
4444
require_once "tester.inc";
4545
FPM\Tester::clean();
4646
?>
47-
--XFAIL--
48-
Split flush not implemented yet

0 commit comments

Comments
 (0)