1#include "streamwriter.h"
2#include <unistd.h>
3
4using namespace jsonrpc;
5using namespace std;
6
7bool StreamWriter::Write(const string &source, int fd) {
8 ssize_t bytesWritten;
9 size_t totalSize = source.size();
10 size_t remainingSize = totalSize;
11
12 do {
13 bytesWritten = write(fd, source.c_str() + (totalSize - remainingSize), remainingSize);
14 if (bytesWritten < 0) {
15 return false;
16 } else {
17 remainingSize -= static_cast<size_t>(bytesWritten);
18 }
19 } while (remainingSize > 0);
20 return true;
21}
22