diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..a2950e2 --- /dev/null +++ b/Makefile @@ -0,0 +1,21 @@ +fmt: + gofumpt -l -w . + gofmt -s -w . + gci write -s "standard,prefix(github.com/sagernet/),default" . + +lint_install: + go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest + +lint: + GOOS=linux golangci-lint run ./... + GOOS=windows golangci-lint run ./... + GOOS=darwin golangci-lint run ./... + GOOS=freebsd golangci-lint run ./... + +test: + go test -v . + +update: + git fetch + git reset FETCH_HEAD --hard + git clean -fdx \ No newline at end of file diff --git a/common/bufio/race.go b/common/bufio/race.go new file mode 100644 index 0000000..576e987 --- /dev/null +++ b/common/bufio/race.go @@ -0,0 +1,36 @@ +package bufio + +import ( + "io" + "sync" + + "github.com/sagernet/sing/common/buf" + N "github.com/sagernet/sing/common/network" +) + +type RaceWriter struct { + upstream N.ExtendedWriter + access sync.Mutex +} + +func NewRaceWriter(writer io.Writer) *RaceWriter { + return &RaceWriter{ + upstream: NewExtendedWriter(writer), + } +} + +func (w *RaceWriter) WriteBuffer(buffer *buf.Buffer) error { + w.access.Lock() + defer w.access.Unlock() + return w.upstream.WriteBuffer(buffer) +} + +func (w *RaceWriter) Write(p []byte) (n int, err error) { + w.access.Lock() + defer w.access.Unlock() + return w.upstream.Write(p) +} + +func (w *RaceWriter) Upstream() any { + return w.upstream +} diff --git a/format.go b/format.go deleted file mode 100644 index 7b30b9a..0000000 --- a/format.go +++ /dev/null @@ -1,7 +0,0 @@ -package box - -//go:generate go install -v mvdan.cc/gofumpt@latest -//go:generate go install -v github.com/daixiang0/gci@v0.4.0 -//go:generate gofumpt -l -w . -//go:generate gofmt -s -w . -//go:generate gci write -s "standard,prefix(github.com/sagernet/),default" .