mirror of
https://github.com/ScuroNeko/mtg.git
synced 2026-08-31 17:24:02 +03:00
REPOSITORY / ScuroNeko/mtg
Compare commits
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
28fe63dbdb | ||
|
|
7718f62477 | ||
|
|
df0994dad3 | ||
|
|
dca43853fb | ||
|
|
ea8e31346c | ||
|
|
4aab3b686c | ||
|
|
ed495b3800 | ||
|
|
4025f223c4 | ||
|
|
121200cfad | ||
|
|
a8c4d0a9c4 | ||
|
|
790bf21166 | ||
|
|
e5b9c841cd | ||
|
|
8ccf61c23e | ||
|
|
0e033b59b3 | ||
|
|
cdd93bd25f | ||
|
|
cac476901d | ||
|
|
bb21bf814f | ||
|
|
68e1d66017 |
@@ -125,7 +125,7 @@ jobs:
|
||||
with:
|
||||
pull: true
|
||||
context: .
|
||||
platforms: linux/amd64,linux/arm64,linux/386
|
||||
platforms: linux/amd64,linux/arm64,linux/386,linux/arm/v7,linux/arm/v6
|
||||
push: ${{ github.event_name != 'pull_request' }}
|
||||
tags: ${{ steps.docker_meta.outputs.tags }}
|
||||
labels: ${{ steps.docker_meta.outputs.labels }}
|
||||
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
###############################################################################
|
||||
# BUILD STAGE
|
||||
|
||||
FROM golang:1.15-alpine AS build
|
||||
FROM golang:1.16-alpine AS build
|
||||
|
||||
RUN set -x \
|
||||
&& apk --no-cache --update add \
|
||||
|
||||
+12
-34
@@ -2,7 +2,6 @@ package stream
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"errors"
|
||||
"io"
|
||||
"net"
|
||||
"sync"
|
||||
@@ -18,10 +17,10 @@ type ReadWriteCloseRewinder interface {
|
||||
}
|
||||
|
||||
type wrapperRewind struct {
|
||||
parent conntypes.StreamReadWriteCloser
|
||||
buf bytes.Buffer
|
||||
mutex sync.Mutex
|
||||
rewinded bool
|
||||
parent conntypes.StreamReadWriteCloser
|
||||
activeReader io.Reader
|
||||
buf bytes.Buffer
|
||||
mutex sync.Mutex
|
||||
}
|
||||
|
||||
func (w *wrapperRewind) Write(p []byte) (int, error) {
|
||||
@@ -36,38 +35,14 @@ func (w *wrapperRewind) Read(p []byte) (int, error) {
|
||||
w.mutex.Lock()
|
||||
defer w.mutex.Unlock()
|
||||
|
||||
if w.rewinded {
|
||||
if n, err := w.buf.Read(p); errors.Is(err, io.EOF) {
|
||||
return n, err // nolint: wrapcheck
|
||||
}
|
||||
}
|
||||
|
||||
n, err := w.parent.Read(p)
|
||||
|
||||
if !w.rewinded {
|
||||
w.buf.Write(p[:n])
|
||||
}
|
||||
|
||||
return n, err // nolint: wrapcheck
|
||||
return w.activeReader.Read(p)
|
||||
}
|
||||
|
||||
func (w *wrapperRewind) ReadTimeout(p []byte, timeout time.Duration) (int, error) {
|
||||
func (w *wrapperRewind) ReadTimeout(p []byte, _ time.Duration) (int, error) {
|
||||
w.mutex.Lock()
|
||||
defer w.mutex.Unlock()
|
||||
|
||||
if w.rewinded {
|
||||
if n, err := w.buf.Read(p); errors.Is(err, io.EOF) {
|
||||
return n, err // nolint: wrapcheck
|
||||
}
|
||||
}
|
||||
|
||||
n, err := w.parent.ReadTimeout(p, timeout)
|
||||
|
||||
if !w.rewinded {
|
||||
w.buf.Write(p[:n])
|
||||
}
|
||||
|
||||
return n, err // nolint: wrapcheck
|
||||
return w.activeReader.Read(p)
|
||||
}
|
||||
|
||||
func (w *wrapperRewind) Conn() net.Conn {
|
||||
@@ -94,12 +69,15 @@ func (w *wrapperRewind) Close() error {
|
||||
|
||||
func (w *wrapperRewind) Rewind() {
|
||||
w.mutex.Lock()
|
||||
w.rewinded = true
|
||||
w.activeReader = io.MultiReader(&w.buf, w.parent)
|
||||
w.mutex.Unlock()
|
||||
}
|
||||
|
||||
func NewRewind(parent conntypes.StreamReadWriteCloser) ReadWriteCloseRewinder {
|
||||
return &wrapperRewind{
|
||||
rv := &wrapperRewind{
|
||||
parent: parent,
|
||||
}
|
||||
rv.activeReader = io.TeeReader(parent, &rv.buf)
|
||||
|
||||
return rv
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user