Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Make sure we kill the launched process after the request is done.

Seems like we re-invented CGI
  • Loading branch information...
commit a5f9c9b499dc429f81af2f6f72260477c3348cb6 1 parent 6840292
Tobias Lütke authored December 30, 2011

Showing 1 changed file with 6 additions and 13 deletions. Show diff stats Hide diff stats

  1. 19  main.go
19  main.go
... ...
@@ -1,7 +1,6 @@
1 1
 package main
2 2
 
3 3
 import (
4  
-	"io"
5 4
 	"os"
6 5
 	"fmt"
7 6
 	"bufio"
@@ -14,17 +13,9 @@ import (
14 13
 	"strconv"
15 14
 )
16 15
 
17  
-var port *int = flag.Int("port", 3333, "port")
18  
-var executable *string = flag.String("executable", "server", "executable to launch. Must support -pXXXX for port assignment")
19  
-var compiler *string = flag.String("compiler", "make", "compiler to execute. make by default.")
20  
-
21  
-func error(client io.WriteCloser, s string) {
22  
-	log.Printf("Error: %s", s)
23  
-	client.Write([]byte("HTTP/1.0 500 Internal Error\n"))
24  
-	client.Write([]byte("Content-Type: text/plain\n"))
25  
-	client.Write([]byte("\n\n" + s + "\n"))
26  
-	client.Close()
27  
-}
  16
+var port *int = flag.Int("p", 3333, "port")
  17
+var executable *string = flag.String("e", "server", "executable to launch. Must support -pXXXX for port assignment")
  18
+var compiler *string = flag.String("c", "gb", "compiler to execute. gb by default.")
28 19
 
29 20
 func pipeRequestResponse(server, client net.Conn) os.Error {
30 21
 
@@ -72,7 +63,7 @@ func forward(client net.Conn) {
72 63
 		return
73 64
 	}
74 65
 
75  
-  client_port := *port+1024
  66
+  client_port := *port + 1024
76 67
 
77 68
 	cmd = exec.Command(*executable, "-p", strconv.Itoa(client_port))
78 69
 	err = cmd.Start()
@@ -82,6 +73,8 @@ func forward(client net.Conn) {
82 73
 		return
83 74
 	}
84 75
 
  76
+  defer cmd.Process.Kill()
  77
+
85 78
 	// 20 retries, ~= 10 secs of attempts
86 79
 	for i := 0; i < 50; i++ {
87 80
 		server, err := net.Dial("tcp", fmt.Sprintf("127.0.0.1:%d", client_port))

0 notes on commit a5f9c9b

Please sign in to comment.
Something went wrong with that request. Please try again.