-
Notifications
You must be signed in to change notification settings - Fork 277
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #202 from xinkonglili/weilili
fix(broker):Added windows pipe socket communication, compatible with other systems #199
- Loading branch information
Showing
7 changed files
with
103 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package broker | ||
|
||
import ( | ||
"fmt" | ||
) | ||
|
||
// StartPipeSocketListening We use the open source npipe library | ||
// to jump over pipe communication in mac | ||
func (b *Broker) StartPipeSocketListening(pipeName string, usePipe bool) { | ||
fmt.Println("macos system") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package broker | ||
|
||
// StartPipeSocketListening We use the open source npipe library to | ||
// jump over pipe communication in linux | ||
func (b *Broker) StartPipeSocketListening(pipeName string, usePipe bool) { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package broker | ||
|
||
import ( | ||
"fmt" | ||
"github.com/natefinch/npipe" | ||
"go.uber.org/zap" | ||
"net" | ||
"time" | ||
) | ||
|
||
// StartPipeSocketListening We use the open source npipe library to support pipe communication in windows | ||
func (b *Broker) StartPipeSocketListening(pipeName string, usePipe bool) { | ||
var err error | ||
var ln *npipe.PipeListener | ||
|
||
for { | ||
if usePipe { | ||
fmt.Println(pipeName) | ||
ln, err = npipe.Listen(pipeName) | ||
log.Info("Start Listening client on ", zap.String("pipeName", pipeName)) | ||
} | ||
if err == nil { | ||
break // successfully listening | ||
} | ||
log.Error("Error listening on ", zap.Error(err)) | ||
time.Sleep(1 * time.Second) | ||
} | ||
|
||
tmpDelay := 10 * ACCEPT_MIN_SLEEP | ||
|
||
for { | ||
conn, err := ln.Accept() | ||
if err != nil { | ||
if ne, ok := err.(net.Error); ok && ne.Temporary() { | ||
log.Error( | ||
"Temporary Client Accept Error(%v), sleeping %dms", | ||
zap.Error(ne), | ||
zap.Duration("sleeping", tmpDelay/time.Millisecond), | ||
) | ||
|
||
time.Sleep(tmpDelay) | ||
tmpDelay *= 2 | ||
if tmpDelay > ACCEPT_MAX_SLEEP { | ||
tmpDelay = ACCEPT_MAX_SLEEP | ||
} | ||
} else { | ||
log.Error("Accept error", zap.Error(err)) | ||
} | ||
continue | ||
} | ||
|
||
tmpDelay = ACCEPT_MIN_SLEEP | ||
go func() { | ||
err := b.handleConnection(CLIENT, conn) | ||
fmt.Println("handleConnection,", err) | ||
if err != nil { | ||
conn.Close() | ||
} | ||
}() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters