Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: src/shared/Communication.cpp

Issue 10807006: Use a binary 0 as string separator (Closed)
Patch Set: Created May 24, 2013, 3:22 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #include PRECOMPILED_HEADER_FILE 1 #include PRECOMPILED_HEADER_FILE
2 2
3 #include <Lmcons.h> 3 #include <Lmcons.h>
4 #include <sstream> 4 #include <sstream>
5 5
6 #include "Communication.h" 6 #include "Communication.h"
7 7
8 namespace 8 namespace
9 { 9 {
10 std::wstring GetUserName() 10 std::wstring GetUserName()
(...skipping 11 matching lines...) Expand all
22 } 22 }
23 } 23 }
24 24
25 const std::wstring Communication::pipeName = L"\\\\.\\pipe\\adblockplusengine_" + GetUserName(); 25 const std::wstring Communication::pipeName = L"\\\\.\\pipe\\adblockplusengine_" + GetUserName();
26 26
27 std::string Communication::MarshalStrings(const std::vector<std::string>& string s) 27 std::string Communication::MarshalStrings(const std::vector<std::string>& string s)
28 { 28 {
29 // TODO: This is some pretty hacky marshalling, replace it with something more robust 29 // TODO: This is some pretty hacky marshalling, replace it with something more robust
30 std::string marshalledStrings; 30 std::string marshalledStrings;
31 for (std::vector<std::string>::const_iterator it = strings.begin(); it != stri ngs.end(); it++) 31 for (std::vector<std::string>::const_iterator it = strings.begin(); it != stri ngs.end(); it++)
32 marshalledStrings += *it + ';'; 32 marshalledStrings += *it + '\0';
33 return marshalledStrings; 33 return marshalledStrings;
34 } 34 }
35 35
36 std::vector<std::string> Communication::UnmarshalStrings(const std::string& mess age) 36 std::vector<std::string> Communication::UnmarshalStrings(const std::string& mess age)
37 { 37 {
38 std::stringstream stream(message); 38 std::stringstream stream(message);
39 std::vector<std::string> strings; 39 std::vector<std::string> strings;
40 std::string string; 40 std::string string;
41 while (std::getline(stream, string, ';')) 41 while (std::getline(stream, string, '\0'))
42 strings.push_back(string); 42 strings.push_back(string);
43 return strings; 43 return strings;
44 } 44 }
45 45
46 std::string Communication::ReadMessage(HANDLE pipe) 46 std::string Communication::ReadMessage(HANDLE pipe)
47 { 47 {
48 std::stringstream stream; 48 std::stringstream stream;
49 std::auto_ptr<char> buffer(new char[bufferSize]); 49 std::auto_ptr<char> buffer(new char[bufferSize]);
50 bool doneReading = false; 50 bool doneReading = false;
51 while (!doneReading) 51 while (!doneReading)
(...skipping 11 matching lines...) Expand all
63 } 63 }
64 return stream.str(); 64 return stream.str();
65 } 65 }
66 66
67 void Communication::WriteMessage(HANDLE pipe, const std::string& message) 67 void Communication::WriteMessage(HANDLE pipe, const std::string& message)
68 { 68 {
69 DWORD bytesWritten; 69 DWORD bytesWritten;
70 if (!WriteFile(pipe, message.c_str(), message.length(), &bytesWritten, 0)) 70 if (!WriteFile(pipe, message.c_str(), message.length(), &bytesWritten, 0))
71 throw std::runtime_error("Failed to write to pipe"); 71 throw std::runtime_error("Failed to write to pipe");
72 } 72 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld