本文整理汇总了Golang中syscall.Timeval.Usec方法的典型用法代码示例。如果您正苦于以下问题:Golang Timeval.Usec方法的具体用法?Golang Timeval.Usec怎么用?Golang Timeval.Usec使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类syscall.Timeval
的用法示例。
在下文中一共展示了Timeval.Usec方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: main
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
}
}
}
}
示例2: timeToTimeval
// timeToTimeval - Convert time.Time to syscall.Timeval
//
// Note: This does not use syscall.NsecToTimespec because
// that does not work properly for times before 1970,
// see https://github.com/golang/go/issues/12777
func timeToTimeval(t *time.Time) syscall.Timeval {
var tv syscall.Timeval
tv.Usec = int32(t.Nanosecond() / 1000)
tv.Sec = t.Unix()
return tv
}