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


Golang libchan.Pipe函数代码示例

本文整理汇总了Golang中github.com/docker/libchan.Pipe函数的典型用法代码示例。如果您正苦于以下问题:Golang Pipe函数的具体用法?Golang Pipe怎么用?Golang Pipe使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


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

示例1: NewLocalRepository

func NewLocalRepository() ThingeyRepository {
	receiver, remoteSender := libchan.Pipe()
	remoteReceiver, sender := libchan.Pipe()
	senderFunc := func() (libchan.Sender, error) {
		return sender, nil
	}
	repo := NewThingeyRepository(senderFunc, receiver, remoteSender)
	adapter := NewThingeyAdapter()
	go func() {
		for {
			adapter.Listen(remoteReceiver)
		}
	}()
	return repo
}
开发者ID:mingderwang,项目名称:banano,代码行数:15,代码来源:connector.go

示例2: TapClient

func TapClient(client net.Conn, name string, stderr bool) error {
	provider, err := spdy.NewSpdyStreamProvider(client, false)
	if err != nil {
		return err
	}

	transport := spdy.NewTransport(provider)
	sender, err := transport.NewSendChannel()
	if err != nil {
		return err
	}
	defer sender.Close()

	remoteDone, done := libchan.Pipe()
	errPipe, remoteErrPipe := libchan.Pipe()

	sm := tapStreamMessage{
		Done:   remoteDone,
		Err:    remoteErrPipe,
		Name:   name,
		Stdout: !stderr,
		W:      os.Stdout,
	}

	if err := sender.Send(&sm); err != nil {
		return err
	}

	signalChan := make(chan os.Signal)
	signal.Notify(signalChan, os.Interrupt, os.Kill)
	go func() {
		<-signalChan
		if err := done.Close(); err != nil {
			logrus.Errorf("Error closing done channel")
		}
	}()

	var em errStreamMessage
	if err := errPipe.Receive(&em); err != nil && err != io.EOF {
		return err
	}

	if em.Message != "" {
		return fmt.Errorf("remote error: %s", em.Message)
	}

	return nil
}
开发者ID:docker,项目名称:golem,代码行数:48,代码来源:logtapper.go

示例3: SpawnLocalPipeBench

func SpawnLocalPipeBench(b *testing.B, sender BenchMessageSender, receiver BenchMessageReceiver) {
	endClient := make(chan bool)
	endServer := make(chan bool)

	receiver1, sender1 := libchan.Pipe()

	go BenchClient(b, endClient, sender1, sender, b.N)
	go BenchServer(b, endServer, receiver1, receiver, b.N)

	timeout := time.After(time.Duration(b.N+1) * 50 * time.Millisecond)

	for endClient != nil || endServer != nil {
		select {
		case <-endClient:
			if b.Failed() {
				b.Fatal("Client failed")
			}
			endClient = nil
		case <-endServer:
			if b.Failed() {
				b.Fatal("Server failed")
			}
			endServer = nil
		case <-timeout:
			if DumpStackOnTimeout {
				pprof.Lookup("goroutine").WriteTo(os.Stdout, 1)
			}
			b.Fatal("Timeout")
		}
	}
}
开发者ID:zhaohaidao,项目名称:libchan,代码行数:31,代码来源:bench_test.go

示例4: TestChannelAbstraction

func TestChannelAbstraction(t *testing.T) {
	client := func(t *testing.T, sender libchan.Sender, s libchan.Transport) {
		recv, send := libchan.Pipe()

		m1 := &AbstractionMessage{
			Message: "irrelevant content",
			Channel: recv,
		}

		sendErr := sender.Send(m1)
		if sendErr != nil {
			t.Fatalf("Error sending channel: %s", sendErr)
		}

		closeErr := send.Close()
		if closeErr != nil {
			t.Fatalf("Error closing sender: %s", closeErr)
		}
	}
	server := func(t *testing.T, receiver libchan.Receiver, s libchan.Transport) {
		m1 := &AbstractionMessage{}
		recvErr := receiver.Receive(m1)
		if recvErr != nil {
			t.Fatalf("Error receiving message: %s", recvErr)
		}

		if expected := "irrelevant content"; m1.Message != expected {
			t.Fatalf("Unexpected message value:\n\tExpected: %s\n\tActual: %s", expected, m1.Message)
		}
	}
	SpawnClientServerTest(t, ClientSendWrapper(client), ServerReceiveWrapper(server))
}
开发者ID:zhaohaidao,项目名称:libchan,代码行数:32,代码来源:session_test.go

示例5: RFSubscribe

func (gc *GearConn) RFSubscribe(start int64) (<-chan RFMessage, error) {
	subRecv, subSend := libchan.Pipe()
	c := make(chan RFMessage, 0)

	req := Request{
		RFS: &RFSubRequest{StartAt: start, Match: RFMessage{}, Messages: subSend},
	}

	err := gc.doRequest(&req)
	if err != nil {
		subSend.Close()
		close(c)
		return nil, err
	}

	go func() {
		for {
			var m RFMessage
			err := subRecv.Receive(&m)
			if err != nil {
				log.Printf("Error receiving RF message: %s", err.Error())
				close(c)
				return
			}
			c <- m
		}
	}()

	return c, nil
}
开发者ID:kaaLabs15,项目名称:widuino,代码行数:30,代码来源:chancli.go

示例6: doRequest

func (gc *GearConn) doRequest(req *Request) error {
	replyRecv, replySend := libchan.Pipe()
	req.Reply = replySend

	// send the request
	err := gc.mainChan.Send(req)
	if err != nil {
		replySend.Close()
		return err
	}

	// wait for a reply
	var r Reply
	err = replyRecv.Receive(&r)
	if err != nil {
		return err
	}
	switch r.Code {
	case CodeOK:
		return nil
	case CodeClientError:
		return fmt.Errorf("client error: %s", r.Error)
	case CodeServerError:
		return fmt.Errorf("server error: %s", r.Error)
	case CodeAckTimeout:
		return AckTimeoutError
	default:
		return fmt.Errorf("unknown error type: %s", r.Error)
	}
}
开发者ID:kaaLabs15,项目名称:widuino,代码行数:30,代码来源:chancli.go

示例7: 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

示例8: SensorSendData

func (gc *GearConn) SensorSendData(name string, si SensorInfo) (chan<- SensorDataValue, error) {
	dataRecv, dataSend := libchan.Pipe()

	req := Request{SD: &SensorDataRequest{name, si, dataRecv}}
	err := gc.doRequest(&req)
	if err != nil {
		dataSend.Close()
		return nil, err
	}

	c := make(chan SensorDataValue, 10)

	go func() {
		for sdv := range c {
			err := dataSend.Send(sdv)
			if err != nil {
				log.Printf("Error sending SensorDataValue message: %s", err.Error())
				return
			}
		}
		dataSend.Close()
	}()

	return c, nil
}
开发者ID:kaaLabs15,项目名称:widuino,代码行数:25,代码来源:chancli.go

示例9: SensorRead

func (gc *GearConn) SensorRead(name string, startAt, endAt, step int64) (
	<-chan SensorDataValue, error) {
	valuesRecv, valuesSend := libchan.Pipe()
	c := make(chan SensorDataValue, 0)

	req := Request{
		SR: &SensorReadRequest{name, startAt, endAt, step, valuesSend},
	}
	err := gc.doRequest(&req)
	if err != nil {
		valuesSend.Close()
		close(c)
		return nil, err
	}

	go func() {
		for {
			var m SensorDataValue
			err := valuesRecv.Receive(&m)
			if err != nil {
				log.Printf("Error receiving SensorData message: %s", err.Error())
				close(c)
				return
			}
			c <- m
		}
	}()

	return c, nil
}
开发者ID:kaaLabs15,项目名称:widuino,代码行数:30,代码来源:chancli.go

示例10: SensorSubscribe

func (gc *GearConn) SensorSubscribe(name string, startAt int64) (<-chan SensorDataValue, error) {
	subRecv, subSend := libchan.Pipe()
	c := make(chan SensorDataValue, 0)

	req := Request{SS: &SensorSubRequest{name, startAt, subSend}}
	err := gc.doRequest(&req)
	if err != nil {
		subSend.Close()
		close(c)
		return nil, err
	}

	go func() {
		for {
			var m SensorDataValue
			err := subRecv.Receive(&m)
			if err != nil {
				log.Printf("Error receiving SensorData message: %s", err.Error())
				close(c)
				return
			}
			c <- m
		}
	}()

	return c, nil
}
开发者ID:kaaLabs15,项目名称:widuino,代码行数:27,代码来源:chancli.go

示例11: GetContent

// GetContent retrieves the content stored at "path" as a []byte.
func (driver *StorageDriverClient) GetContent(path string) ([]byte, error) {
	if err := driver.exited(); err != nil {
		return nil, err
	}

	receiver, remoteSender := libchan.Pipe()

	params := map[string]interface{}{"Path": path}
	err := driver.sender.Send(&Request{Type: "GetContent", Parameters: params, ResponseChannel: remoteSender})
	if err != nil {
		return nil, err
	}

	response := new(ReadStreamResponse)
	err = driver.receiveResponse(receiver, response)
	if err != nil {
		return nil, err
	}

	if response.Error != nil {
		return nil, response.Error.Unwrap()
	}

	defer response.Reader.Close()
	contents, err := ioutil.ReadAll(response.Reader)
	if err != nil {
		return nil, err
	}
	return contents, nil
}
开发者ID:jhadvig,项目名称:origin,代码行数:31,代码来源:client.go

示例12: PutContent

// PutContent stores the []byte content at a location designated by "path".
func (driver *StorageDriverClient) PutContent(path string, contents []byte) error {
	if err := driver.exited(); err != nil {
		return err
	}

	receiver, remoteSender := libchan.Pipe()

	params := map[string]interface{}{"Path": path, "Reader": ioutil.NopCloser(bytes.NewReader(contents))}
	err := driver.sender.Send(&Request{Type: "PutContent", Parameters: params, ResponseChannel: remoteSender})
	if err != nil {
		return err
	}

	response := new(WriteStreamResponse)
	err = driver.receiveResponse(receiver, response)
	if err != nil {
		return err
	}

	if response.Error != nil {
		return response.Error.Unwrap()
	}

	return nil
}
开发者ID:jhadvig,项目名称:origin,代码行数:26,代码来源:client.go

示例13: 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

示例14: TestSendRet

func TestSendRet(t *testing.T) {
	r, w := libchan.Pipe()
	defer r.Close()
	defer w.Close()
	q := NewQueue(w, 1)
	defer q.Close()
	ret, err := q.Send(&libchan.Message{Data: []byte("Log"), Ret: libchan.RetPipe})
	if err != nil {
		t.Fatal(err)
	}
	go func() {
		ping, err := r.Receive(libchan.Ret)
		if err != nil {
			t.Fatal(err)
		}
		if _, err := ping.Ret.Send(&libchan.Message{Data: []byte("Log")}); err != nil {
			t.Fatal(err)
		}
	}()
	pong, err := ret.Receive(0)
	if err != nil {
		t.Fatal(err)
	}
	if string(pong.Data) != "Log" {
		t.Fatal(err)
	}
}
开发者ID:ndeloof,项目名称:libchan,代码行数:27,代码来源:queue_test.go

示例15: TestChannelProxy

func TestChannelProxy(t *testing.T) {
	messages := []string{
		"Proxied messages",
		"Another proxied message",
		"Far less interesting message",
		"This was ALSO sent over the proxy",
	}
	client := func(t *testing.T, sender libchan.Sender) {
		for i, m := range messages {
			nestedReceiver, remoteSender := libchan.Pipe()

			message := &ProxiedMessage{
				Message: m,
				Ret:     remoteSender,
			}

			err := sender.Send(message)
			if err != nil {
				t.Fatalf("Error sending message: %s", err)
			}

			ack := &ProxyAckMessage{}
			err = nestedReceiver.Receive(ack)
			if err != nil {
				t.Fatalf("Error receiving ack: %s", err)
			}

			if ack.N != (i + 1) {
				t.Fatalf("Unexpected ack value\n\tExpected: %d\n\tActual: %d", (i + 1), ack.N)
			}

			if ack.MessageLen != len(m) {
				t.Fatalf("Unexpected ack value\n\tExpected: %d\n\tActual: %d", len(m), ack.MessageLen)
			}
		}

	}
	server := func(t *testing.T, receiver libchan.Receiver) {
		for i, m := range messages {
			message := &ProxiedMessage{}
			err := receiver.Receive(message)
			if err != nil {
				t.Fatalf("Error receiving message: %s", err)
			}

			if message.Message != m {
				t.Fatalf("Unexpected message:\n\tExpected: %s\n\tActual: %s", m, message.Message)
			}

			ack := &ProxyAckMessage{N: i + 1, MessageLen: len(message.Message)}
			err = message.Ret.Send(ack)
			if err != nil {
				t.Fatalf("Error sending ack: %s", err)
			}
		}
	}
	SpawnProxyTest(t, client, server, 4)
}
开发者ID:zhaohaidao,项目名称:libchan,代码行数:58,代码来源:proxy_test.go


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