| 282 | } |
| 283 | |
| 284 | int HookProcessor::PullData(std::vector<char>* data) { |
| 285 | LOG(TRACE) << "Entering HookProcessor::PullData"; |
| 286 | std::vector<char> buffer(NAMED_PIPE_BUFFER_SIZE); |
| 287 | |
| 288 | // Wait for the client to connect; if it succeeds, |
| 289 | // the function returns a nonzero value. If the function |
| 290 | // returns zero, GetLastError returns ERROR_PIPE_CONNECTED. |
| 291 | LOG(DEBUG) << "Waiting for connection from browser via named pipe"; |
| 292 | bool is_connected = true; |
| 293 | if (!::ConnectNamedPipe(this->pipe_handle_, NULL)) { |
| 294 | DWORD error = ::GetLastError(); |
| 295 | if (error != ERROR_PIPE_CONNECTED) { |
| 296 | is_connected = false; |
| 297 | } |
| 298 | } |
| 299 | if (is_connected) { |
| 300 | LOG(DEBUG) << "Connection from browser established via named pipe"; |
| 301 | unsigned long bytes_read = 0; |
| 302 | BOOL is_read_successful = ::ReadFile(this->pipe_handle_, |
| 303 | &buffer[0], |
| 304 | NAMED_PIPE_BUFFER_SIZE, |
| 305 | &bytes_read, |
| 306 | NULL); |
| 307 | while (!is_read_successful && ERROR_MORE_DATA == ::GetLastError()) { |
| 308 | data->insert(data->end(), buffer.begin(), buffer.begin() + bytes_read); |
| 309 | is_read_successful = ::ReadFile(this->pipe_handle_, |
| 310 | &buffer[0], |
| 311 | NAMED_PIPE_BUFFER_SIZE, |
| 312 | &bytes_read, |
| 313 | NULL); |
| 314 | } |
| 315 | if (is_read_successful) { |
| 316 | data->insert(data->end(), buffer.begin(), buffer.begin() + bytes_read); |
| 317 | } |
| 318 | ::DisconnectNamedPipe(this->pipe_handle_); |
| 319 | } else { |
| 320 | LOG(WARN) << "No connection received from browser via named pipe"; |
| 321 | } |
| 322 | return static_cast<int>(data->size()); |
| 323 | } |
| 324 | |
| 325 | void HookProcessor::ResetFlag() { |
| 326 | flag = false; |
no test coverage detected