Commit eb96532b authored by rjshade's avatar rjshade Committed by Commit bot

Remove inability to call QuicSimpleServerPacketWriter::WritePacket directly.

Fixes toy server crash described here:
https://groups.google.com/a/chromium.org/forum/#!topic/proto-quic/ziwUgZbV2Wk

BUG=

Review-Url: https://codereview.chromium.org/2180003004
Cr-Commit-Position: refs/heads/master@{#408221}
parent b14b5323
......@@ -45,7 +45,9 @@ void QuicSimpleServerPacketWriter::OnWriteComplete(int rv) {
DCHECK_NE(rv, ERR_IO_PENDING);
write_blocked_ = false;
WriteResult result(rv < 0 ? WRITE_STATUS_ERROR : WRITE_STATUS_OK, rv);
base::ResetAndReturn(&callback_).Run(result);
if (!callback_.is_null()) {
base::ResetAndReturn(&callback_).Run(result);
}
blocked_writer_->OnCanWrite();
}
......@@ -71,7 +73,6 @@ WriteResult QuicSimpleServerPacketWriter::WritePacket(
scoped_refptr<StringIOBuffer> buf(
new StringIOBuffer(std::string(buffer, buf_len)));
DCHECK(!IsWriteBlocked());
DCHECK(!callback_.is_null());
int rv;
if (buf_len <= static_cast<size_t>(std::numeric_limits<int>::max())) {
rv = socket_->SendTo(
......
......@@ -33,15 +33,19 @@ class QuicSimpleServerPacketWriter : public QuicPacketWriter {
QuicBlockedWriterInterface* blocked_writer);
~QuicSimpleServerPacketWriter() override;
// Use this method to write packets rather than WritePacket:
// QuicSimpleServerPacketWriter requires a callback to exist for every
// write, which will be called once the write completes.
virtual WriteResult WritePacketWithCallback(const char* buffer,
size_t buf_len,
const IPAddress& self_address,
const IPEndPoint& peer_address,
PerPacketOptions* options,
WriteCallback callback);
// Wraps WritePacket, and ensures that |callback| is run on successful write.
WriteResult WritePacketWithCallback(const char* buffer,
size_t buf_len,
const IPAddress& self_address,
const IPEndPoint& peer_address,
PerPacketOptions* options,
WriteCallback callback);
WriteResult WritePacket(const char* buffer,
size_t buf_len,
const IPAddress& self_address,
const IPEndPoint& peer_address,
PerPacketOptions* options) override;
void OnWriteComplete(int rv);
......@@ -51,14 +55,6 @@ class QuicSimpleServerPacketWriter : public QuicPacketWriter {
void SetWritable() override;
QuicByteCount GetMaxPacketSize(const IPEndPoint& peer_address) const override;
protected:
// Do not call WritePacket on its own -- use WritePacketWithCallback
WriteResult WritePacket(const char* buffer,
size_t buf_len,
const IPAddress& self_address,
const IPEndPoint& peer_address,
PerPacketOptions* options) override;
private:
UDPServerSocket* socket_;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment