Esempio n. 1
0
func (sched *Sched) handleConnection(conn net.Conn) {
	c := protocol.NewServerConn(conn)
	payload, err := c.Receive()
	if len(payload) == 4 {
		if bytes.Contains([]byte("GET ,POST,DELETE,PUT "), payload) {
			httpclient := newHTTPClient(sched, c)
			httpclient.handle(payload)
		} else {
			log.Printf("Unsupport protocol %v\n", payload)
			c.Close()
		}
		return
	}
	if err != nil {
		if err != io.EOF {
			log.Printf("Connection Error: %v, %v\n", err, payload)
			c.Close()
		}
		return
	}
	switch protocol.ClientType(payload[0]) {
	case protocol.TYPECLIENT:
		client := newClient(sched, c)
		client.handle()
		break
	case protocol.TYPEWORKER:
		w := newWorker(sched, c)
		w.handle()
		break
	default:
		log.Printf("Unsupport client %d\n", payload[0])
		c.Close()
		break
	}
}
Esempio n. 2
0
func (sched *Sched) HandleConnection(conn net.Conn) {
	c := protocol.Conn{Conn: conn}
	payload, err := c.Receive()
	if err != nil {
		return
	}
	switch protocol.ClientType(payload[0]) {
	case protocol.TYPE_CLIENT:
		client := NewClient(sched, c)
		go client.Handle()
		break
	case protocol.TYPE_WORKER:
		worker := NewWorker(sched, c)
		go worker.Handle()
		break
	default:
		log.Printf("Unsupport client %d\n", payload[0])
		c.Close()
		break
	}
}