Skip to content

Commit

Permalink
core/os/android/adb: Try port connection more frequently.
Browse files Browse the repository at this point in the history
Reduce worst-case latency.
  • Loading branch information
ben-clayton committed Sep 26, 2017
1 parent 691a884 commit d492248
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions core/os/android/adb/forward_and_connect.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ import (
)

const (
connectionAttempts = 30
reconnectDelay = time.Second
ErrServiceTimeout = fault.Const("Timeout connecting to service")
reconnectDelay = time.Millisecond * 100
connectionTimeout = time.Second * 30
ErrServiceTimeout = fault.Const("Timeout connecting to service")
)

// ForwardAndConnect forwards the local-abstract-socket las and connects to it.
Expand All @@ -54,7 +54,8 @@ func ForwardAndConnect(ctx context.Context, d Device, las string) (io.ReadCloser

app.AddCleanup(ctx, unforward)

for i := 0; i < connectionAttempts; i++ {
start := time.Now()
for time.Since(start) < connectionTimeout {
if sock, err := net.Dial("tcp", fmt.Sprintf("localhost:%v", port)); err == nil {
reader := bufio.NewReader(sock)
if _, err := reader.Peek(1); err == nil {
Expand All @@ -65,7 +66,6 @@ func ForwardAndConnect(ctx context.Context, d Device, las string) (io.ReadCloser

return readerCustomCloser{reader, close}, nil
}

sock.Close()
}
time.Sleep(reconnectDelay)
Expand Down

0 comments on commit d492248

Please sign in to comment.