Advertisement
Guest User

Untitled

a guest
Aug 31st, 2015
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.83 KB | None | 0 0
  1. ```
  2. func waitPts(ctx *VmContext) {
  3. conn, err := UnixSocketConnect(ctx.TtySockName)
  4. if err != nil {
  5. glog.Error("Cannot connect to tty socket ", err.Error())
  6. ctx.Hub <- &InitFailedEvent{
  7. Reason: "Cannot connect to tty socket " + err.Error(),
  8. }
  9. return
  10. }
  11.  
  12. glog.V(1).Info("tty socket connected")
  13.  
  14. go waitTtyMessage(ctx, conn.(*net.UnixConn))
  15. for {
  16. res, err := readTtyMessage(conn.(*net.UnixConn))
  17. if err != nil {
  18. glog.V(1).Info("tty socket closed, quit the reading goroutine ", err.Error())
  19. ctx.Hub <- &Interrupted{Reason: "tty socket failed " + err.Error()}
  20. close(ctx.ptys.channel)
  21. return
  22. }
  23. if ta, ok := ctx.ptys.ttys[res.session]; ok {
  24. if len(res.message) == 0 {
  25. glog.V(1).Infof("session %d closed by peer, close pty", res.session)
  26. ctx.ptys.Close(ctx, res.session)
  27. } else {
  28. for _, tty := range ta.attachments {
  29. if tty.Stdout != nil {
  30. _, err := tty.Stdout.Write(res.message)
  31. if err != nil {
  32. glog.V(1).Infof("fail to write session %d, close pty attachment", res.session)
  33. ctx.ptys.Detach(ctx, res.session, tty)
  34. }
  35. }
  36. }
  37. }
  38. }
  39. }
  40. }
  41. ```
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement