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


Golang Socket.GetFd方法代碼示例

本文整理匯總了Golang中github.com/pebbe/zmq4.Socket.GetFd方法的典型用法代碼示例。如果您正苦於以下問題:Golang Socket.GetFd方法的具體用法?Golang Socket.GetFd怎麽用?Golang Socket.GetFd使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/pebbe/zmq4.Socket的用法示例。


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

示例1: Add

// Add registers a socket for sending and/or receiving.  The caller can't
// access the socket directly after this.  The send channel (if any) should be
// closed by the caller.
func (io *IO) Add(s *zmq.Socket, send <-chan Data, recv chan<- Data) (err error) {
	fd, err := s.GetFd()
	if err != nil {
		return
	}

	w := newWorker()

	io.lock.Lock()
	io.workers[int32(fd)] = w
	io.lock.Unlock()

	defer func() {
		if err != nil {
			io.lock.Lock()
			delete(io.workers, int32(fd))
			io.lock.Unlock()
		}
	}()

	e := &syscall.EpollEvent{
		Events: syscall.EPOLLIN | syscall.EPOLLET&0xffffffff,
		Fd:     int32(fd),
	}

	if err = syscall.EpollCtl(io.epollFd, syscall.EPOLL_CTL_ADD, fd, e); err != nil {
		return
	}

	state, err := s.GetEvents()
	if err != nil {
		syscall.EpollCtl(io.epollFd, syscall.EPOLL_CTL_DEL, fd, nil)
		return
	}

	go func() {
		defer s.Close()
		defer syscall.EpollCtl(io.epollFd, syscall.EPOLL_CTL_DEL, fd, nil)

		w.socketLoop(s, send, recv, state)
	}()

	return
}
開發者ID:ninchat,項目名稱:zmq4chan,代碼行數:47,代碼來源:io.go

示例2: Remove

// Remove closes a socket.  If it has been registered, it will be removed.  The
// recv channel (if any) will be closed.
func (io *IO) Remove(s *zmq.Socket) (err error) {
	fd, err := s.GetFd()
	if err != nil {
		return
	}

	io.lock.Lock()
	w := io.workers[int32(fd)]
	if w != nil {
		delete(io.workers, int32(fd))
	}
	io.lock.Unlock()

	if w != nil {
		w.close()
	} else {
		err = s.Close()
	}
	return
}
開發者ID:ninchat,項目名稱:zmq4chan,代碼行數:22,代碼來源:io.go


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