Skip to content

Commit

Permalink
make cross-platform EADDRINUSE check
Browse files Browse the repository at this point in the history
  • Loading branch information
KevRiver committed Nov 2, 2024
1 parent 0f57c86 commit e875e81
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
4 changes: 2 additions & 2 deletions cmd/humanlog/localhost.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ import (
"github.com/rs/cors"
"golang.org/x/net/http2"
"golang.org/x/net/http2/h2c"
"golang.org/x/sys/unix"

// imported for side-effect
internal_errors "github.com/humanlogio/humanlog/internal/errors"
_ "github.com/humanlogio/humanlog/internal/memstorage"
)

Expand All @@ -51,7 +51,7 @@ func isEADDRINUSE(err error) bool {
if !ok {
return false
}
return nserrno == unix.EADDRINUSE
return internal_errors.IsSocketInUse(nserrno)
}

func startLocalhostServer(
Expand Down
13 changes: 13 additions & 0 deletions internal/errors/errors_unix.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//go:build !windows

package errors

import (
"syscall"

"golang.org/x/sys/unix"
)

func IsSocketInUse(errno syscall.Errno) bool {
return errno == unix.EADDRINUSE
}
13 changes: 13 additions & 0 deletions internal/errors/errors_windows.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//go:build windows

package errors

import (
"syscall"

"golang.org/x/sys/windows"
)

func IsSocketInUse(errno syscall.Errno) bool {
return errno == windows.WSAEADDRINUSE
}

0 comments on commit e875e81

Please sign in to comment.