當前位置: 首頁>>代碼示例>>Golang>>正文


Golang C.zmq_poll函數代碼示例

本文整理匯總了Golang中C.zmq_poll函數的典型用法代碼示例。如果您正苦於以下問題:Golang zmq_poll函數的具體用法?Golang zmq_poll怎麽用?Golang zmq_poll使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了zmq_poll函數的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: poll

func (p *Poller) poll(timeout time.Duration, all bool) ([]Polled, error) {
	lst := make([]Polled, 0, len(p.items))

	for _, soc := range p.socks {
		if !soc.opened {
			return lst, ErrorSocketClosed
		}
	}

	t := timeout
	if t > 0 {
		t = t / time.Millisecond
	}
	if t < 0 {
		t = -1
	}
	rv, err := C.zmq_poll(&p.items[0], C.int(len(p.items)), C.long(t))
	if rv < 0 {
		return lst, errget(err)
	}
	for i, it := range p.items {
		if all || it.events&it.revents != 0 {
			lst = append(lst, Polled{p.socks[i], State(it.revents)})
		}
	}
	return lst, nil
}
開發者ID:pebbe,項目名稱:zmq3,代碼行數:27,代碼來源:polling.go

示例2: Poll

// Poll waits for activity on the monitored set of sockets and/or files. If the timeout is zero, Poll will return
// immediately. If it is negative, Poll will wait forever until an event is triggered. Poll returns the number of
// sockets/files for which events were triggered, or a non-nil error.
func (p *PollSet) Poll(timeout time.Duration) (n int, err error) {
	if p.items == nil || len(p.items) == 0 {
		return
	}
	started := time.Now()
	for {
		var micros C.long
		if timeout < 0 {
			micros = -1
		} else {
			micros = C.long(started.Add(timeout).Sub(time.Now()) / time.Microsecond)
		}
		err = nil
		r := C.zmq_poll(&p.items[0], C.int(len(p.items)), micros)
		if r == -1 {
			err = zmqerr()
		} else {
			n = int(r)
		}
		if err != ErrInterrupted {
			break
		}
	}
	return
}
開發者ID:The-Cloud-Source,項目名稱:opentsp,代碼行數:28,代碼來源:poll.go

示例3: Poll

func (p lzmqContext) Poll(items []PollItem, timeout int) (int, os.Error) {
	ret := int(C.zmq_poll((*C.zmq_pollitem_t)(unsafe.Pointer(&items[0])), C.int(len(items)), C.long(timeout)))
	if ret >= 0 {
		return ret, nil
	}
	return 0, p.Provider().GetError()
}
開發者ID:miffa,項目名稱:gozero,代碼行數:7,代碼來源:zmq.go

示例4: Poll

// Poll ZmqSockets and file descriptors for I/O readiness. Timeout is in
// microseconds.
func Poll(items []PollItem, timeout int64) (count int, err error) {
	zitems := make([]C.zmq_pollitem_t, len(items))
	for i, pi := range items {
		zitems[i].socket = pi.Socket.apiSocket()
		zitems[i].fd = pi.Fd.ToRaw()
		zitems[i].events = C.short(pi.Events)
	}
	rc := int(C.zmq_poll(&zitems[0], C.int(len(zitems)), C.long(timeout)))
	if rc == -1 {
		return 0, errno()
	}

	for i, zi := range zitems {
		items[i].REvents = PollEvents(zi.revents)
	}

	return rc, nil
}
開發者ID:psilva261,項目名稱:gozmq,代碼行數:20,代碼來源:zmq.go

示例5: Poll

/*
Input/output multiplexing

If timeout < 0, wait forever until a matching event is detected

Only sockets with matching socket events are returned in the list.

Example:

    poller := zmq.NewPoller()
    poller.Add(socket0, zmq.POLLIN)
    poller.Add(socket1, zmq.POLLIN)
    //  Process messages from both sockets
    for {
        sockets, _ := poller.Poll(-1)
        for _, socket := range sockets {
            switch s := socket.Socket; s {
            case socket0:
                msg, _ := s.Recv(0)
                //  Process msg
            case socket1:
                msg, _ := s.Recv(0)
                //  Process msg
            }
        }
    }
*/
func (p *Poller) Poll(timeout time.Duration) ([]Polled, error) {
	lst := make([]Polled, 0, p.size)
	t := timeout
	if t > 0 {
		t = t / time.Millisecond
	}
	if t < 0 {
		t = -1
	}
	rv, err := C.zmq_poll(&p.items[0], C.int(len(p.items)), C.long(t))
	if rv < 0 {
		return lst, errget(err)
	}
	for i, it := range p.items {
		if it.events&it.revents != 0 {
			lst = append(lst, Polled{p.socks[i], State(it.revents)})
		}
	}
	return lst, nil
}
開發者ID:johnvilsack,項目名稱:golang-stuff,代碼行數:47,代碼來源:polling.go

示例6: Poll

// Poll ZmqSockets and file descriptors for I/O readiness. Timeout is in
// time.Duration. The smallest possible timeout is time.Millisecond for
// ZeroMQ version 3 and above, and time.Microsecond for earlier versions.
func Poll(items []PollItem, timeout time.Duration) (count int, err error) {
	zitems := make([]C.zmq_pollitem_t, len(items))
	for i, pi := range items {
		zitems[i].socket = pi.Socket.apiSocket()
		zitems[i].fd = pi.Fd.ToRaw()
		zitems[i].events = C.short(pi.Events)
	}
	ztimeout := C.long(-1)
	if timeout >= 0 {
		ztimeout = C.long(uint64(timeout / pollunit))
	}
	rc, err := C.zmq_poll(&zitems[0], C.int(len(zitems)), ztimeout)
	if rc == -1 {
		return 0, casterr(err)
	}

	for i, zi := range zitems {
		items[i].REvents = PollEvents(zi.revents)
	}

	return int(rc), nil
}
開發者ID:quenel,項目名稱:gozmq,代碼行數:25,代碼來源:zmq.go


注:本文中的C.zmq_poll函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。