Exemple #1
0
func TestSendConn(t *testing.T) {
	a, b, err := USocketPair()
	if err != nil {
		t.Fatal(err)
	}
	defer a.Close()
	defer b.Close()
	go func() {
		conn, err := SendConn(a, data.Empty().Set("type", "connection").Bytes())
		if err != nil {
			t.Fatal(err)
		}
		if err := conn.Send(data.Empty().Set("foo", "bar").Bytes(), nil); err != nil {
			t.Fatal(err)
		}
		conn.CloseWrite()
	}()
	payload, conn, err := ReceiveConn(b)
	if err != nil {
		t.Fatal(err)
	}
	if val := data.Message(string(payload)).Get("type"); val == nil || val[0] != "connection" {
		t.Fatalf("%v != %v\n", val, "connection")
	}
	msg, _, err := conn.Receive()
	if err != nil {
		t.Fatal(err)
	}
	if val := data.Message(string(msg)).Get("foo"); val == nil || val[0] != "bar" {
		t.Fatalf("%v != %v\n", val, "bar")
	}
}
Exemple #2
0
func (m *Message) LibchanMessage() *libchan.Message {
	encoded := data.Empty().
		Set("verb", m.Verb.String()).
		Set("args", m.Args...)

	var ret libchan.Sender
	if m.Ret != nil {
		ret = m.Ret.Unwrap()
	}

	return &libchan.Message{
		Data: []byte(encoded),
		Ret:  ret,
		Fd:   m.Att,
	}
}