Fix ping2

This commit is contained in:
Super User
2024-05-08 15:42:47 +03:00
parent e03e5e7c47
commit deca713acc
3 changed files with 20 additions and 41 deletions

View File

@@ -12,7 +12,7 @@
type cmpWbsCliStruct struct {
W http.ResponseWriter
Connect *websocket.Conn
Mutex sync.Mutex
Mutex *sync.Mutex
HostPort string
}
@@ -51,7 +51,7 @@
var cmpWbsCli cmpWbsCliStruct = cmpWbsCliStruct{
w,
conn,
Mutex,
&Mutex,
HostPort,
}
@@ -132,14 +132,14 @@
func (app *App) HttpWebSockSendRawTo(cmpWbsCli cmpWbsCliStruct, raw map[string]interface{}) {
var err error
app.Log("LOCK")
// app.Log("LOCK")
cmpWbsCli.Mutex.Lock()
defer cmpWbsCli.Mutex.Unlock()
err = cmpWbsCli.Connect.WriteJSON(raw)
cmpWbsCli.Mutex.Unlock()
if err != nil {
app.Log(err)
return

View File

@@ -78,31 +78,6 @@
}, nil
}
func (app *App) copyAndCapture(r io.Reader, strWin string) ([]byte, error) {
var out []byte
buf := make([]byte, 1024, 1024)
for {
n, err := r.Read(buf[:])
if n > 0 {
d := buf[:n]
out = append(out, d...)
str := strings.Trim(string(d), "\n\r")
app.Log("Std: %s", str)
app.Ping2SendStr(str)
}
if err != nil {
// Read returns io.EOF at the end of file, which is not an error for us
if err == io.EOF {
err = nil
}
return out, err
}
}
}
func (app *App) Ping2SendObj(obj map[string]interface{}) (error) {
if app.CliCur == nil {
app.Log("No cli")
@@ -113,14 +88,14 @@ func (app *App) copyAndCapture(r io.Reader, strWin string) ([]byte, error) {
return nil
}
/*
func (app *App) Ping2SendStr(str string) (error) {
return app.Ping2SendObj(map[string]interface{}{
"data" : "stdout",
"string": str,
})
}
*/
@@ -136,7 +111,11 @@ func (app *App) ping2Capture(r io.Reader, strWin string) ([]byte, error) {
app.Log("Std: %s", str)
app.Ping2SendStr(str)
app.Ping2SendObj(map[string]interface{}{
"data" : "stdout",
"win" : strWin,
"string": str,
})
}
if err != nil {
// Read returns io.EOF at the end of file, which is not an error for us

View File

@@ -285,7 +285,7 @@
if(!this.blobPing2Wind[w].nodeAddrList) {
this.blobPing2Wind[w].nodeAddrList = dcrt({
tag : "div",
style: "display:block; visibility:hidden; position:absolute; top:32px; left:110px; background-color:#222; overflow:auto; border:1px solid grey; padding:15px;",
style: "display:block; visibility:hidden; position:absolute; top:100px; left:30px; background-color:#222; overflow:auto; border:1px solid grey; padding:15px;",
parn : this.blobPing2Wind[w].nodeRoot
});
@@ -334,14 +334,14 @@
this.blobPing2Wind[w].nodeAddr = dcrt({
tag : "div",
style: "display:block; position:absolute; top:-2px; left:125px;",
style: "display:block; position:absolute; top:125px; left:1px;",
click: this.ping2Addr.bind(this, w),
html : "8.8.8.8"
});
this.blobPing2Wind[w].nodeHead = dcrt({
tag : "div",
style: "display:block; position:absolute; top:1px; height:32px; left:1px; right:1px; overflow:auto; border:0px solid red; padding:0;",
style: "display:block; position:absolute; top:1px; width:32px; /* height:32px; right:1px; */ left:1px; bottom:1px; overflow:auto; border:0px solid red; padding:0;",
parn : this.blobPing2Wind[w].nodeRoot,
child: [
{
@@ -352,19 +352,19 @@
},
{
tag : "div",
style: "display:block; position:absolute; top:0px; left:25px;",
style: "display:block; position:absolute; top:25px; left:1px;",
click: this.ping2Snip.bind(this, w, "stat"),
html : '<svg xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 -960 960 960" width="24px" fill="#e8eaed"><path d="M660-240v-480h80v480h-80Zm-440 0v-480l360 240-360 240Zm80-240Zm0 90 136-90-136-90v180Z"/></svg>'
},
{
tag : "div",
style: "display:block; position:absolute; top:0px; left:50px;",
style: "display:block; position:absolute; top:50px; left:1px;",
click: this.ping2Snip.bind(this, w, "stop"),
html : '<svg xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 -960 960 960" width="24px" fill="#e8eaed"><path d="M320-640v320-320Zm-80 400v-480h480v480H240Zm80-80h320v-320H320v320Z"/></svg>'
},
{
tag : "div",
style: "display:block; position:absolute; top:0px; left:100px;",
style: "display:block; position:absolute; top:100px; left:1px;",
click: this.ping2Addr.bind(this, w),
html : '<svg xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 -960 960 960" width="24px" fill="#e8eaed"><path d="M240-160q-33 0-56.5-23.5T160-240q0-33 23.5-56.5T240-320q33 0 56.5 23.5T320-240q0 33-23.5 56.5T240-160Zm240 0q-33 0-56.5-23.5T400-240q0-33 23.5-56.5T480-320q33 0 56.5 23.5T560-240q0 33-23.5 56.5T480-160Zm240 0q-33 0-56.5-23.5T640-240q0-33 23.5-56.5T720-320q33 0 56.5 23.5T800-240q0 33-23.5 56.5T720-160ZM240-400q-33 0-56.5-23.5T160-480q0-33 23.5-56.5T240-560q33 0 56.5 23.5T320-480q0 33-23.5 56.5T240-400Zm240 0q-33 0-56.5-23.5T400-480q0-33 23.5-56.5T480-560q33 0 56.5 23.5T560-480q0 33-23.5 56.5T480-400Zm240 0q-33 0-56.5-23.5T640-480q0-33 23.5-56.5T720-560q33 0 56.5 23.5T800-480q0 33-23.5 56.5T720-400ZM240-640q-33 0-56.5-23.5T160-720q0-33 23.5-56.5T240-800q33 0 56.5 23.5T320-720q0 33-23.5 56.5T240-640Zm240 0q-33 0-56.5-23.5T400-720q0-33 23.5-56.5T480-800q33 0 56.5 23.5T560-720q0 33-23.5 56.5T480-640Zm240 0q-33 0-56.5-23.5T640-720q0-33 23.5-56.5T720-800q33 0 56.5 23.5T800-720q0 33-23.5 56.5T720-640Z"/></svg>'
},
@@ -374,7 +374,7 @@
this.blobPing2Wind[w].nodeBody = dcrt({
tag : "div",
style: "display:block; position:absolute; top:26px; bottom:1px; left:1px; right:1px; overflow:auto; border:1px solid grey;",
style: "display:block; position:absolute; top:1px; bottom:1px; left:26px; right:1px; overflow:auto; border:1px solid grey;",
parn : this.blobPing2Wind[w].nodeRoot
});
@@ -454,7 +454,7 @@
return;
}
var w = 0;
var w = obj.win;
this.blobPing2Wind[w].list.push(dcrt({
tag : "pre",