Skip to content

Commit

Permalink
Sockets: make Go workers log the same messages Node ones do on init
Browse files Browse the repository at this point in the history
  • Loading branch information
Morfent committed May 28, 2017
1 parent 6f016e5 commit ba5a655
Showing 1 changed file with 33 additions and 28 deletions.
61 changes: 33 additions & 28 deletions sockets/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ func main() {
conn.Listen(smux)

// Set up server routing.
// FIXME: this doesn't route correctly on Windows. Fix it!!
r := mux.NewRouter()

staticDir, _ := filepath.Abs("./static")
Expand Down Expand Up @@ -67,6 +66,38 @@ func main() {
http.Redirect(w, r, "/static/404.html", http.StatusSeeOther)
})

// Begin serving over HTTP.
go func(ba string, port string) {
srv := &http.Server{
Handler: r,
Addr: ba + port}

// Again, IPv6 is verboten until PS can support it.
addr, err := net.ResolveTCPAddr("tcp4", ba+port)
if err != nil {
log.Fatalf("Sockets: failed to resolve the TCP address of the parent's server: %v", err)
}

ln, err := net.ListenTCP("tcp4", addr)
defer ln.Close()
if err != nil {
log.Fatalf("Sockets: failed to listen on %v over HTTP", srv.Addr)
}

fmt.Printf("Go workers now listening on %v%v\n", ba, port)

if ba == "0.0.0.0" {
fmt.Printf("Test your server at http://%v%v/\n", "localhost", port)
} else {
fmt.Printf("Test your server at http://%v%v/\n", ba, port)
}

// This will block indefinitely until http.Serve returns an error.
if err = http.Serve(ln, r); err != nil {
log.Fatalf("Sockets: HTTP server failed with error: %v", err)
}
}(config.BindAddress, config.Port)

// Begin serving over HTTPS if configured to do so.
if config.SSL.Options.Cert != "" && config.SSL.Options.Key != "" {
go func(ba string, port string, cert string, key string) {
Expand All @@ -88,7 +119,7 @@ func main() {
log.Fatalf("Sockets: failed to listen on %v over HTTPS", srv.Addr)
}

fmt.Printf("Sockets: now serving on https://%v%v/\n", ba, port)
fmt.Printf("Go workers now listening for SSL on port %v\n", port)

// This will block indefinitely until http.Serve returns an error.
if err := http.Serve(ln, r); err != nil {
Expand All @@ -97,32 +128,6 @@ func main() {
}(config.BindAddress, config.SSL.Port, config.SSL.Options.Cert, config.SSL.Options.Key)
}

// Begin serving over HTTP.
go func(ba string, port string) {
srv := &http.Server{
Handler: r,
Addr: ba + port}

// Again, IPv6 is verboten until PS can support it.
addr, err := net.ResolveTCPAddr("tcp4", ba+port)
if err != nil {
log.Fatalf("Sockets: failed to resolve the TCP address of the parent's server: %v", err)
}

ln, err := net.ListenTCP("tcp4", addr)
defer ln.Close()
if err != nil {
log.Fatalf("Sockets: failed to listen on %v over HTTP", srv.Addr)
}

fmt.Printf("Sockets: now serving on http://%v%v/\n", ba, port)

// This will block indefinitely until http.Serve returns an error.
if err = http.Serve(ln, r); err != nil {
log.Fatalf("Sockets: HTTP server failed with error: %v", err)
}
}(config.BindAddress, config.Port)

// Finally, spawn workers.to pipe messages received at the multiplexer or
// IPC connection to each other concurrently.
master := sockets.NewMaster(config.Workers)
Expand Down

0 comments on commit ba5a655

Please sign in to comment.