func main() {
conn, connErr := net.Dial("tcp", "127.0.0.1:9527")
if connErr != nil {
fmt.Printf("Failed to dial: %vn", connErr)
return
}
handle := windows.Handle(getSocketFd2(conn))
handle2, err := windows.WSASocket(int32(windows.AF_INET), int32(windows.SOCK_STREAM), int32(windows.IPPROTO_TCP), nil, 0, windows.WSA_FLAG_OVERLAPPED|windows.WSA_FLAG_NO_HANDLE_INHERIT)
iocp, err := windows.CreateIoCompletionPort(windows.InvalidHandle, 0, 0, 0)
if err != nil {
fmt.Printf("CreateIoCompletionPort failed11: %vn", err)
return
}
// Bind the socket with IOCP
iocpHandle, err := windows.CreateIoCompletionPort(handle2, iocp, 0, 0)
if err != nil {
fmt.Printf("CreateIoCompletionPort handle2 failed: %vn", err)
return
}
// Bind the socket with IOCP
iocpHandle, err = windows.CreateIoCompletionPort(handle, iocp, 0, 0)
//There will be an error here CreateIoCompletionPort handle failed: The parameter is incorrect.
if err != nil {
fmt.Printf("CreateIoCompletionPort handle failed: %vn", err)
return
}
if iocpHandle == windows.InvalidHandle {
fmt.Println("CreateIoCompletionPort returned invalid handle")
} else {
fmt.Println("IOCP and socket handle are valid")
}
}
Listening to fd through iocp will always prompt ‘The parameter is incorrect’
I tried to take a look at ‘net’ The source code for creating a Socket on Windows is called ‘Windows.’
WSASocket(int32(windows.AF_INET), int32(windows. SOCK_STREAM), int32(windows. IPPROTO_TCP), nil, 0, windows.WSA_FLAG_OVERLAPPED|windows.WSA_FLAG_NO_HANDLE_INHERIT)
If I also use this Windows The WSASocket function will be successfully monitored by iocp upon creation
If obtaining the fd of conn, an error message will appear indicating that the parameter is incorrect