introduced Ping() function
This commit is contained in:
14
commands.go
14
commands.go
@ -2,7 +2,6 @@ package mpvipc
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"net"
|
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -30,15 +29,18 @@ func Quit(socket string) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func Ping(socket string) bool {
|
||||||
|
_, err := GetPID(socket)
|
||||||
|
return err == nil
|
||||||
|
}
|
||||||
|
|
||||||
func IsReady(ctx context.Context, socket string) <-chan bool {
|
func IsReady(ctx context.Context, socket string) <-chan bool {
|
||||||
out := make(chan bool, 1)
|
out := make(chan bool, 1)
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
defer close(out)
|
defer close(out)
|
||||||
|
|
||||||
conn, err := net.Dial("unix", socket)
|
if Ping(socket) {
|
||||||
if err == nil {
|
|
||||||
defer conn.Close()
|
|
||||||
out <- true
|
out <- true
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -49,9 +51,7 @@ func IsReady(ctx context.Context, socket string) <-chan bool {
|
|||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case <-ticker.C:
|
case <-ticker.C:
|
||||||
conn, err := net.Dial("unix", socket)
|
if Ping(socket) {
|
||||||
if err == nil {
|
|
||||||
defer conn.Close()
|
|
||||||
out <- true
|
out <- true
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user