MCPcopy
hub / github.com/1Panel-dev/KubePi / Run

Method Run

thirdparty/gotty/webtty/webtty.go:69–153  ·  view source on GitHub ↗

Run starts the main process of the WebTTY. This method blocks until the context is canceled. Note that the master and slave are left intact even after the context is canceled. Closing them is caller's responsibility. If the connection to one end gets closed, returns ErrSlaveClosed or ErrMasterClosed

(ctx context.Context)

Source from the content-addressed store, hash-verified

67// responsibility.
68// If the connection to one end gets closed, returns ErrSlaveClosed or ErrMasterClosed.
69func (wt *WebTTY) Run(ctx context.Context) error {
70 err := wt.sendInitializeMessage()
71 if err != nil {
72 return errors.Wrapf(err, "failed to send initializing message")
73 }
74
75 errs := make(chan error, 3)
76
77 slaveBuffer := make([]byte, wt.bufferSize)
78 go func() {
79 errs <- func() error {
80 defer func() {
81 if e := recover(); e != nil {
82 }
83 }()
84 for {
85 if slaveBuffer == nil {
86 return ErrSlaveClosed
87 }
88 n, err := wt.slave.Read(slaveBuffer)
89 if err != nil {
90 return ErrSlaveClosed
91 }
92 err = wt.handleSlaveReadEvent(slaveBuffer[:n])
93 if err != nil {
94 return err
95 }
96 }
97 }()
98 }()
99 masterBuffer := make([]byte, wt.bufferSize)
100 go func() {
101 errs <- func() error {
102 defer func() {
103 if e := recover(); e != nil {
104 }
105 }()
106 for {
107 if masterBuffer == nil {
108 return ErrMasterClosed
109 }
110 n, err := wt.masterConn.Read(masterBuffer)
111 if err != nil {
112 return ErrMasterClosed
113 }
114 err = wt.handleMasterReadEvent(masterBuffer[:n])
115 if err != nil {
116 return err
117 }
118 }
119 }()
120 }()
121
122 go func() {
123 errs <- func() error {
124 lostPingTimeout := time.Duration(180) * time.Second
125 seconds, _err := strconv.Atoi(os.Getenv("LOST_PING_TIMEOUT_SECONDS"))
126 if _err != nil && seconds > 30 {

Callers 13

mainFunction · 0.45
TestWriteFromPTYFunction · 0.45
TestWriteFromConnFunction · 0.45
ListMethod · 0.45
GetDetailMethod · 0.45
InstallMethod · 0.45
UpgradeMethod · 0.45
UninstallMethod · 0.45
TestNormalizeLoginIPFunction · 0.45
ListenFunction · 0.45
startTtyMethod · 0.45

Calls 5

sendInitializeMessageMethod · 0.95
handleSlaveReadEventMethod · 0.95
handleMasterReadEventMethod · 0.95
AddMethod · 0.65
ReadMethod · 0.45

Tested by 4

TestWriteFromPTYFunction · 0.36
TestWriteFromConnFunction · 0.36
TestNormalizeLoginIPFunction · 0.36