| 457 | |
| 458 | |
| 459 | Future<string> Pipe::Reader::read() |
| 460 | { |
| 461 | synchronized (data->lock) { |
| 462 | if (data->readEnd == Reader::CLOSED) { |
| 463 | return Failure("closed"); |
| 464 | } else if (!data->writes.empty()) { |
| 465 | Future<string> future = data->writes.front(); |
| 466 | data->writes.pop(); |
| 467 | return future; |
| 468 | } else if (data->writeEnd == Writer::CLOSED) { |
| 469 | return ""; // End-of-file. |
| 470 | } else if (data->writeEnd == Writer::FAILED) { |
| 471 | CHECK_SOME(data->failure); |
| 472 | return data->failure.get(); |
| 473 | } else { |
| 474 | data->reads.push(Owned<Promise<string>>(new Promise<string>())); |
| 475 | return data->reads.back()->future(); |
| 476 | } |
| 477 | } |
| 478 | } |
| 479 | |
| 480 | |
| 481 | Future<string> Pipe::Reader::readAll() |