本文整理汇总了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
}
开发者ID:kaaLabs15,项目名称:widuino,代码行数:25,代码来源:chancli.go
示例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
}
开发者ID:ndeloof,项目名称:libchan,代码行数:29,代码来源:queue.go
示例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
}
开发者ID:lox,项目名称:binarystar,代码行数:8,代码来源:events.go
示例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)
}
}
开发者ID:zhaohaidao,项目名称:libchan,代码行数:10,代码来源:bench_test.go
示例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
}
开发者ID:josephwinston,项目名称:libchan,代码行数:11,代码来源:copy.go
示例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
}
开发者ID:beibei1990,项目名称:libchan,代码行数:12,代码来源:encode.go
示例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)
}
}
开发者ID:zhaohaidao,项目名称:libchan,代码行数:14,代码来源:bench_test.go
示例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
}
开发者ID:zhaohaidao,项目名称:libchan,代码行数:17,代码来源:session.go
示例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
}
开发者ID:beibei1990,项目名称:libchan,代码行数:20,代码来源:session.go
示例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")
开发者ID:kaaLabs15,项目名称:widuino,代码行数:31,代码来源:chansrv_test.go
注:本文中的github.com/docker/libchan.Sender类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论