diff --git a/client_all.go b/client_all.go index 66313ab..cec1c00 100755 --- a/client_all.go +++ b/client_all.go @@ -3,6 +3,7 @@ package ipc import ( "bufio" "errors" + "io" "strings" "time" ) @@ -124,7 +125,7 @@ func (cc *Client) read() { func (cc *Client) readData(buff []byte) bool { - _, err := cc.conn.Read(buff) + _, err := io.ReadFull(cc.conn, buff) if err != nil { if strings.Contains(err.Error(), "EOF") { // the connection has been closed by the client. cc.conn.Close() @@ -156,15 +157,19 @@ func (cc *Client) reconnect() { cc.status = ReConnecting cc.recieved <- &Message{Status: cc.status.String(), MsgType: -1} - err := cc.dial() // connect to the pipe - if err != nil { - if err.Error() == "Timed out trying to connect" { - cc.status = Timeout - cc.recieved <- &Message{Status: cc.status.String(), MsgType: -1} - cc.recieved <- &Message{err: errors.New("Timed out trying to re-connect"), MsgType: -2} +loop: + for { + err := cc.dial() // connect to the pipe + if err != nil { + if err.Error() == "Timed out trying to connect" { + cc.status = Timeout + cc.recieved <- &Message{Status: cc.status.String(), MsgType: -1} + cc.recieved <- &Message{err: errors.New("Timed out trying to re-connect"), MsgType: -2} + } + } else { + break loop } - - return + time.Sleep(time.Second * 5) //sleep for 5 sec } cc.status = Connected diff --git a/go.mod b/go.mod index c9465da..c3c5715 100644 --- a/go.mod +++ b/go.mod @@ -1,5 +1,8 @@ -module github.com/james-barrow/golang-ipc +module github.com/thebradleysanders/golang-ipc go 1.15 -require github.com/Microsoft/go-winio v0.4.16 +require ( + github.com/Microsoft/go-winio v0.4.16 + github.com/james-barrow/golang-ipc v1.0.0 +) diff --git a/go.sum b/go.sum index 284f8a4..9470a7b 100644 --- a/go.sum +++ b/go.sum @@ -1,6 +1,8 @@ github.com/Microsoft/go-winio v0.4.16 h1:FtSW/jqD+l4ba5iPBj9CODVtgfYAD8w2wS923g/cFDk= github.com/Microsoft/go-winio v0.4.16/go.mod h1:XB6nPKklQyQ7GC9LdcBEcBl8PF76WugXOPRXwdLnMv0= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/james-barrow/golang-ipc v1.0.0 h1:ZOZtmgQMC8WE4pm1pvTQQzeo+G+FGUt3PsJiDSPdKPA= +github.com/james-barrow/golang-ipc v1.0.0/go.mod h1:M3eGiVVY7bdtqyWT+gtbIqji7CqHi3PKJHSPl2pP40c= github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= diff --git a/server_all.go b/server_all.go index c0b13a2..3f9b3b2 100755 --- a/server_all.go +++ b/server_all.go @@ -3,6 +3,7 @@ package ipc import ( "bufio" "errors" + "io" "time" ) @@ -179,7 +180,7 @@ func (sc *Server) read() { func (sc *Server) readData(buff []byte) bool { - _, err := sc.conn.Read(buff) + _, err := io.ReadFull(sc.conn, buff) if err != nil { if sc.status == Closing {