Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PR: error handling bug, rebase, unexport, naming
* changed names to be more conventional * unexported socket code * made `(*HvsockDialer) Dial` take `Context`, removed `DialContext` * added default `Dial` function * rebased onto main Signed-off-by: Hamza El-Saawy <hamzaelsaawy@microsoft.com>
- Loading branch information
Showing
5 changed files
with
112 additions
and
116 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package socket | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
"unsafe" | ||
) | ||
|
||
// todo: should these be custom types to store the desired/actual size and addr family? | ||
|
||
var ( | ||
ErrBufferSize = errors.New("buffer size") | ||
ErrInvalidPointer = errors.New("invalid pointer") | ||
ErrAddrFamily = errors.New("address family") | ||
) | ||
|
||
// todo: replace this with generics, along with GetSockName and co. | ||
|
||
// RawSockaddr allows structs to be used with Bind and ConnectEx. The | ||
// struct must meet the Wind32 sockaddr requirements specified here: | ||
// https://docs.microsoft.com/en-us/windows/win32/winsock/sockaddr-2 | ||
type RawSockaddr interface { | ||
// Sockaddr returns a pointer to the RawSockaddr and the length of the struct. | ||
Sockaddr() (unsafe.Pointer, int32, error) | ||
|
||
// FromBytes populates the RawsockAddr with the data in the byte array. | ||
// Implementers should check the buffer is correctly sized and the address family | ||
// is appropriate. | ||
// Receivers should be pointers. | ||
FromBytes([]byte) error | ||
} | ||
|
||
func validateSockAddr(ptr unsafe.Pointer, n int32) error { | ||
if ptr == nil { | ||
return fmt.Errorf("pointer is %p: %w", ptr, ErrInvalidPointer) | ||
} | ||
if n < 1 { | ||
return fmt.Errorf("buffer size %d < 1: %w", n, ErrBufferSize) | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
pkg/sockets/zsyscall_windows.go → internal/socket/zsyscall_windows.go
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.