fix runtime timeout
This commit is contained in:
parent
ccba493de1
commit
1c87615fdd
21
main.go
21
main.go
|
@ -11,7 +11,6 @@ import (
|
||||||
"log"
|
"log"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"net"
|
"net"
|
||||||
_ "net/http/pprof"
|
|
||||||
"os"
|
"os"
|
||||||
"runtime/pprof"
|
"runtime/pprof"
|
||||||
"time"
|
"time"
|
||||||
|
@ -24,7 +23,7 @@ var image_offsetx = flag.Int("xoffset", 0, "Offset of posted image from left bor
|
||||||
var image_offsety = flag.Int("yoffset", 0, "Offset of posted image from top border")
|
var image_offsety = flag.Int("yoffset", 0, "Offset of posted image from top border")
|
||||||
var connections = flag.Int("connections", 4, "Number of simultaneous connections. Each connection posts a subimage")
|
var connections = flag.Int("connections", 4, "Number of simultaneous connections. Each connection posts a subimage")
|
||||||
var address = flag.String("host", "127.0.0.1:1337", "Server address")
|
var address = flag.String("host", "127.0.0.1:1337", "Server address")
|
||||||
var runtime = flag.String("runtime", "1", "Runtime in Minutes")
|
var runtime = flag.String("runtime", "60s", "exit after timeout")
|
||||||
var shuffle = flag.Bool("shuffle", false, "pixel send ordering")
|
var shuffle = flag.Bool("shuffle", false, "pixel send ordering")
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
@ -46,6 +45,7 @@ func main() {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
defer f.Close()
|
||||||
pprof.StartCPUProfile(f)
|
pprof.StartCPUProfile(f)
|
||||||
defer pprof.StopCPUProfile()
|
defer pprof.StopCPUProfile()
|
||||||
}
|
}
|
||||||
|
@ -61,12 +61,12 @@ func main() {
|
||||||
go bomb(messages)
|
go bomb(messages)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Terminate after 1 Minute to save resources
|
// Terminate after timeout to save resources
|
||||||
timer, err := time.ParseDuration(*runtime + "m")
|
timer, err := time.ParseDuration(*runtime)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal("Invalid runtime specified: " + err.Error())
|
log.Fatal("Invalid runtime specified: " + err.Error())
|
||||||
}
|
}
|
||||||
time.Sleep(time.Minute * timer)
|
time.Sleep(timer)
|
||||||
}
|
}
|
||||||
|
|
||||||
func bomb(messages []byte) {
|
func bomb(messages []byte) {
|
||||||
|
@ -113,12 +113,13 @@ func genCommands(img image.Image, offset_x, offset_y int) (commands [][]byte) {
|
||||||
c := color.NRGBAModel.Convert(img.At(x, y)).(color.NRGBA)
|
c := color.NRGBAModel.Convert(img.At(x, y)).(color.NRGBA)
|
||||||
|
|
||||||
// ignore transparent pixels
|
// ignore transparent pixels
|
||||||
if c.A != 0 {
|
if c.A == 0 {
|
||||||
cmd := fmt.Sprintf("PX %d %d %.2x%.2x%.2x\n",
|
continue
|
||||||
x+offset_x, y+offset_y, c.R, c.G, c.B)
|
|
||||||
commands[numCmds] = []byte(cmd)
|
|
||||||
numCmds += 1
|
|
||||||
}
|
}
|
||||||
|
cmd := fmt.Sprintf("PX %d %d %.2x%.2x%.2x\n",
|
||||||
|
x+offset_x, y+offset_y, c.R, c.G, c.B)
|
||||||
|
commands[numCmds] = []byte(cmd)
|
||||||
|
numCmds += 1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue