Skip to content

Commit

Permalink
Server: allow user to specify maximum number of cores to use.
Browse files Browse the repository at this point in the history
  • Loading branch information
cyfdecyf committed Jan 16, 2013
1 parent ce4d808 commit 8ef8ed6
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions cmd/shadowsocks-server/server.go
Expand Up @@ -10,6 +10,7 @@ import (
"net"
"os"
"os/signal"
"runtime"
"strconv"
"sync"
"sync/atomic"
Expand Down Expand Up @@ -299,13 +300,15 @@ func main() {

var cmdConfig ss.Config
var printVer bool
var core int

flag.BoolVar(&printVer, "version", false, "print version")
flag.StringVar(&configFile, "c", "config.json", "specify config file")
flag.StringVar(&cmdConfig.Password, "k", "", "password")
flag.IntVar(&cmdConfig.ServerPort, "p", 0, "server port")
flag.IntVar(&cmdConfig.Timeout, "t", 60, "connection timeout (in seconds)")
flag.StringVar(&cmdConfig.Method, "m", "", "encryption method, use empty string or rc4")
flag.IntVar(&core, "core", 0, "maximum number of CPU cores to use, default is determinied by Go runtime")
flag.BoolVar((*bool)(&debug), "d", false, "print debug message")

flag.Parse()
Expand All @@ -330,14 +333,15 @@ func main() {
} else {
ss.UpdateConfig(config, &cmdConfig)
}
if err = unifyPortPassword(config); err != nil {
os.Exit(1)
}
if err = ss.SetDefaultCipher(config.Method); err != nil {
log.Fatal(err)
}

if err = unifyPortPassword(config); err != nil {
os.Exit(1)
if core > 0 {
runtime.GOMAXPROCS(core)
}

for port, password := range config.PortPassword {
go run(port, password)
}
Expand Down

0 comments on commit 8ef8ed6

Please sign in to comment.