本文整理汇总了Golang中github.com/mdlayher/aoe.Header类的典型用法代码示例。如果您正苦于以下问题:Golang Header类的具体用法?Golang Header怎么用?Golang Header使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Header类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: headersEqual
// headersEqual compares a response and request AoE header for equality, but
// does not factor in their Arg fields.
func headersEqual(res, req aoe.Header) bool {
if !res.FlagResponse {
panic("response AoE header did not have FlagResponse set, please verify parameter order")
}
// Set request's response flag for comparison
req.FlagResponse = true
// Clear arguments of both request and response so we can compare the
// headers, and because the arguments are compared separately
req.Arg = nil
res.Arg = nil
return reflect.DeepEqual(res, req)
}
开发者ID:ConfusedReality,项目名称:server_distributed-storage_torus,代码行数:17,代码来源:aoe_test.go
示例2: Send
func (fs *FrameSender) Send(hdr *aoe.Header) (int, error) {
hdr.Version = 1
hdr.FlagResponse = true
hdr.Major = fs.major
hdr.Minor = fs.minor
hdr.Tag = fs.orig.Tag
hbuf, err := hdr.MarshalBinary()
if err != nil {
panic(err)
}
frame := ðernet.Frame{
Destination: fs.dst,
Source: fs.src,
EtherType: aoe.EtherType,
Payload: hbuf,
}
ebuf, err := frame.MarshalBinary()
if err != nil {
panic(err)
}
clog.Debugf("send %d %s %+v", len(ebuf), fs.dst, hdr)
//clog.Debugf("send arg %+v", hdr.Arg)
return fs.conn.WriteTo(ebuf, &raw.Addr{HardwareAddr: fs.dst})
}
开发者ID:ConfusedReality,项目名称:server_distributed-storage_torus,代码行数:29,代码来源:frame.go
示例3: testRequest
// testRequest performs a single AoE request using the input request
// header and returns a single AoE response.
func testRequest(t *testing.T, req *aoe.Header) *aoe.Header {
recv, send, run, done := testAoEServer(t)
defer done()
reqb, err := req.MarshalBinary()
if err != nil {
t.Fatalf("failed to marshal request AoE header: %v", err)
}
reqf := ðernet.Frame{
Payload: reqb,
}
reqfb, err := reqf.MarshalBinary()
if err != nil {
t.Fatalf("failed to marshal request Ethernet frame: %v", err)
}
if _, err := send.Write(reqfb); err != nil {
t.Fatalf("failed to write request to server: %v", err)
}
if err := run(); err != nil {
t.Fatalf("failed to run server: %v", err)
}
b, err := ioutil.ReadAll(recv)
if err != nil {
t.Fatalf("failed to read server response: %v", err)
}
resf := new(ethernet.Frame)
if err := resf.UnmarshalBinary(b); err != nil {
t.Fatalf("failed to unmarshal response Ethernet frame: %v", err)
}
resh := new(aoe.Header)
if err := resh.UnmarshalBinary(resf.Payload); err != nil {
t.Fatalf("failed to unmarshal response AoE header: %v", err)
}
return resh
}
开发者ID:ConfusedReality,项目名称:server_distributed-storage_torus,代码行数:45,代码来源:aoe_test.go
示例4: testBPFProgram
// testBPFProgram builds a BPF program for the input server and compares the
// output of the program against the input AoE header, returning whether or
// not the header was accepted by the filter.
func testBPFProgram(t *testing.T, s *Server, h *aoe.Header) bool {
filter, ok := bpf.Disassemble(s.mustAssembleBPF(testMTU))
if !ok {
t.Fatal("failed to decode all BPF instructions")
}
vm, err := bpf.NewVM(filter)
if !ok {
t.Fatalf("failed to load BPF program: %v", err)
}
// Fill in empty AoE header fields not relevant to this test
h.Version = aoe.Version
h.Command = aoe.CommandQueryConfigInformation
h.Arg = &aoe.ConfigArg{
Command: aoe.ConfigCommandRead,
}
hb, err := h.MarshalBinary()
if err != nil {
t.Fatalf("failed to marshal AoE header to binary: %v", err)
}
f := ðernet.Frame{
EtherType: aoe.EtherType,
Payload: hb,
}
fb, err := f.MarshalBinary()
if err != nil {
t.Fatalf("failed to marshal Ethernet frame to binary: %v", err)
}
out, err := vm.Run(fb)
if err != nil {
t.Fatalf("failed to run BPF program: %v", err)
}
return out > 0
}
开发者ID:ConfusedReality,项目名称:server_distributed-storage_torus,代码行数:42,代码来源:aoe_test.go
注:本文中的github.com/mdlayher/aoe.Header类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论