forked from M-Labs/zynq-rs
libasync: create TcpSocketBuffers from uninitialized memory
This commit is contained in:
parent
0618642d3f
commit
75a8889d28
|
@ -47,9 +47,15 @@ macro_rules! poll_stream {
|
||||||
|
|
||||||
impl TcpStream {
|
impl TcpStream {
|
||||||
fn new(rx_bufsize: usize, tx_bufsize: usize) -> Self {
|
fn new(rx_bufsize: usize, tx_bufsize: usize) -> Self {
|
||||||
// TODO: Uninitialized is faster than zeroed
|
fn uninit_vec<T>(size: usize) -> Vec<T> {
|
||||||
let rx_buffer = TcpSocketBuffer::new(vec![0u8; rx_bufsize]);
|
let mut result = Vec::with_capacity(size);
|
||||||
let tx_buffer = TcpSocketBuffer::new(vec![0u8; tx_bufsize]);
|
unsafe {
|
||||||
|
result.set_len(size);
|
||||||
|
}
|
||||||
|
result
|
||||||
|
}
|
||||||
|
let rx_buffer = TcpSocketBuffer::new(uninit_vec(rx_bufsize));
|
||||||
|
let tx_buffer = TcpSocketBuffer::new(uninit_vec(tx_bufsize));
|
||||||
let socket = TcpSocket::new(rx_buffer, tx_buffer);
|
let socket = TcpSocket::new(rx_buffer, tx_buffer);
|
||||||
let handle = Sockets::instance().sockets.borrow_mut()
|
let handle = Sockets::instance().sockets.borrow_mut()
|
||||||
.add(socket);
|
.add(socket);
|
||||||
|
|
Loading…
Reference in New Issue