Beispiel #1
0
func (receiver *socksReceiver) handleConnection(conn net.Conn) {
	data, host, err := receiver.request(conn)
	if err != nil {
		logger.Errorf("Server:---->cannot find host %s\n", err)
		return
	}
	cli := client.NewClient(host)
	if cli == nil {
		logger.Error("handle connection error,cannot create client.")
		return
	}
	defer func() {
		//fixe bug when cli is nil
		if cli != nil {
			cli.Close()
		}
		conn.Close()
	}()
	if _, err := cli.Conn.Write(data); err != nil {
		logger.Error("Server:----->write data error")
		return
	}

	c.SetTimeout(cli.Conn.SetReadDeadline, receiver.cfg.Timeout)
	c.SetTimeout(conn.SetReadDeadline, receiver.cfg.Timeout)
	//for comment
	go io.Copy(cli.Conn, conn)
	io.Copy(conn, cli.Conn)

}
Beispiel #2
0
func handleChina(con net.Conn, host string) {
	//con.Write(httpOk)
	cli := client.NewClient(host)
	if cli == nil {
		logger.Errorf("http----->error when create client")
		return
	}
	//config.SetTimeout(cli.Conn.SetReadDeadline, 5)
	defer func() {
		logger.Info("close pipline")
		con.Close()
		cli.Close()
	}()
	pipe(cli.Conn, con)
}