| Index: remoting/host/gnubby_connection.cc
|
| diff --git a/remoting/host/gnubby_connection.cc b/remoting/host/gnubby_connection.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..864f4d9daddef0a831a4fddaf9e002d0c922d70c
|
| --- /dev/null
|
| +++ b/remoting/host/gnubby_connection.cc
|
| @@ -0,0 +1,89 @@
|
| +// Copyright 2014 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#include "remoting/host/gnubby_connection.h"
|
| +
|
| +#include "net/base/net_errors.h"
|
| +#include "remoting/base/logging.h"
|
| +#include "remoting/host/gnubby_auth_handler.h"
|
| +
|
| +namespace remoting {
|
| +
|
| +GnubbyConnection::GnubbyConnection(
|
| + scoped_refptr<base::SingleThreadTaskRunner> network_task_runner,
|
| + GnubbyAuthHandler* auth_handler,
|
| + int connection_id,
|
| + net::StreamSocket* socket)
|
| + : network_task_runner_(network_task_runner),
|
| + auth_handler_(auth_handler),
|
| + connection_id_(connection_id),
|
| + socket_(socket) {
|
| + DCHECK(network_task_runner_);
|
| + DCHECK(auth_handler_);
|
| + DCHECK(socket_);
|
| +
|
| + in_buffer_ = new net::IOBufferWithSize(512);
|
| +}
|
| +
|
| +GnubbyConnection::~GnubbyConnection() {}
|
| +
|
| +void GnubbyConnection::Read() {
|
| + DCHECK(network_task_runner_->BelongsToCurrentThread());
|
| +
|
| + int result = socket_->Read(
|
| + in_buffer_.get(),
|
| + in_buffer_->size(),
|
| + base::Bind(&GnubbyConnection::OnRead, base::Unretained(this)));
|
| + if (result != net::ERR_IO_PENDING) {
|
| + OnRead(result);
|
| + }
|
| +}
|
| +
|
| +void GnubbyConnection::Write(const std::string& data) {
|
| + DCHECK(network_task_runner_->BelongsToCurrentThread());
|
| +
|
| + scoped_refptr<net::StringIOBuffer> buffer = new net::StringIOBuffer(data);
|
| +
|
| + int result = socket_->Write(
|
| + buffer.get(),
|
| + buffer->size(),
|
| + base::Bind(&GnubbyConnection::OnWrite, base::Unretained(this)));
|
| + if (result != net::ERR_IO_PENDING) {
|
| + OnWrite(result);
|
| + }
|
| +}
|
| +
|
| +void GnubbyConnection::OnRead(int result) {
|
| + DCHECK(network_task_runner_->BelongsToCurrentThread());
|
| +
|
| + if (result > 0) {
|
| + std::string data(in_buffer_->data(), result);
|
| +
|
| + auth_handler_->DeliverHostDataMessage(connection_id_, data);
|
| +
|
| + Read();
|
| + } else if (result == 0) {
|
| + auth_handler_->ConnectionClosed(connection_id_);
|
| + } else {
|
| + HOST_LOG << "Failed to read from gnubbyd: " << result;
|
| + Error(result);
|
| + }
|
| +}
|
| +
|
| +void GnubbyConnection::OnWrite(int result) {
|
| + DCHECK(network_task_runner_->BelongsToCurrentThread());
|
| +
|
| + if (result < 0) {
|
| + HOST_LOG << "Failed to write to gnubbyd: " << result;
|
| + Error(result);
|
| + }
|
| +}
|
| +
|
| +void GnubbyConnection::Error(int result) {
|
| + DCHECK(network_task_runner_->BelongsToCurrentThread());
|
| +
|
| + auth_handler_->ConnectionError(connection_id_, result);
|
| +}
|
| +
|
| +} // namespace remoting
|
|
|