本文整理汇总了Golang中github.com/docker/libchan.Sender类的典型用法代码示例。如果您正苦于以下问题:Golang Sender类的具体用法?Golang Sender怎么用?Golang Sender使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Sender类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: doEcho
func doEcho(sender libchan.Sender, timeout time.Duration) error {
txt := "Hello world!"
replyRecv, replySend := libchan.Pipe()
req := Request{ER: (*EchoRequest)(&txt), Reply: replySend}
err := sender.Send(req)
if err != nil {
replySend.Close()
return err
}
var reply Reply
err = replyRecv.Receive(&reply)
if err != nil {
return err
}
if reply.Code != CodeOK {
return fmt.Errorf("%s", reply.Error)
}
if string(*reply.ER) != txt {
return fmt.Errorf("echo returned bad message: '%s'", reply.ER)
}
return nil
}
示例2: NewQueue
func NewQueue(dst libchan.Sender, size int) *Queue {
r, w := libchan.Pipe()
q := &Queue{
PipeSender: w,
dst: dst,
ch: make(chan *libchan.Message, size),
}
go func() {
defer close(q.ch)
for {
msg, err := r.Receive(libchan.Ret)
if err != nil {
r.Close()
return
}
q.ch <- msg
}
}()
go func() {
for msg := range q.ch {
_, err := dst.Send(msg)
if err != nil {
r.Close()
return
}
}
}()
return q
}
示例3: SendEvents
func SendEvents(ch chan FileEvent, sender libchan.Sender) error {
for ev := range ch {
if err := sender.Send(ev); err != nil {
return err
}
}
return nil
}
示例4: BenchClient
func BenchClient(b *testing.B, c chan bool, sender libchan.Sender, sendFunc BenchMessageSender, count int) {
defer close(c)
for i := 0; i < count; i++ {
sendFunc(i, sender)
}
err := sender.Close()
if err != nil {
b.Fatalf("Error closing sender: %s", err)
}
}
示例5: copySender
func (c *channel) copySender(val libchan.Sender) (libchan.Sender, error) {
recv, send, err := c.CreateNestedReceiver()
if err != nil {
return nil, err
}
go func() {
libchan.Copy(val, recv)
val.Close()
}()
return send, nil
}
示例6: copySendChannel
func (c *channel) copySendChannel(send libchan.Sender) (*channel, error) {
recv, sendCopy, err := c.CreateNestedReceiver()
if err != nil {
return nil, err
}
// Start copying into sender
go func() {
libchan.Copy(send, recv)
send.Close()
}()
return sendCopy.(*channel), nil
}
示例7: BenchProxy
func BenchProxy(b *testing.B, c chan bool, sender libchan.Sender, receiver libchan.Receiver, count int) {
defer close(c)
n, err := libchan.Copy(sender, receiver)
if err != nil {
b.Errorf("Error proxying: %s", err)
}
err = sender.Close()
if err != nil {
b.Errorf("Error closing sender: %s", err)
}
if n != count {
b.Errorf("Wrong proxy count\n\tExpected: %d\n\tActual: %d", count, n)
}
}
示例8: SendTo
func (r *receiver) SendTo(dst libchan.Sender) (int, error) {
var n int
for {
var rm msgpack.RawMessage
if err := r.Receive(&rm); err == io.EOF {
break
} else if err != nil {
return n, err
}
if err := dst.Send(&rm); err != nil {
return n, err
}
n++
}
return n, nil
}
示例9: SendTo
func (c *channel) SendTo(dst libchan.Sender) (int, error) {
if c.direction == outbound {
return 0, ErrWrongDirection
}
var n int
for {
var rm msgpack.RawMessage
if err := c.Receive(&rm); err == io.EOF {
break
} else if err != nil {
return n, err
}
if err := dst.Send(&rm); err != nil {
return n, err
}
n++
}
return n, nil
}
示例10:
"time"
"./database"
"github.com/docker/libchan"
"github.com/docker/libchan/spdy"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
//===== tests =====
var _ = Describe("Libchan server", func() {
var clientConn net.Conn
var clientSender libchan.Sender
var serverListener net.Listener
var dbDir string
BeforeEach(func() {
dbDir = fmt.Sprintf("/tmp/db-%d", os.Getpid())
db, _ = database.Open(dbDir) // db is global defined in main.go
var err error
serverListener, err = net.Listen("tcp", "localhost:9323")
Ω(err).ShouldNot(HaveOccurred())
go ServeChan(serverListener)
time.Sleep(10 * time.Millisecond)
clientConn, err = net.Dial("tcp", "127.0.0.1:9323")