Beispiel #1
0
func (this *S2sClientProcessor) OnAccept(client *server.Client) {
	for {
		if this.server.SessTimeout.Nanoseconds() > int64(0) {
			client.SetReadDeadline(time.Now().Add(this.server.SessTimeout))
		}
		input := make([]byte, 1460)
		n, err := client.Conn.Read(input)

		input = input[:n]

		if err != nil {
			if err == io.EOF {
				client.Close()
				return
			} else if nerr, ok := err.(net.Error); ok && nerr.Timeout() {
				log.Info("client[%s] read timeout", client.RemoteAddr())
				client.Close()
				return
			} else if nerr, ok := err.(net.Error); !ok || !nerr.Temporary() {
				client.Close()
				return
			} else {
				log.Info("Unexpected error: %s", err.Error())
				client.Close()
				return
			}
		}

		strInput := string(input)
		log.Debug("input: %s", strInput)

		this.OnRead(client, strInput)
	}
}
Beispiel #2
0
func (this *PushdClientProcessor) OnAccept(c *server.Client) {
	client := NewClient()
	client.Client = c

	for {
		if this.server.SessTimeout.Nanoseconds() > int64(0) {
			client.SetReadDeadline(time.Now().Add(this.server.SessTimeout))
		}
		input, err := client.Proto.Read()

		if err != nil {
			if err == io.EOF {
				client.Close()
				return
			} else if nerr, ok := err.(net.Error); ok && nerr.Timeout() {
				log.Info("client[%s] read timeout", client.RemoteAddr())
				client.Close()
				return
			} else if nerr, ok := err.(net.Error); !ok || !nerr.Temporary() {
				client.Close()
				return
			} else {
				log.Info("Unexpected error: %s", err.Error())
				client.Close()
				return
			}
		}

		this.OnRead(client, string(input))
	}
}
Beispiel #3
0
func batchConn(batchSize, firstNum int) {
	var err error
	for i := 0; i < batchSize; i++ {
		log.Info("%d", i)
		conns[firstNum+i], err = net.DialTimeout("tcp", options.addr, options.connTimeout)
		if err != nil {
			lostConns++
			log.Info("connection error: %s", err.Error())
		}
	}
	wg.Done()
	log.Info("Established %d connections", batchSize)
}
Beispiel #4
0
func main() {
	log_ := "NOTICE: 15-05-25 15:32:26 errno[0] client[10.77.141.87] uri[/commoncomponent?header=1&footer=1&menu=1&hlflag=child] user[15000000000209285] refer[] cookie[SESSIONID=02bef8adbvrquan5j1gjcsd9u3;U_UID=02bef8adbvrquan5j1gjcsd9u3;tempNoticeClosed=1;CITY_ID=110100;uid=15000000000209285;PHPSESSID=02bef8adbvrquan5j1gjcsd9u3] post[] ts[0.045583009719849]\n"
	var err error
	if checkFileIsExist(options.log) {
		log.Info("Log file: %s", options.log)
	} else {
		_, err = os.Create(options.log)
		if err != nil {
			log.Error("file not exists")
		}
		os.Exit(1)
	}
	waitGroup := make(chan interface{})
	for i := 0; i < options.concurrency; i++ {
		go func() {
			f, err := os.OpenFile(options.log, os.O_RDWR|os.O_APPEND, 0666)
			if err != nil {
				log.Error(err)
			}
			for j := 0; j < options.last; j++ {
				for k := 0; k < options.requests; k++ {
					appendLog(f, log_)
				}
				time.Sleep(time.Second)
			}
			waitGroup <- true
		}()
	}
	for i := 0; i < options.concurrency; i++ {
		<-waitGroup
	}
}
Beispiel #5
0
func shutdown() {
	for i, conn := range conns {
		log.Debug("close connection %d", i)
		err := conn.Close()
		if err != nil {
			log.Info("close error: %s", err.Error())
		}
	}
}
Beispiel #6
0
func (this *Poller) tailFile(filename string, isNew bool) {
	log.Info("Tail file: %s", filename)
	var location *tail.SeekInfo
	if isNew {
		location = &tail.SeekInfo{Offset: 0, Whence: os.SEEK_SET}
	} else {
		location = &tail.SeekInfo{Offset: 0, Whence: os.SEEK_END}
	}
	t, err := tail.TailFile(filename, tail.Config{Follow: true, Location: location})
	if err != nil {
		log.Error("tail file[%s] errer: %s", filename, err.Error())
	}
	for line := range t.Lines {
		txt := line.Text
		log.Info(txt)
		if tag := this.filter(txt); tag != "" {
			this.forwarder.Enqueue(fmt.Sprintf("%s|%s", tag, txt))
		}
	}
}
Beispiel #7
0
func GetPiped() (string, error) {
	addrs, err := etclib.Children(fmt.Sprintf("/%s", etclib.SERVICE_PIPED))
	if err != nil {
		return "", err
	}
	if len(addrs) == 0 {
		panic("No piped found")
	}
	log.Info(addrs)
	time.Sleep(time.Second)
	return addrs[rand.Intn(len(addrs))], nil
}
Beispiel #8
0
func main() {
	buildConns()

	for i := 0; i < options.requests; i++ {
		log.Info("Start round %d", i)
		batchStart := 0
		for connLeft := options.concurrency; connLeft > 0; connLeft -= options.batchSize {
			thisBatch := int(math.Min(float64(connLeft), float64(options.batchSize)))
			go batchWrite(thisBatch, batchStart, i)
			batchStart += thisBatch
		}
		time.Sleep(time.Second)
	}

	shutdown()

	time.Sleep(time.Second)
}
Beispiel #9
0
func shutdown() {
	defer func() {
		if err := recover(); err != nil {
			fmt.Println(err)
			debug.PrintStack()
		}
	}()
	log.Info("Terminated")

	if config.PushdConf.IsDistMode() {
		err := engine.UnregisterEtc()
		if err != nil {
			log.Error(err)
		}
	}

	if config.PushdConf.IsDistMode() {
		s2sServer.StopTcpServer()
	}
	pushdServer.StopTcpServer()
	time.Sleep(time.Second * 2)
	os.Exit(0)
}
Beispiel #10
0
func (this *PushdLongPollingServer) ServeSubscribe(w http.ResponseWriter, req *http.Request) {
	vars := mux.Vars(req)
	channel := vars["channel"]
	tsStr := vars["ts"]
	ts, err := strconv.Atoi(tsStr)
	if err != nil {
		io.WriteString(w, "invalid timestamp")
		return
	}
	hj, ok := w.(http.Hijacker)
	if !ok {
		http.Error(w, "webserver doesn't support hijacking", http.StatusInternalServerError)
		return
	}

	conn, _, err := hj.Hijack()
	if err != nil {
		http.Error(w, err.Error(), http.StatusInternalServerError)
		return
	}

	conn.Write([]byte("HTTP/1.1 200 OK\r\n"))
	conn.Write([]byte("Access-Control-Allow-Origin: *\r\n"))
	conn.Write([]byte("\r\n"))

	//fetch history first
	if ts != 0 {
		hisRet, err := history(channel, int64(ts)+1)
		for i, hisRetEle := range hisRet {
			retEleBson, _ := hisRetEle.(bson.M)
			retEleBson["ts"] = strconv.Itoa(int(retEleBson["ts"].(int64)))
			hisRet[i] = retEleBson
		}
		if err != nil {
			log.Error(err)
		}
		if len(hisRet) > 0 {
			var retBytes []byte
			retBytes, err = json.Marshal(hisRet)

			conn.Write(retBytes)
			conn.Close()
			return
		}
	}

	c := server.NewClient(conn, time.Now(), server.CONN_TYPE_LONG_POLLING, nil)
	client := NewClient()
	client.Client = c

	subscribe(client, channel)

	for {
		if this.sessTimeout.Nanoseconds() > int64(0) {
			client.SetReadDeadline(time.Now().Add(this.sessTimeout))
		}
		_, err := client.Conn.Read(make([]byte, 1460))

		if err != nil {
			if err == io.EOF {
				log.Info("Client end polling: %s", client.Conn.RemoteAddr())
				client.Close()
				return
			} else if nerr, ok := err.(net.Error); ok && nerr.Timeout() {
				log.Info("client[%s] read timeout", client.RemoteAddr())
				client.Close()
				return
			} else if nerr, ok := err.(net.Error); !ok || !nerr.Temporary() {
				client.Close()
				return
			} else {
				log.Info("Unexpected error: %s", err.Error())
				client.Close()
				return
			}
		}
	}
}
Beispiel #11
0
func (this *ServerStats) stopHttpServer() {
	log.Info("stats httpd stopped")
	this.StopHttpServer()
}
Beispiel #12
0
func shutdown() {
	cleanup()
	log.Info("Terminated")
	os.Exit(0)
}