diff options
Diffstat (limited to 'multipart-replace.c')
-rw-r--r-- | multipart-replace.c | 20 |
1 files changed, 11 insertions, 9 deletions
diff --git a/multipart-replace.c b/multipart-replace.c index 24a783e..78732e6 100644 --- a/multipart-replace.c +++ b/multipart-replace.c @@ -53,7 +53,7 @@ void multipart_replace_reader(struct multipart_replace_stream *s, int fd, const do { line_len = getline(&line_buf, &line_cap, stream); if (line_len < 0) { - error(0, 0, "source hung up"); + error(0, ferror(stream), "source hung up"); return; } } while (strcmp(line_buf, "\r\n") == 0); @@ -66,7 +66,7 @@ void multipart_replace_reader(struct multipart_replace_stream *s, int fd, const do { line_len = getline(&line_buf, &line_cap, stream); if (line_len < 0) { - error(0, 0, "source hung up"); + error(0, ferror(stream), "source hung up"); return; } /* append the line to the frame contents */ @@ -104,11 +104,12 @@ void multipart_replace_reader(struct multipart_replace_stream *s, int fd, const } void multipart_replace_writer(struct multipart_replace_stream *s, int fd, const char *boundary) { + FILE *stream = fdopen(fd, "w"); struct frame myframe = { 0 }; long lastframe = 0; boundary = boundary_line(boundary); size_t boundary_len = strlen(boundary); - error(0, 0, "boundary: <%s>", boundary); + while(1) { /* poll until there's a new frame */ pthread_rwlock_rdlock(&s->frontlock); @@ -127,19 +128,20 @@ void multipart_replace_writer(struct multipart_replace_stream *s, int fd, const pthread_rwlock_unlock(&s->frontlock); /* send the frame to the client */ - if (write(fd, boundary, boundary_len) < (ssize_t)boundary_len) { - error(0, errno, "write"); + if (fwrite(boundary, boundary_len, 1, stream) < 1) { + error(0, ferror(stream), "fwrite(boundary)"); return; } - if (write(fd, myframe.buf, myframe.len) < myframe.len) { - error(0, errno, "write"); + if (fwrite(myframe.buf, myframe.len, 1, stream) < 1) { + error(0, ferror(stream), "fwrite(frame.buf)"); return; } /* send a blank line for pleasantness */ - if (write(fd, "\r\n", 2) < 2) { - error(0, errno, "write"); + if (fwrite("\r\n", 2, 1, stream) < 1) { + error(0, ferror(stream), "fwrite(\"\\r\\n\")"); return; } + fflush(stream); } } |