mirror of
https://github.com/romanz/electrs.git
synced 2025-02-23 14:50:45 +01:00
Reuse buffer in p2p handling (#910)
This commit is contained in:
parent
b041adf9bc
commit
fae1e61946
1 changed files with 7 additions and 1 deletions
|
@ -1,5 +1,6 @@
|
|||
use anyhow::{Context, Result};
|
||||
use bitcoin::blockdata::block::Header as BlockHeader;
|
||||
use bitcoin::consensus::Encodable;
|
||||
use bitcoin::{
|
||||
consensus::{
|
||||
encode::{self, ReadExt, VarInt},
|
||||
|
@ -173,6 +174,7 @@ impl Connection {
|
|||
);
|
||||
|
||||
let stream = Arc::clone(&conn);
|
||||
let mut buffer = vec![];
|
||||
crate::thread::spawn("p2p_send", move || loop {
|
||||
use std::net::Shutdown;
|
||||
let msg = match send_duration.observe_duration("wait", || tx_recv.recv()) {
|
||||
|
@ -193,8 +195,12 @@ impl Connection {
|
|||
magic,
|
||||
payload: msg,
|
||||
};
|
||||
buffer.clear();
|
||||
raw_msg
|
||||
.consensus_encode(&mut buffer)
|
||||
.expect("in-memory writers don't error");
|
||||
(&*stream)
|
||||
.write_all(encode::serialize(&raw_msg).as_slice())
|
||||
.write_all(buffer.as_slice())
|
||||
.context("p2p failed to send")
|
||||
})?;
|
||||
});
|
||||
|
|
Loading…
Add table
Reference in a new issue