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