当前位置: 首页>>代码示例>>Golang>>正文


Golang Socket.Context方法代码示例

本文整理汇总了Golang中github.com/pebbe/zmq4.Socket.Context方法的典型用法代码示例。如果您正苦于以下问题:Golang Socket.Context方法的具体用法?Golang Socket.Context怎么用?Golang Socket.Context使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/pebbe/zmq4.Socket的用法示例。


在下文中一共展示了Socket.Context方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: NewZmqChanSocket

// func NewZmqChanSocket(zmqContext *zmq.Context, zSock *zmq.Socket, txbuf int, rxbuf in) (*ZmqChanSocket, error)
//
// Produce a new ZmqChanSocket. Pass a contact and a zmq.Socket, plus the buffering parameters for the channels.
//
// If this call succeeds (err == nil), then a ZmqChanSocket is returned, and control of your zmq.Socket is passed
// irrevocably to this routine. You should forget you ever had the socket. Do not attempt to use it in any way,
// as its manipulation is now the responsibility of goroutines launched by this routine. Closing the ZmqChanSocket
// will also close your zmq.Socket.
//
// If this routine errors, it is the caller's responsibility to close the zmq.Socket
//
func NewZmqChanSocket(zSock *zmq.Socket, txbuf int, rxbuf int) (ChanSocket, error) {
	s := &ZmqChanSocket{
		zSock: zSock,
	}

	zmqContext, err := zSock.Context()
	if err != nil {
		return nil, err
	}

	if s.zControlIn, s.zControlOut, err = newPair(zmqContext); err != nil {
		return nil, err
	}
	if s.zTxIn, s.zTxOut, err = newPair(zmqContext); err != nil {
		s.zControlIn.Close()
		s.zControlOut.Close()
		return nil, err
	}

	// as we should never read or send to these sockets unless they are ready
	// we set the timeout to 0 so a write or read in any other circumstance
	// returns a immediate error
	s.zSock.SetRcvtimeo(0)
	s.zSock.SetSndtimeo(0)
	s.zTxIn.SetRcvtimeo(0)
	s.zTxIn.SetSndtimeo(0)
	s.zTxOut.SetRcvtimeo(0)
	s.zTxOut.SetSndtimeo(0)
	s.zControlIn.SetRcvtimeo(0)
	s.zControlIn.SetSndtimeo(0)
	s.zControlOut.SetRcvtimeo(0)
	s.zControlOut.SetSndtimeo(0)

	s.initImpl(txbuf, rxbuf)

	barrier()
	s.wg.Add(2)
	go s.runSockets()
	go s.runChannels()
	return s, nil
}
开发者ID:abligh,项目名称:ghostfish,代码行数:52,代码来源:zmqchansocket.go


注:本文中的github.com/pebbe/zmq4.Socket.Context方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。