mirror of
https://github.com/criyle/go-judge.git
synced 2025-11-04 14:50:02 +08:00
- increase default tmpfs size to 128M - add /config to get file store path - remove memory only file store close #20
55 lines
928 B
Go
55 lines
928 B
Go
package envexec
|
|
|
|
import (
|
|
"io"
|
|
"os"
|
|
)
|
|
|
|
type pipeBuffer struct {
|
|
W *os.File
|
|
Buffer *os.File
|
|
Done <-chan struct{}
|
|
Limit Size
|
|
}
|
|
|
|
type pipeCollector struct {
|
|
done <-chan struct{}
|
|
buffer *os.File
|
|
limit Size
|
|
name string
|
|
}
|
|
|
|
func newPipe(writer io.Writer, limit Size) (<-chan struct{}, *os.File, error) {
|
|
r, w, err := os.Pipe()
|
|
if err != nil {
|
|
return nil, nil, err
|
|
}
|
|
done := make(chan struct{})
|
|
go func() {
|
|
io.CopyN(writer, r, int64(limit))
|
|
close(done)
|
|
// ensure no blocking / SIGPIPE on the other end
|
|
io.Copy(io.Discard, r)
|
|
r.Close()
|
|
}()
|
|
return done, w, nil
|
|
}
|
|
|
|
func newPipeBuffer(limit Size, newFile NewStoreFile) (*pipeBuffer, error) {
|
|
buffer, err := newFile()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
done, w, err := newPipe(buffer, limit+1)
|
|
if err != nil {
|
|
buffer.Close()
|
|
return nil, err
|
|
}
|
|
return &pipeBuffer{
|
|
W: w,
|
|
Buffer: buffer,
|
|
Done: done,
|
|
Limit: limit,
|
|
}, nil
|
|
}
|