Exemplo n.º 1
0
func main() {

	ch1 := curl.EasyInit()
	ch2 := curl.EasyInit()

	ch1.Setopt(curl.OPT_URL, "http://www.163.com")
	ch1.Setopt(curl.OPT_HEADER, 0)
	ch1.Setopt(curl.OPT_VERBOSE, true)
	ch2.Setopt(curl.OPT_URL, "http://www.baidu.com")
	ch2.Setopt(curl.OPT_HEADER, 0)
	ch2.Setopt(curl.OPT_VERBOSE, true)

	mh := curl.MultiInit()

	mh.AddHandle(ch1)
	mh.AddHandle(ch2)

	for {
		nRunning, _ := mh.Perform()
		// println("n =", nRunning)
		if nRunning == 0 {
			println("ok")
			break
		}
		time.Sleep(1000)
	}

}
Exemplo n.º 2
0
func main() {
	var (
		rset, wset, eset            syscall.FdSet
		still_running, curl_timeout int = 0, 0
		err                         error
	)

	ch1 := curl.EasyInit()
	ch2 := curl.EasyInit()

	ch1.Setopt(curl.OPT_URL, "http://www.163.com")
	ch1.Setopt(curl.OPT_HEADER, 0)
	ch1.Setopt(curl.OPT_VERBOSE, true)
	ch2.Setopt(curl.OPT_URL, "http://www.baidu.com")
	ch2.Setopt(curl.OPT_HEADER, 0)
	ch2.Setopt(curl.OPT_VERBOSE, true)

	mh := curl.MultiInit()

	mh.AddHandle(ch1)
	mh.AddHandle(ch2)

	for {
		FD_ZERO(&rset)
		FD_ZERO(&wset)
		FD_ZERO(&eset)

		timeout := syscall.Timeval{Sec: 1, Usec: 0}
		curl_timeout, err = mh.Timeout()
		if err != nil {
			fmt.Printf("Error multi_timeout: %s\n", err)
		}
		if curl_timeout >= 0 {
			timeout.Sec = int64(curl_timeout / 1000)
			if timeout.Sec > 1 {
				timeout.Sec = 1
			} else {
				timeout.Usec = int64((curl_timeout % 1000)) * 1000
			}
		}

		max_fd, err := mh.Fdset(&rset, &wset, &eset)
		if err != nil {
			fmt.Printf("Error FDSET: %s\n", err)
		}

		_, err = syscall.Select(int(max_fd+1), &rset, &wset, &eset, &timeout)
		if err != nil {
			fmt.Printf("Error select: %s\n", err)
		} else {
			still_running, err = mh.Perform()
			if still_running > 0 {
				fmt.Printf("Still running: %d\n", still_running)
			} else {
				break
			}
		}
	}

}