Skip to content

Commit 94e88da

Browse files
committed
hook connect
1 parent 5ee597c commit 94e88da

File tree

3 files changed

+9
-9
lines changed

3 files changed

+9
-9
lines changed

core/src/syscall/unix/connect.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ impl<I: ConnectSyscall> ConnectSyscall for NioConnectSyscall<I> {
6868
break;
6969
}
7070
let errno = Error::last_os_error().raw_os_error();
71-
if errno == Some(libc::EINPROGRESS) || errno == Some(libc::EALREADY) {
71+
if errno == Some(libc::EINPROGRESS) || errno == Some(libc::EALREADY) || errno == Some(libc::EWOULDBLOCK) {
7272
//阻塞,直到写事件发生
7373
if EventLoops::wait_write_event(fd, Some(crate::common::constants::SLICE)).is_err()
7474
{

core/src/syscall/windows/connect.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use crate::syscall::common::{is_blocking, reset_errno, set_blocking, set_errno,
33
use once_cell::sync::Lazy;
44
use std::ffi::c_int;
55
use std::io::Error;
6-
use windows_sys::Win32::Networking::WinSock::{getpeername, getsockopt, SO_ERROR, SOCKADDR, SOCKET, SOL_SOCKET, WSAEALREADY, WSAEINPROGRESS, WSAEINTR, WSAETIMEDOUT};
6+
use windows_sys::Win32::Networking::WinSock::{getpeername, getsockopt, SO_ERROR, SOCKADDR, SOCKET, SOL_SOCKET, WSAEALREADY, WSAEINPROGRESS, WSAEINTR, WSAETIMEDOUT, WSAEWOULDBLOCK};
77

88
#[must_use]
99
pub extern "system" fn connect(
@@ -56,7 +56,7 @@ impl<I: ConnectSyscall> ConnectSyscall for NioConnectSyscall<I> {
5656
break;
5757
}
5858
let errno = Error::last_os_error().raw_os_error();
59-
if errno == Some(WSAEINPROGRESS) || errno == Some(WSAEALREADY) {
59+
if errno == Some(WSAEINPROGRESS) || errno == Some(WSAEALREADY) || errno == Some(WSAEWOULDBLOCK) {
6060
//阻塞,直到写事件发生
6161
if EventLoops::wait_write_event(
6262
fd as _,

hook/src/syscall/windows.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,11 @@ unsafe fn attach() -> std::io::Result<()> {
6969
address: *mut SOCKADDR,
7070
address_len: *mut c_int
7171
) -> SOCKET);
72+
impl_hook!("ws2_32.dll", CONNECT, connect(
73+
fd: SOCKET,
74+
address: *const SOCKADDR,
75+
len: c_int
76+
) -> c_int);
7277
impl_hook!("ws2_32.dll", IOCTLSOCKET, ioctlsocket(
7378
fd: SOCKET,
7479
cmd: c_int,
@@ -154,18 +159,13 @@ unsafe fn attach() -> std::io::Result<()> {
154159
lpnewfilepointer : *mut c_longlong,
155160
dwmovemethod : SET_FILE_POINTER_MOVE_METHOD
156161
) -> BOOL);
157-
// NOTE: unhook WaitOnAddress/connect due to stack overflow or bug
162+
// NOTE: unhook WaitOnAddress due to stack overflow or bug
158163
// impl_hook!("api-ms-win-core-synch-l1-2-0.dll", WAITONADDRESS, WaitOnAddress(
159164
// address: *const c_void,
160165
// compareaddress: *const c_void,
161166
// addresssize: usize,
162167
// dwmilliseconds: c_uint
163168
// ) -> BOOL);
164-
// impl_hook!("ws2_32.dll", CONNECT, connect(
165-
// fd: SOCKET,
166-
// address: *const SOCKADDR,
167-
// len: c_int
168-
// ) -> c_int);
169169
// Enable the hook
170170
minhook::MinHook::enable_all_hooks()
171171
.map_err(|_| Error::new(ErrorKind::Other, "init all hooks failed !"))

0 commit comments

Comments
 (0)