mirror of
https://github.com/klzgrad/naiveproxy.git
synced 2024-11-24 06:16:30 +03:00
Fix OnPushComplete logic
Should not Push the same thing again.
This commit is contained in:
parent
c1e1deeca8
commit
84757ced90
@ -241,7 +241,7 @@ int HttpProxySocket::DoLoop(int last_io_result) {
|
||||
int HttpProxySocket::DoHeaderRead() {
|
||||
next_state_ = STATE_HEADER_READ_COMPLETE;
|
||||
|
||||
handshake_buf_ = new IOBuffer(kBufferSize);
|
||||
handshake_buf_ = base::MakeRefCounted<IOBuffer>(kBufferSize);
|
||||
return transport_->Read(handshake_buf_.get(), kBufferSize, io_callback_);
|
||||
}
|
||||
|
||||
@ -293,7 +293,7 @@ int HttpProxySocket::DoHeaderWrite() {
|
||||
// Adds padding.
|
||||
int padding_size = base::RandInt(kMinPaddingSize, kMaxPaddingSize);
|
||||
header_write_size_ = kResponseHeaderSize + padding_size + 4;
|
||||
handshake_buf_ = new IOBuffer(header_write_size_);
|
||||
handshake_buf_ = base::MakeRefCounted<IOBuffer>(header_write_size_);
|
||||
char* p = handshake_buf_->data();
|
||||
std::memcpy(p, kResponseHeader, kResponseHeaderSize);
|
||||
std::memset(p + kResponseHeaderSize, '.', padding_size);
|
||||
|
@ -12,7 +12,7 @@
|
||||
#include <string>
|
||||
|
||||
#include "base/macros.h"
|
||||
#include "base/memory/ref_counted.h"
|
||||
#include "base/memory/scoped_refptr.h"
|
||||
#include "net/base/completion_once_callback.h"
|
||||
#include "net/base/completion_repeating_callback.h"
|
||||
#include "net/base/host_port_pair.h"
|
||||
|
@ -279,13 +279,13 @@ void NaiveConnection::Pull(Direction from, Direction to) {
|
||||
|
||||
int read_size = kBufferSize;
|
||||
if (from == pad_direction_ && num_paddings_[from] < kFirstPaddings) {
|
||||
auto* buffer = new GrowableIOBuffer;
|
||||
auto buffer = base::MakeRefCounted<GrowableIOBuffer>();
|
||||
buffer->SetCapacity(kBufferSize);
|
||||
buffer->set_offset(kPaddingHeaderSize);
|
||||
read_buffers_[from] = buffer;
|
||||
read_size = kBufferSize - kPaddingHeaderSize - kMaxPaddingSize;
|
||||
} else {
|
||||
read_buffers_[from] = new IOBuffer(kBufferSize);
|
||||
read_buffers_[from] = base::MakeRefCounted<IOBuffer>(kBufferSize);
|
||||
}
|
||||
|
||||
DCHECK(sockets_[from]);
|
||||
@ -333,7 +333,7 @@ void NaiveConnection::Push(Direction from, Direction to, int size) {
|
||||
}
|
||||
}
|
||||
if (!trivial_padding) {
|
||||
auto* unpadded_buffer = new IOBuffer(kBufferSize);
|
||||
auto unpadded_buffer = base::MakeRefCounted<IOBuffer>(kBufferSize);
|
||||
char* unpadded_ptr = unpadded_buffer->data();
|
||||
for (int i = 0; i < size;) {
|
||||
if (num_paddings_[from] >= kFirstPaddings &&
|
||||
@ -394,8 +394,8 @@ void NaiveConnection::Push(Direction from, Direction to, int size) {
|
||||
}
|
||||
}
|
||||
|
||||
write_buffers_[to] = new DrainableIOBuffer(read_buffers_[from].get(),
|
||||
write_offset + write_size);
|
||||
write_buffers_[to] = base::MakeRefCounted<DrainableIOBuffer>(
|
||||
std::move(read_buffers_[from]), write_offset + write_size);
|
||||
if (write_offset) {
|
||||
write_buffers_[to]->DidConsume(write_offset);
|
||||
}
|
||||
@ -486,7 +486,13 @@ void NaiveConnection::OnPushComplete(Direction from, Direction to, int result) {
|
||||
write_buffers_[to]->DidConsume(result);
|
||||
int size = write_buffers_[to]->BytesRemaining();
|
||||
if (size > 0) {
|
||||
Push(from, to, size);
|
||||
int rv = sockets_[to]->Write(
|
||||
write_buffers_[to].get(), size,
|
||||
base::BindRepeating(&NaiveConnection::OnPushComplete,
|
||||
weak_ptr_factory_.GetWeakPtr(), from, to),
|
||||
traffic_annotation_);
|
||||
if (rv != ERR_IO_PENDING)
|
||||
OnPushComplete(from, to, rv);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -10,7 +10,7 @@
|
||||
#include <string>
|
||||
|
||||
#include "base/macros.h"
|
||||
#include "base/memory/ref_counted.h"
|
||||
#include "base/memory/scoped_refptr.h"
|
||||
#include "base/memory/weak_ptr.h"
|
||||
#include "base/time/time.h"
|
||||
#include "net/base/completion_once_callback.h"
|
||||
|
@ -285,7 +285,7 @@ int Socks5ServerSocket::DoGreetRead() {
|
||||
|
||||
int handshake_buf_len = greet_read_header_size_ - bytes_received_;
|
||||
DCHECK_LT(0, handshake_buf_len);
|
||||
handshake_buf_ = new IOBuffer(handshake_buf_len);
|
||||
handshake_buf_ = base::MakeRefCounted<IOBuffer>(handshake_buf_len);
|
||||
return transport_->Read(handshake_buf_.get(), handshake_buf_len,
|
||||
io_callback_);
|
||||
}
|
||||
@ -348,7 +348,7 @@ int Socks5ServerSocket::DoGreetWrite() {
|
||||
next_state_ = STATE_GREET_WRITE_COMPLETE;
|
||||
int handshake_buf_len = buffer_.size() - bytes_sent_;
|
||||
DCHECK_LT(0, handshake_buf_len);
|
||||
handshake_buf_ = new IOBuffer(handshake_buf_len);
|
||||
handshake_buf_ = base::MakeRefCounted<IOBuffer>(handshake_buf_len);
|
||||
std::memcpy(handshake_buf_->data(), &buffer_.data()[bytes_sent_],
|
||||
handshake_buf_len);
|
||||
return transport_->Write(handshake_buf_.get(), handshake_buf_len,
|
||||
@ -385,7 +385,7 @@ int Socks5ServerSocket::DoHandshakeRead() {
|
||||
|
||||
int handshake_buf_len = read_header_size_ - bytes_received_;
|
||||
DCHECK_LT(0, handshake_buf_len);
|
||||
handshake_buf_ = new IOBuffer(handshake_buf_len);
|
||||
handshake_buf_ = base::MakeRefCounted<IOBuffer>(handshake_buf_len);
|
||||
return transport_->Read(handshake_buf_.get(), handshake_buf_len,
|
||||
io_callback_);
|
||||
}
|
||||
@ -506,7 +506,7 @@ int Socks5ServerSocket::DoHandshakeWrite() {
|
||||
|
||||
int handshake_buf_len = buffer_.size() - bytes_sent_;
|
||||
DCHECK_LT(0, handshake_buf_len);
|
||||
handshake_buf_ = new IOBuffer(handshake_buf_len);
|
||||
handshake_buf_ = base::MakeRefCounted<IOBuffer>(handshake_buf_len);
|
||||
std::memcpy(handshake_buf_->data(), &buffer_[bytes_sent_], handshake_buf_len);
|
||||
return transport_->Write(handshake_buf_.get(), handshake_buf_len,
|
||||
io_callback_, traffic_annotation_);
|
||||
|
@ -12,7 +12,7 @@
|
||||
#include <string>
|
||||
|
||||
#include "base/macros.h"
|
||||
#include "base/memory/ref_counted.h"
|
||||
#include "base/memory/scoped_refptr.h"
|
||||
#include "net/base/completion_once_callback.h"
|
||||
#include "net/base/completion_repeating_callback.h"
|
||||
#include "net/base/host_port_pair.h"
|
||||
|
Loading…
Reference in New Issue
Block a user