-
Notifications
You must be signed in to change notification settings - Fork 0
/
Server.go
executable file
·68 lines (60 loc) · 1.43 KB
/
Server.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package main
import (
"bufio"
"log"
"net"
"time"
)
type Server struct {
L_client net.Listener
ToStartClient chan *Client
Cache *Cache
}
func (self *Server) StartServer( cache *Cache ) {
var err error
self.L_client, err = net.Listen("tcp", ":"+mainConfig.ClientPort)
if err != nil {
log.Fatal("Create client listen port: " + err.Error())
}
self.ToStartClient = make(chan *Client, 1000)
self.Cache = cache
go self.AcceptClient()
}
func (self *Server) AcceptClient() {
for {
c, err := self.L_client.Accept()
if err != nil {
log.Fatal(err)
}
client := &Client{
Conn: c,
InputChan: make(chan *Input, 100000),
Buff: bufio.NewReader(c),
Cache: self.Cache,
}
self.ToStartClient <- client
log.Println("added client for " + client.Conn.RemoteAddr().String())
}
}
func (self *Server) startClient(client *Client) {
log.Println("started client for " + client.Conn.RemoteAddr().String())
err := client.handleConn()
if err != nil {
log.Println("ClientHandler returned: " + err.Error())
client.Conn.Close()
}
}
func (self *Server) ClientStarter() {
for client := range self.ToStartClient {
go client.ProcessInput()
go self.startClient(client)
}
}
func (self *Server) Run() {
go self.ClientStarter()
for {
//replace this with function which checks for new source
// builds new binaries and set new versions
time.Sleep(time.Second * 10)
}
}