Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Read & Add Reconnect Loop #9

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 14 additions & 9 deletions client_all.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package ipc
import (
"bufio"
"errors"
"io"
"strings"
"time"
)
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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
Expand Down
7 changes: 5 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -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
)
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -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=
Expand Down
3 changes: 2 additions & 1 deletion server_all.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package ipc
import (
"bufio"
"errors"
"io"
"time"
)

Expand Down Expand Up @@ -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 {
Expand Down