netstack: remove {linux,darwin}HostTranslation

It can be replaced with a simpler type.

PiperOrigin-RevId: 409533054
This commit is contained in:
Kevin Krakauer
2021-11-12 16:24:59 -08:00
committed by gVisor bot
parent 82793c5e90
commit b490036d83
2 changed files with 10 additions and 20 deletions
+5 -10
View File
@@ -25,26 +25,21 @@ import (
const maxErrno = 107
type darwinHostTranslation struct {
err *Error
ok bool
}
var darwinHostTranslations [maxErrno]darwinHostTranslation
var darwinHostTranslations [maxErrno]*Error
// FromHost translates a unix.Errno to a corresponding Error value.
func FromHost(err unix.Errno) *Error {
if int(err) >= len(darwinHostTranslations) || !darwinHostTranslations[err].ok {
if int(err) >= len(darwinHostTranslations) || darwinHostTranslations[err] == nil {
panic(fmt.Sprintf("unknown host errno %q (%d)", err.Error(), err))
}
return darwinHostTranslations[err].err
return darwinHostTranslations[err]
}
// TODO(gvisor.dev/issue/1270): We currently only add translations for errors
// that exist both on Darwin and Linux.
func addHostTranslation(host unix.Errno, trans *Error) {
if darwinHostTranslations[host].ok {
if darwinHostTranslations[host] != nil {
panic(fmt.Sprintf("duplicate translation for host errno %q (%d)", host.Error(), host))
}
darwinHostTranslations[host] = darwinHostTranslation{err: trans, ok: true}
darwinHostTranslations[host] = trans
}
+5 -10
View File
@@ -26,26 +26,21 @@ import (
const maxErrno = 134
type linuxHostTranslation struct {
err *Error
ok bool
}
var linuxHostTranslations [maxErrno]linuxHostTranslation
var linuxHostTranslations [maxErrno]*Error
// FromHost translates a unix.Errno to a corresponding Error value.
func FromHost(err unix.Errno) *Error {
if int(err) >= len(linuxHostTranslations) || !linuxHostTranslations[err].ok {
if int(err) >= len(linuxHostTranslations) || linuxHostTranslations[err] == nil {
panic(fmt.Sprintf("unknown host errno %q (%d)", err.Error(), err))
}
return linuxHostTranslations[err].err
return linuxHostTranslations[err]
}
func addHostTranslation(host unix.Errno, trans *Error) {
if linuxHostTranslations[host].ok {
if linuxHostTranslations[host] != nil {
panic(fmt.Sprintf("duplicate translation for host errno %q (%d)", host.Error(), host))
}
linuxHostTranslations[host] = linuxHostTranslation{err: trans, ok: true}
linuxHostTranslations[host] = trans
}
// TODO(b/34162363): Remove or replace most of these errors.