-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fixup! conn, device, tun: implement vectorized I/O on Linux
- Loading branch information
Showing
9 changed files
with
106 additions
and
25 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,11 @@ | ||
// Package native provides easy access to native byte order. | ||
// | ||
// Usage: use native.Endian where you need the native binary.ByteOrder. | ||
// | ||
// Please think twice before using this package. | ||
// It can break program portability. | ||
// Native byte order is usually not the right answer. | ||
// This package is a drop-in of github.com/josharian/native, with attribution in | ||
// the file 'license'. This package will likely be replaced by something similar | ||
// in the standard library, see https://github.com/golang/go/issues/57237. | ||
package native |
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,14 @@ | ||
//go:build mips || mips64 || ppc64 || s390x | ||
// +build mips mips64 ppc64 s390x | ||
|
||
package native | ||
|
||
import "encoding/binary" | ||
|
||
// Endian is the encoding/binary.ByteOrder implementation for the | ||
// current CPU's native byte order. | ||
var Endian = binary.BigEndian | ||
|
||
// IsBigEndian is whether the current CPU's native byte order is big | ||
// endian. | ||
const IsBigEndian = true |
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,31 @@ | ||
//go:build !mips && !mips64 && !ppc64 && !s390x && !amd64 && !386 && !arm && !arm64 && !loong64 && !mipsle && !mips64le && !ppc64le && !riscv64 && !wasm | ||
// +build !mips,!mips64,!ppc64,!s390x,!amd64,!386,!arm,!arm64,!loong64,!mipsle,!mips64le,!ppc64le,!riscv64,!wasm | ||
|
||
// This file is a fallback, so that package native doesn't break | ||
// the instant the Go project adds support for a new architecture. | ||
// | ||
|
||
package native | ||
|
||
import ( | ||
"encoding/binary" | ||
"log" | ||
"runtime" | ||
"unsafe" | ||
) | ||
|
||
var Endian binary.ByteOrder | ||
|
||
var IsBigEndian bool | ||
|
||
func init() { | ||
b := uint16(0xff) // one byte | ||
if *(*byte)(unsafe.Pointer(&b)) == 0 { | ||
Endian = binary.BigEndian | ||
IsBigEndian = true | ||
} else { | ||
Endian = binary.LittleEndian | ||
IsBigEndian = false | ||
} | ||
log.Printf("unrecognized arch %v (%v), please file an issue", runtime.GOARCH, Endian) | ||
} |
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,14 @@ | ||
//go:build amd64 || 386 || arm || arm64 || loong64 || mipsle || mips64le || ppc64le || riscv64 || wasm | ||
// +build amd64 386 arm arm64 loong64 mipsle mips64le ppc64le riscv64 wasm | ||
|
||
package native | ||
|
||
import "encoding/binary" | ||
|
||
// Endian is the encoding/binary.ByteOrder implementation for the | ||
// current CPU's native byte order. | ||
var Endian = binary.LittleEndian | ||
|
||
// IsBigEndian is whether the current CPU's native byte order is big | ||
// endian. | ||
const IsBigEndian = false |
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,20 @@ | ||
package native_test | ||
|
||
import ( | ||
"encoding/binary" | ||
"testing" | ||
|
||
"golang.zx2c4.com/wireguard/native" | ||
) | ||
|
||
func TestPrintEndianness(t *testing.T) { | ||
t.Logf("native endianness is %v", native.Endian) | ||
|
||
var want binary.ByteOrder = binary.BigEndian | ||
if !native.IsBigEndian { | ||
want = binary.LittleEndian | ||
} | ||
if native.Endian != want { | ||
t.Errorf("IsBigEndian = %v not consistent with native.Endian = %T", native.IsBigEndian, want) | ||
} | ||
} |
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,7 @@ | ||
Copyright 2020 Josh Bleecher Snyder | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
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
439157b
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you miss my comment about how I think this package is unnecessary?
#64 (comment)