SSHTunnel/CreateLocalEndPoint.go
Thorsten Sommer 6ae3b46fc1 Retry, Refactoring & Doc
+ Refactoring of some functions
+ Added the retrying of all three connections
+ Added the documentation to the code
+ Improved the error messages
2015-01-02 18:01:52 +01:00

36 lines
864 B
Go

package main
import (
"log"
"net"
"time"
)
func createLocalEndPoint() (localListener net.Listener) {
// Loop for the necessary retries
for {
// Try to create the local end-point
if localListenerObj, err := net.Listen(`tcp`, localAddrString); err != nil {
// It was not able to create the end-point:
currentRetriesLocal++
log.Printf("Was not able to create the local end-point %s: %s\n", localAddrString, err.Error())
// Is another retry possible?
if currentRetriesLocal < maxRetriesLocal {
log.Println(`Retry...`)
time.Sleep(1 * time.Second)
} else {
log.Fatalln(`No more retries for the local end-point: ` + localAddrString) // => Exit
}
} else {
// Success!
log.Println(`Listen to local address ` + localAddrString)
localListener = localListenerObj
return
}
}
}