- if (FILE *file = fdopen(fds[0], "r")) {
- uint8_t buffer[16*1024];
- read:
- size_t count(fread(buffer, 1, sizeof(buffer), file));
- if (count != 0) {
- fwrite(buffer, 1, count, stderr);
- CFHTTPMessageAppendBytes(http, buffer, count);
- }
- if (count == sizeof(buffer))
- goto read;
- if (ferror(file)) {
- [client URLProtocol:self didFailWithError:[NSError errorWithDomain:NSURLErrorDomain code:NSURLErrorNetworkConnectionLost userInfo:nil]];
- fclose(file);
- goto fail;
- }
- fclose(file);
- } else _assert(close(fds[0]));
+ [[NSNotificationCenter defaultCenter]
+ addObserver:self
+ selector:@selector(onRead:)
+ name:@"NSFileHandleReadCompletionNotification"
+ object:handle
+ ];