本文整理匯總了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
}