Skip to content

Commit ee0e418

Browse files
committed
refactor: simplify packet sending loop using core::slice::chunks
1 parent 9e375b6 commit ee0e418

1 file changed

Lines changed: 2 additions & 12 deletions

File tree

apps/src/sendto.rs

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@
2424
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
2525
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2626

27-
use std::cmp;
28-
2927
use std::io;
3028

3129
/// For Linux, try to detect GSO is available.
@@ -109,22 +107,14 @@ pub fn send_to(
109107
}
110108
}
111109

112-
let mut off = 0;
113-
let mut left = buf.len();
114110
let mut written = 0;
115-
116-
while left > 0 {
117-
let pkt_len = cmp::min(left, segment_size);
118-
119-
match socket.send_to(&buf[off..off + pkt_len], send_info.to) {
111+
for chunk in buf.chunks(segment_size) {
112+
match socket.send_to(chunk, send_info.to) {
120113
Ok(v) => {
121114
written += v;
122115
},
123116
Err(e) => return Err(e),
124117
}
125-
126-
off += pkt_len;
127-
left -= pkt_len;
128118
}
129119

130120
Ok(written)

0 commit comments

Comments
 (0)