This repository has been archived by the owner on May 12, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 373
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #259 from bergwolf/sandbox_api_2
add sandbox process operation relay API support
- Loading branch information
Showing
13 changed files
with
690 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
// Copyright (c) 2018 HyperHQ Inc. | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
|
||
package virtcontainers | ||
|
||
import ( | ||
"errors" | ||
"io" | ||
) | ||
|
||
type iostream struct { | ||
sandbox *Sandbox | ||
container *Container | ||
process string | ||
closed bool | ||
} | ||
|
||
// io.WriteCloser | ||
type stdinStream struct { | ||
*iostream | ||
} | ||
|
||
// io.Reader | ||
type stdoutStream struct { | ||
*iostream | ||
} | ||
|
||
// io.Reader | ||
type stderrStream struct { | ||
*iostream | ||
} | ||
|
||
func newIOStream(s *Sandbox, c *Container, proc string) *iostream { | ||
return &iostream{ | ||
sandbox: s, | ||
container: c, | ||
process: proc, | ||
closed: false, // needed to workaround buggy structcheck | ||
} | ||
} | ||
|
||
func (s *iostream) stdin() io.WriteCloser { | ||
return &stdinStream{s} | ||
} | ||
|
||
func (s *iostream) stdout() io.Reader { | ||
return &stdoutStream{s} | ||
} | ||
|
||
func (s *iostream) stderr() io.Reader { | ||
return &stderrStream{s} | ||
} | ||
|
||
func (s *stdinStream) Write(data []byte) (n int, err error) { | ||
if s.closed { | ||
return 0, errors.New("stream closed") | ||
} | ||
|
||
return s.sandbox.agent.writeProcessStdin(s.container, s.process, data) | ||
} | ||
|
||
func (s *stdinStream) Close() error { | ||
if s.closed { | ||
return errors.New("stream closed") | ||
} | ||
|
||
err := s.sandbox.agent.closeProcessStdin(s.container, s.process) | ||
if err == nil { | ||
s.closed = true | ||
} | ||
|
||
return err | ||
} | ||
|
||
func (s *stdoutStream) Read(data []byte) (n int, err error) { | ||
if s.closed { | ||
return 0, errors.New("stream closed") | ||
} | ||
|
||
return s.sandbox.agent.readProcessStdout(s.container, s.process, data) | ||
} | ||
|
||
func (s *stderrStream) Read(data []byte) (n int, err error) { | ||
if s.closed { | ||
return 0, errors.New("stream closed") | ||
} | ||
|
||
return s.sandbox.agent.readProcessStderr(s.container, s.process, data) | ||
} |
Oops, something went wrong.