fusego/internal/buffer/out_message.go

97 lines
2.9 KiB
Go
Raw Normal View History

2015-07-24 06:36:53 +03:00
// Copyright 2015 Google Inc. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package buffer
2015-07-24 06:26:25 +03:00
import (
2015-07-28 09:23:10 +03:00
"log"
2015-07-24 06:26:25 +03:00
"unsafe"
"github.com/jacobsa/fuse/internal/fusekernel"
)
2015-07-28 09:20:50 +03:00
const outHeaderSize = unsafe.Sizeof(fusekernel.OutHeader{})
2015-07-28 09:06:23 +03:00
// We size out messages to be large enough to hold a header for the response
// plus the largest read that may come in.
2015-07-28 09:20:50 +03:00
const outMessageSize = outHeaderSize + MaxReadSize
2015-07-28 09:06:23 +03:00
2015-07-24 07:11:03 +03:00
// OutMessage provides a mechanism for constructing a single contiguous fuse
2015-07-24 06:36:53 +03:00
// message from multiple segments, where the first segment is always a
// fusekernel.OutHeader message.
//
2015-07-28 09:06:23 +03:00
// Must be initialized with Reset.
2015-07-24 07:11:03 +03:00
type OutMessage struct {
2015-07-28 09:06:23 +03:00
offset uintptr
storage [outMessageSize]byte
2015-07-24 06:26:25 +03:00
}
2015-07-28 09:23:10 +03:00
// Make sure alignment works out correctly, at least for the header.
func init() {
a := unsafe.Alignof(OutMessage{})
o := unsafe.Offsetof(OutMessage{}.storage)
e := unsafe.Alignof(fusekernel.OutHeader{})
if a%e != 0 || o%e != 0 {
log.Panicf("Bad alignment or offset: %d, %d, need %d", a, o, e)
}
}
2015-07-28 09:09:27 +03:00
// Reset the message so that it is ready to be used again. Afterward, the
// contents are solely a zeroed header.
func (m *OutMessage) Reset() {
2015-07-28 09:20:50 +03:00
m.offset = outHeaderSize
memclr(unsafe.Pointer(&m.storage), outHeaderSize)
2015-07-24 06:26:25 +03:00
}
2015-07-28 09:09:27 +03:00
// Return a pointer to the header at the start of the message.
2015-07-24 07:11:03 +03:00
func (b *OutMessage) OutHeader() (h *fusekernel.OutHeader) {
2015-07-28 09:23:34 +03:00
h = (*fusekernel.OutHeader)(unsafe.Pointer(&b.storage))
return
2015-07-24 06:26:25 +03:00
}
2015-07-24 06:36:53 +03:00
// Grow the buffer by the supplied number of bytes, returning a pointer to the
2015-07-28 09:09:27 +03:00
// start of the new segment, which is zeroed. If there is no space left, return
// the nil pointer.
2015-07-24 07:11:03 +03:00
func (b *OutMessage) Grow(size uintptr) (p unsafe.Pointer) {
2015-07-28 09:09:27 +03:00
panic("TODO")
2015-07-24 06:36:53 +03:00
}
2015-07-28 09:09:27 +03:00
// Equivalent to Grow, except the new segment is not zeroed. Use with caution!
func (b *OutMessage) GrowNoZero(size uintptr) (p unsafe.Pointer) {
panic("TODO")
}
2015-07-24 06:46:18 +03:00
2015-07-28 09:09:27 +03:00
// Equivalent to growing by the length of p, then copying p over the new
2015-07-28 09:17:56 +03:00
// segment. Panics if there is not enough room available.
2015-07-28 09:09:27 +03:00
func (b *OutMessage) Append(p []byte) {
panic("TODO")
2015-07-24 06:46:18 +03:00
}
2015-07-28 09:09:27 +03:00
// Equivalent to growing by the length of s, then copying s over the new
2015-07-28 09:17:56 +03:00
// segment. Panics if there is not enough room available.
2015-07-24 07:11:03 +03:00
func (b *OutMessage) AppendString(s string) {
2015-07-28 09:09:27 +03:00
panic("TODO")
}
2015-07-24 06:46:18 +03:00
2015-07-28 09:09:27 +03:00
// Return the current size of the buffer.
func (b *OutMessage) Len() int {
panic("TODO")
2015-07-24 06:46:18 +03:00
}
2015-07-24 06:36:53 +03:00
// Return a reference to the current contents of the buffer.
2015-07-24 07:11:03 +03:00
func (b *OutMessage) Bytes() []byte {
2015-07-28 09:09:27 +03:00
panic("TODO")
2015-07-24 06:36:53 +03:00
}