Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitd812b4f

Browse files
committed
catnap: active_socket: avoid unnecessary addr clone
There is no need to clone addr because the ownership can be cleanlytransfered to the callee.
1 parent987aa22 commitd812b4f

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

‎src/catnap/linux/active_socket.rs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,8 @@ impl ActiveSocketData {
9090
// Put the buffer back and try again later.
9191
self.send_queue.push_front(Outgoing{ addr, buffer, result});
9292
}else{
93-
let cause =format!("failed to send on socket: {:?}", errno);
94-
error!("poll_send(): {}", cause);
95-
result.set(Some(Err(Fail::new(errno,&cause))));
93+
error!("poll_send(): failed on socket: {:?}", errno);
94+
result.set(Some(Err(Fail::new(errno,"send failed on socket"))));
9695
}
9796
},
9897
}
@@ -126,9 +125,8 @@ impl ActiveSocketData {
126125
Err(e) =>{
127126
let errno =get_libc_err(e);
128127
if !DemiRuntime::should_retry(errno){
129-
let cause =format!("failed to receive on socket: {:?}", errno);
130-
error!("poll_recv(): {}", cause);
131-
self.recv_queue.push(Err(Fail::new(errno,&cause)));
128+
error!("poll_recv(): failed on socket: {:?}", errno);
129+
self.recv_queue.push(Err(Fail::new(errno,"receive failed on socket")));
132130
}
133131
},
134132
}
@@ -153,21 +151,22 @@ impl ActiveSocketData {
153151
}
154152
}
155153

156-
///Pops data from the socket.Blocks until some data is found but does not wait until the buf has reached [size].
154+
/// Blocks until some data is found but does not wait until the buf has reached [size].
157155
pubasyncfnpop(
158156
&mutself,
159157
size:usize,
160158
timeout:Option<Duration>,
161159
) ->Result<(Option<SocketAddr>,DemiBuffer),Fail>{
162160
let(addr,mut buffer) =self.recv_queue.pop(timeout).await??;
163-
// Figure out how much data we got.
164161
let bytes_read =min(buffer.len(), size);
162+
165163
// Trim the buffer and leave for next read if we got more than expected.
166164
ifletOk(remainder) = buffer.split_back(bytes_read){
167165
if !remainder.is_empty(){
168-
self.push_front(remainder, addr.clone());
166+
self.push_front(remainder, addr);
169167
}
170168
}
169+
171170
Ok((addr, buffer))
172171
}
173172

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp