本文整理汇总了Golang中github.com/lxc/lxd/shared.WebsocketMirror函数的典型用法代码示例。如果您正苦于以下问题:Golang WebsocketMirror函数的具体用法?Golang WebsocketMirror怎么用?Golang WebsocketMirror使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了WebsocketMirror函数的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: rsyncWebsocket
func rsyncWebsocket(cmd *exec.Cmd, conn *websocket.Conn) error {
stdin, err := cmd.StdinPipe()
if err != nil {
return err
}
stdout, err := cmd.StdoutPipe()
if err != nil {
return err
}
stderr, err := cmd.StderrPipe()
if err != nil {
return err
}
if err := cmd.Start(); err != nil {
return err
}
shared.WebsocketMirror(conn, stdin, stdout)
data, err2 := ioutil.ReadAll(stderr)
if err2 != nil {
shared.Debugf("error reading rsync stderr: %s", err2)
return err2
}
shared.Debugf("Stderr from rsync: %s", data)
err = cmd.Wait()
if err != nil {
shared.Debugf("rsync recv error %s: %s", err, string(data))
}
return err
}
示例2: RsyncSend
// RsyncSend sets up the sending half of an rsync, to recursively send the
// directory pointed to by path over the websocket.
func RsyncSend(path string, conn *websocket.Conn) error {
cmd, dataSocket, stderr, err := rsyncSendSetup(path)
if dataSocket != nil {
defer dataSocket.Close()
}
if err != nil {
return err
}
readDone, writeDone := shared.WebsocketMirror(conn, dataSocket, dataSocket)
output, err := ioutil.ReadAll(stderr)
if err != nil {
shared.LogDebugf("problem reading rsync stderr %s", err)
}
err = cmd.Wait()
if err != nil {
shared.LogDebugf("problem with rsync send of %s: %s: %s", path, err, string(output))
}
<-readDone
<-writeDone
return err
}
示例3: RsyncSend
// RsyncSend sets up the sending half of an rsync, to recursively send the
// directory pointed to by path over the websocket.
func RsyncSend(path string, conn *websocket.Conn) error {
cmd, dataSocket, err := rsyncSendSetup(path)
if dataSocket != nil {
defer dataSocket.Close()
}
if err != nil {
return err
}
shared.WebsocketMirror(conn, dataSocket, dataSocket)
return cmd.Wait()
}
示例4: RsyncRecv
// RsyncRecv sets up the receiving half of the websocket to rsync (the other
// half set up by RsyncSend), putting the contents in the directory specified
// by path.
func RsyncRecv(path string, conn *websocket.Conn, writeWrapper func(io.WriteCloser) io.WriteCloser) error {
cmd := exec.Command("rsync",
"--server",
"-vlogDtpre.iLsfx",
"--numeric-ids",
"--devices",
"--partial",
".",
path)
stdin, err := cmd.StdinPipe()
if err != nil {
return err
}
stdout, err := cmd.StdoutPipe()
if err != nil {
return err
}
stderr, err := cmd.StderrPipe()
if err != nil {
return err
}
if err := cmd.Start(); err != nil {
return err
}
writePipe := io.WriteCloser(stdin)
if writeWrapper != nil {
writePipe = writeWrapper(stdin)
}
readDone, writeDone := shared.WebsocketMirror(conn, writePipe, stdout)
data, err2 := ioutil.ReadAll(stderr)
if err2 != nil {
shared.LogDebugf("error reading rsync stderr: %s", err2)
return err2
}
err = cmd.Wait()
if err != nil {
shared.LogDebugf("rsync recv error for path %s: %s: %s", path, err, string(data))
}
<-readDone
<-writeDone
return err
}
示例5: rsyncWebsocket
func rsyncWebsocket(cmd *exec.Cmd, conn *websocket.Conn) error {
stdin, err := cmd.StdinPipe()
if err != nil {
return err
}
stdout, err := cmd.StdoutPipe()
if err != nil {
return err
}
if err := cmd.Start(); err != nil {
return err
}
shared.WebsocketMirror(conn, stdin, stdout)
return cmd.Wait()
}
示例6: RsyncSend
// RsyncSend sets up the sending half of an rsync, to recursively send the
// directory pointed to by path over the websocket.
func RsyncSend(path string, conn *websocket.Conn) error {
cmd, dataSocket, stderr, err := rsyncSendSetup(path)
if dataSocket != nil {
defer dataSocket.Close()
}
if err != nil {
return err
}
shared.WebsocketMirror(conn, dataSocket, dataSocket)
output, err := ioutil.ReadAll(stderr)
if err != nil {
shared.Debugf("problem reading rsync stderr %s", err)
}
if err := cmd.Wait(); err != nil {
shared.Debugf("problem with rsync send %s: %s", err, string(output))
}
return err
}
示例7: rsyncWebsocket
func rsyncWebsocket(path string, cmd *exec.Cmd, conn *websocket.Conn) error {
stdin, err := cmd.StdinPipe()
if err != nil {
return err
}
stdout, err := cmd.StdoutPipe()
if err != nil {
return err
}
stderr, err := cmd.StderrPipe()
if err != nil {
return err
}
if err := cmd.Start(); err != nil {
return err
}
readDone, writeDone := shared.WebsocketMirror(conn, stdin, stdout)
data, err2 := ioutil.ReadAll(stderr)
if err2 != nil {
shared.LogDebugf("error reading rsync stderr: %s", err2)
return err2
}
err = cmd.Wait()
if err != nil {
shared.LogDebugf("rsync recv error for path %s: %s: %s", path, err, string(data))
}
<-readDone
<-writeDone
return err
}
示例8: Do
func (s *execWs) Do(id string) shared.OperationResult {
<-s.allConnected
var err error
var ttys []*os.File
var ptys []*os.File
if s.interactive {
ttys = make([]*os.File, 1)
ptys = make([]*os.File, 1)
ptys[0], ttys[0], err = shared.OpenPty(s.rootUid, s.rootGid)
s.options.StdinFd = ttys[0].Fd()
s.options.StdoutFd = ttys[0].Fd()
s.options.StderrFd = ttys[0].Fd()
} else {
ttys = make([]*os.File, 3)
ptys = make([]*os.File, 3)
for i := 0; i < len(ttys); i++ {
ptys[i], ttys[i], err = shared.Pipe()
if err != nil {
return shared.OperationError(err)
}
}
s.options.StdinFd = ptys[0].Fd()
s.options.StdoutFd = ttys[1].Fd()
s.options.StderrFd = ttys[2].Fd()
}
controlExit := make(chan bool)
var wgEOF sync.WaitGroup
if s.interactive {
wgEOF.Add(1)
go func() {
select {
case <-s.controlConnected:
break
case <-controlExit:
return
}
for {
mt, r, err := s.conns[-1].NextReader()
if mt == websocket.CloseMessage {
break
}
if err != nil {
shared.Debugf("Got error getting next reader %s", err)
break
}
buf, err := ioutil.ReadAll(r)
if err != nil {
shared.Debugf("Failed to read message %s", err)
break
}
command := shared.ContainerExecControl{}
if err := json.Unmarshal(buf, &command); err != nil {
shared.Debugf("Failed to unmarshal control socket command: %s", err)
continue
}
if command.Command == "window-resize" {
winchWidth, err := strconv.Atoi(command.Args["width"])
if err != nil {
shared.Debugf("Unable to extract window width: %s", err)
continue
}
winchHeight, err := strconv.Atoi(command.Args["height"])
if err != nil {
shared.Debugf("Unable to extract window height: %s", err)
continue
}
err = shared.SetSize(int(ptys[0].Fd()), winchWidth, winchHeight)
if err != nil {
shared.Debugf("Failed to set window size to: %dx%d", winchWidth, winchHeight)
continue
}
}
if err != nil {
shared.Debugf("Got error writing to writer %s", err)
break
}
}
}()
go func() {
<-shared.WebsocketMirror(s.conns[0], ptys[0], ptys[0])
wgEOF.Done()
}()
} else {
wgEOF.Add(len(ttys) - 1)
for i := 0; i < len(ttys); i++ {
go func(i int) {
//.........这里部分代码省略.........
示例9: Do
func (s *execWs) Do(op *operation) error {
<-s.allConnected
var err error
var ttys []*os.File
var ptys []*os.File
var stdin *os.File
var stdout *os.File
var stderr *os.File
if s.interactive {
ttys = make([]*os.File, 1)
ptys = make([]*os.File, 1)
ptys[0], ttys[0], err = shared.OpenPty(s.rootUid, s.rootGid)
stdin = ttys[0]
stdout = ttys[0]
stderr = ttys[0]
if s.width > 0 && s.height > 0 {
shared.SetSize(int(ptys[0].Fd()), s.width, s.height)
}
} else {
ttys = make([]*os.File, 3)
ptys = make([]*os.File, 3)
for i := 0; i < len(ttys); i++ {
ptys[i], ttys[i], err = shared.Pipe()
if err != nil {
return err
}
}
stdin = ptys[0]
stdout = ttys[1]
stderr = ttys[2]
}
controlExit := make(chan bool)
var wgEOF sync.WaitGroup
if s.interactive {
wgEOF.Add(1)
go func() {
select {
case <-s.controlConnected:
break
case <-controlExit:
return
}
for {
mt, r, err := s.conns[-1].NextReader()
if mt == websocket.CloseMessage {
break
}
if err != nil {
shared.Debugf("Got error getting next reader %s", err)
break
}
buf, err := ioutil.ReadAll(r)
if err != nil {
shared.Debugf("Failed to read message %s", err)
break
}
command := shared.ContainerExecControl{}
if err := json.Unmarshal(buf, &command); err != nil {
shared.Debugf("Failed to unmarshal control socket command: %s", err)
continue
}
if command.Command == "window-resize" {
winchWidth, err := strconv.Atoi(command.Args["width"])
if err != nil {
shared.Debugf("Unable to extract window width: %s", err)
continue
}
winchHeight, err := strconv.Atoi(command.Args["height"])
if err != nil {
shared.Debugf("Unable to extract window height: %s", err)
continue
}
err = shared.SetSize(int(ptys[0].Fd()), winchWidth, winchHeight)
if err != nil {
shared.Debugf("Failed to set window size to: %dx%d", winchWidth, winchHeight)
continue
}
}
}
}()
go func() {
readDone, writeDone := shared.WebsocketMirror(s.conns[0], ptys[0], ptys[0])
<-readDone
//.........这里部分代码省略.........
示例10: Do
//.........这里部分代码省略.........
if err := json.Unmarshal(buf, &command); err != nil {
shared.LogDebugf("Failed to unmarshal control socket command: %s", err)
continue
}
if command.Command == "window-resize" {
winchWidth, err := strconv.Atoi(command.Args["width"])
if err != nil {
shared.LogDebugf("Unable to extract window width: %s", err)
continue
}
winchHeight, err := strconv.Atoi(command.Args["height"])
if err != nil {
shared.LogDebugf("Unable to extract window height: %s", err)
continue
}
err = shared.SetSize(int(ptys[0].Fd()), winchWidth, winchHeight)
if err != nil {
shared.LogDebugf("Failed to set window size to: %dx%d", winchWidth, winchHeight)
continue
}
} else if command.Command == "signal" {
if err := syscall.Kill(receivedPid, command.Signal); err != nil {
shared.LogDebugf("Failed forwarding signal '%s' to PID %d.", command.Signal, receivedPid)
continue
}
shared.LogDebugf("Forwarded signal '%s' to PID %d.", command.Signal, receivedPid)
}
}
}()
go func() {
readDone, writeDone := shared.WebsocketMirror(s.conns[0], ptys[0], ptys[0])
<-readDone
<-writeDone
s.conns[0].Close()
wgEOF.Done()
}()
} else {
wgEOF.Add(len(ttys) - 1)
for i := 0; i < len(ttys); i++ {
go func(i int) {
if i == 0 {
<-shared.WebsocketRecvStream(ttys[i], s.conns[i])
ttys[i].Close()
} else {
<-shared.WebsocketSendStream(s.conns[i], ptys[i], -1)
ptys[i].Close()
wgEOF.Done()
}
}(i)
}
}
finisher := func(cmdResult int, cmdErr error) error {
for _, tty := range ttys {
tty.Close()
}
if s.conns[-1] == nil {
if s.interactive {
controlExit <- true
}
} else {
s.conns[-1].Close()
示例11: Do
//.........这里部分代码省略.........
if err := json.Unmarshal(buf, &command); err != nil {
shared.LogDebugf("Failed to unmarshal control socket command: %s", err)
continue
}
if command.Command == "window-resize" {
winchWidth, err := strconv.Atoi(command.Args["width"])
if err != nil {
shared.LogDebugf("Unable to extract window width: %s", err)
continue
}
winchHeight, err := strconv.Atoi(command.Args["height"])
if err != nil {
shared.LogDebugf("Unable to extract window height: %s", err)
continue
}
err = shared.SetSize(int(ptys[0].Fd()), winchWidth, winchHeight)
if err != nil {
shared.LogDebugf("Failed to set window size to: %dx%d", winchWidth, winchHeight)
continue
}
} else if command.Command == "signal" {
if err := syscall.Kill(receivedPid, command.Signal); err != nil {
shared.LogDebugf("Failed forwarding signal '%s' to PID %d.", command.Signal, receivedPid)
continue
}
shared.LogDebugf("Forwarded signal '%s' to PID %d.", command.Signal, receivedPid)
}
}
}()
go func() {
readDone, writeDone := shared.WebsocketMirror(s.conns[0], ptys[0], ptys[0])
<-readDone
<-writeDone
s.conns[0].Close()
wgEOF.Done()
}()
} else {
wgEOF.Add(len(ttys) - 1)
for i := 0; i < len(ttys); i++ {
go func(i int) {
if i == 0 {
<-shared.WebsocketRecvStream(ttys[i], s.conns[i])
ttys[i].Close()
} else {
<-shared.WebsocketSendStream(s.conns[i], ptys[i], -1)
ptys[i].Close()
wgEOF.Done()
}
}(i)
}
}
finisher := func(cmdResult int, cmdErr error) error {
for _, tty := range ttys {
tty.Close()
}
if s.conns[-1] == nil {
if s.interactive {
controlExit <- true
}
} else {
s.conns[-1].Close()