本文整理汇总了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
}