func main() { fmt.Fprintf(os.Stderr, "Starting "+sys.Name+" Tangra Daemon, Build "+sys.Build+"\n") flag.Parse() // Setup log writing facility if *flagLog == "" { fmt.Fprintf(os.Stderr, "tonika-tangrad: You must specify a log file prefix\n") os.Exit(1) } fw_, err := filewriter.MakeFileWriter(*flagLog) if err != nil { fmt.Fprintf(os.Stderr, "tonika-tangrad: Error creating log file: %s\n", err) os.Exit(1) } fw = fw_ // Start listening l, err := net.Listen("tcp", *flagBind) if err != nil { fmt.Fprintf(os.Stderr, "tonika-tangrad: Error binding: %s\n", err) os.Exit(1) } s := http.NewAsyncServer(l, 10e9, 240) for { q, err := s.Read() if err == nil { go serve(q) } } }
func MakeServer(bind, dir string, fdlim int) (*Server, os.Error) { statPrefix := dir + "/log/towstats" logPrefix := dir + "/log/towlog" templateDir := dir + "/template" // Stats stats := &WWWStats{} err := filewriter.LatestDecode(statPrefix, stats) if err != nil { stats = &WWWStats{} } statwriter, err := filewriter.MakeLatestFileEncoder(statPrefix) if err != nil { return nil, err } fmt.Fprintf(os.Stderr, "tonika-wwwd: Starting with Views=%d, Downloads=%d\n", stats.Views, stats.Downloads) // Logger logwriter, err := filewriter.MakeFileWriter(logPrefix) if err != nil { return nil, err } // Templates tmpl, err := loadTmpl(templateDir, "index.html") if err != nil { return nil, err } // HTTP Bind l, err := net.Listen("tcp", bind) if err != nil { return nil, err } // OK s := &Server{ as: http.NewAsyncServer(l, 20e9, fdlim), dir: dir, logwriter: logwriter, stats: stats, statwriter: statwriter, indextmpl: tmpl, } go s.statLoop() return s, nil }