Skip to content

Commit e8be4be

Browse files
committed
fix connect bug
1 parent 7c55eb5 commit e8be4be

File tree

2 files changed

+16
-36
lines changed

2 files changed

+16
-36
lines changed

core/src/syscall/unix/mod.rs

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -131,9 +131,7 @@ macro_rules! impl_nio_read {
131131
$crate::syscall::common::set_non_blocking($fd);
132132
}
133133
let start_time = $crate::common::now();
134-
let mut left_time = start_time
135-
.saturating_add($crate::syscall::common::recv_time_limit($fd))
136-
.saturating_sub(start_time);
134+
let mut left_time = $crate::syscall::common::recv_time_limit($fd);
137135
let mut r = -1;
138136
while left_time > 0 {
139137
r = self.inner.$syscall(fn_ptr, $fd, $($arg, )*);
@@ -191,9 +189,7 @@ macro_rules! impl_nio_read_buf {
191189
$crate::syscall::common::set_non_blocking($fd);
192190
}
193191
let start_time = $crate::common::now();
194-
let mut left_time = start_time
195-
.saturating_add($crate::syscall::common::recv_time_limit($fd))
196-
.saturating_sub(start_time);
192+
let mut left_time = $crate::syscall::common::recv_time_limit($fd);
197193
let mut received = 0;
198194
let mut r = 0;
199195
while received < $len && left_time > 0 {
@@ -262,9 +258,7 @@ macro_rules! impl_nio_read_iovec {
262258
$crate::syscall::common::set_non_blocking($fd);
263259
}
264260
let start_time = $crate::common::now();
265-
let mut left_time = start_time
266-
.saturating_add($crate::syscall::common::recv_time_limit($fd))
267-
.saturating_sub(start_time);
261+
let mut left_time = $crate::syscall::common::recv_time_limit($fd);
268262
let vec = unsafe { Vec::from_raw_parts($iov.cast_mut(), $iovcnt as usize, $iovcnt as usize) };
269263
let mut length = 0;
270264
let mut received = 0usize;
@@ -375,9 +369,7 @@ macro_rules! impl_nio_write_buf {
375369
$crate::syscall::common::set_non_blocking($fd);
376370
}
377371
let start_time = $crate::common::now();
378-
let mut left_time = start_time
379-
.saturating_add($crate::syscall::common::send_time_limit($fd))
380-
.saturating_sub(start_time);
372+
let mut left_time = $crate::syscall::common::send_time_limit($fd);
381373
let mut sent = 0;
382374
let mut r = 0;
383375
while sent < $len && left_time > 0 {
@@ -448,9 +440,7 @@ macro_rules! impl_nio_write_iovec {
448440
$crate::syscall::common::set_non_blocking($fd);
449441
}
450442
let start_time = $crate::common::now();
451-
let mut left_time = start_time
452-
.saturating_add($crate::syscall::common::send_time_limit($fd))
453-
.saturating_sub(start_time);
443+
let mut left_time = $crate::syscall::common::send_time_limit($fd);
454444
let vec = unsafe { Vec::from_raw_parts($iov.cast_mut(), $iovcnt as usize, $iovcnt as usize) };
455445
let mut length = 0;
456446
let mut sent = 0usize;
@@ -703,7 +693,7 @@ pub extern "C" fn send_time_limit(fd: c_int) -> u64 {
703693
// not a socket
704694
return u64::MAX;
705695
}
706-
panic!("getsockopt failed: {}", error);
696+
panic!("getsockopt failed: {error}");
707697
}
708698
let mut time_limit = (tv.tv_sec as u64)
709699
.saturating_mul(1_000_000_000)
@@ -738,7 +728,7 @@ pub extern "C" fn recv_time_limit(fd: c_int) -> u64 {
738728
// not a socket
739729
return u64::MAX;
740730
}
741-
panic!("getsockopt failed: {}", error);
731+
panic!("getsockopt failed: {error}");
742732
}
743733
let mut time_limit = (tv.tv_sec as u64)
744734
.saturating_mul(1_000_000_000)

core/src/syscall/windows/mod.rs

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,8 @@ macro_rules! impl_nio_read {
6363
$crate::syscall::common::set_non_blocking($fd);
6464
}
6565
let start_time = $crate::common::now();
66-
let mut left_time = start_time
67-
.saturating_add($crate::syscall::common::recv_time_limit($fd))
68-
.saturating_sub(start_time);
69-
let mut r = -1;
66+
let mut left_time = $crate::syscall::common::recv_time_limit($fd);
67+
let mut r = 0;
7068
while left_time > 0 {
7169
r = self.inner.$syscall(fn_ptr, $fd, $($arg, )*);
7270
if r != -1 as _ {
@@ -123,9 +121,7 @@ macro_rules! impl_nio_read_buf {
123121
$crate::syscall::common::set_non_blocking($fd);
124122
}
125123
let start_time = $crate::common::now();
126-
let mut left_time = start_time
127-
.saturating_add($crate::syscall::common::recv_time_limit($fd))
128-
.saturating_sub(start_time);
124+
let mut left_time = $crate::syscall::common::recv_time_limit($fd);
129125
let mut received = 0;
130126
let mut r = 0;
131127
while received < $len && left_time > 0 {
@@ -196,9 +192,7 @@ macro_rules! impl_nio_read_iovec {
196192
$crate::syscall::common::set_non_blocking($fd);
197193
}
198194
let start_time = $crate::common::now();
199-
let mut left_time = start_time
200-
.saturating_add($crate::syscall::common::recv_time_limit($fd))
201-
.saturating_sub(start_time);
195+
let mut left_time = $crate::syscall::common::recv_time_limit($fd);
202196
let vec = unsafe { Vec::from_raw_parts($iov.cast_mut(), $iovcnt as usize, $iovcnt as usize) };
203197
let mut length = 0;
204198
let mut received = 0usize;
@@ -309,9 +303,7 @@ macro_rules! impl_nio_write_buf {
309303
$crate::syscall::common::set_non_blocking($fd);
310304
}
311305
let start_time = $crate::common::now();
312-
let mut left_time = start_time
313-
.saturating_add($crate::syscall::common::send_time_limit($fd))
314-
.saturating_sub(start_time);
306+
let mut left_time = $crate::syscall::common::send_time_limit($fd);
315307
let mut sent = 0;
316308
let mut r = 0;
317309
while sent < $len && left_time > 0 {
@@ -382,9 +374,7 @@ macro_rules! impl_nio_write_iovec {
382374
$crate::syscall::common::set_non_blocking($fd);
383375
}
384376
let start_time = $crate::common::now();
385-
let mut left_time = start_time
386-
.saturating_add($crate::syscall::common::send_time_limit($fd))
387-
.saturating_sub(start_time);
377+
let mut left_time = $crate::syscall::common::send_time_limit($fd);
388378
let vec = unsafe { Vec::from_raw_parts($iov.cast_mut(), $iovcnt as usize, $iovcnt as usize) };
389379
let mut length = 0;
390380
let mut sent = 0usize;
@@ -401,7 +391,7 @@ macro_rules! impl_nio_write_iovec {
401391
for i in vec.iter().skip(index) {
402392
arg.push(*i);
403393
}
404-
while sent < length {
394+
while sent < length && left_time > 0 {
405395
if 0 != offset {
406396
arg[0] = windows_sys::Win32::Networking::WinSock::WSABUF {
407397
buf: (arg[0].buf as usize + offset) as windows_sys::core::PSTR,
@@ -577,7 +567,7 @@ pub extern "system" fn send_time_limit(fd: SOCKET) -> u64 {
577567
// not a socket
578568
return u64::MAX;
579569
}
580-
panic!("getsockopt failed: {}", error);
570+
panic!("getsockopt failed: {error}");
581571
}
582572
let mut time_limit = (ms as u64).saturating_mul(1_000_000);
583573
if 0 == time_limit {
@@ -612,7 +602,7 @@ pub extern "system" fn recv_time_limit(fd: SOCKET) -> u64 {
612602
// not a socket
613603
return u64::MAX;
614604
}
615-
panic!("getsockopt failed: {}", error);
605+
panic!("getsockopt failed: {error}");
616606
}
617607
let mut time_limit = (ms as u64).saturating_mul(1_000_000);
618608
if 0 == time_limit {

0 commit comments

Comments
 (0)