Documentation
¶
Index ¶
- Constants
- Variables
- func Bytes2String(b []byte) string
- func CmdAndChangeDirToShow(commandName string, params []string, key int64) (error, bool)
- func Decode(data []byte, v interface{}, codec ...string) error
- func DestroySegment(id int64) error
- func Encode(v interface{}, codec ...string) ([]byte, error)
- func HasKeyofSHM(key int64) bool
- func Readtlv(k int64)
- func RegisterConverter(codec string, c Converter) error
- func SHMInfoStructToBytes(s *SHMInfo) []byte
- func SizeStruct(data interface{}) int
- func StartSubscribe(key int64, callBack TLVCallBack) bool
- func StringToByteArr(s string, arr []byte)
- func TagTLVStructToBytes(s *TagTLV) []byte
- func UpdateCtx(shmparam CreateSHMParam, updatectx UpdateContent) (index int, err error)
- type ConsumerHandler
- type ContentData
- type Converter
- type CreateSHMParam
- type DefaultConverter
- type HeadData
- type MemBlock
- type MemChain
- type SHMInfo
- type Segment
- func Create(size int64) (*Segment, error)
- func CreateWithKey(key, size int64) (*Segment, error)
- func Open(id int64) (*Segment, error)
- func OpenSegment(size int64, flags SharedMemoryFlags, perms os.FileMode) (*Segment, error)
- func OpenSegmentWithKey(key, size int64, flags SharedMemoryFlags, perms os.FileMode) (*Segment, error)
- func (s *Segment) Attach() (unsafe.Pointer, error)
- func (s *Segment) Destroy() error
- func (s *Segment) Detach() error
- func (s *Segment) GetBytes(key interface{}) ([]byte, error)
- func (s *Segment) IsAttached() bool
- func (s *Segment) Position() int64
- func (s *Segment) Read(p []byte) (n int, err error)
- func (s *Segment) ReadChunk(length int64, start int64) ([]byte, error)
- func (s *Segment) ReadChunkWithoutAttach(length int64, start int64) ([]byte, error)
- func (s *Segment) ReadObj(key *interface{}) (n int, err error)
- func (s *Segment) Reset()
- func (s *Segment) Seek(offset int64, whence int) (int64, error)
- func (s *Segment) Write(p []byte) (n int, err error)
- func (s *Segment) WriteObj(key interface{}) (n int, err error)
- type SharedMemoryFlags
- type ShmCmdEnum
- type ShmCommand
- type ShmConsumerStatus
- type ShmDataBlockConsumer
- func (consumer *ShmDataBlockConsumer) AutoNext() (*TagTLV, ShmConsumerStatus)
- func (consumer *ShmDataBlockConsumer) Close()
- func (consumer *ShmDataBlockConsumer) Detach() error
- func (consumer *ShmDataBlockConsumer) GetCmdChannel() chan ShmCommand
- func (consumer *ShmDataBlockConsumer) Init(key int64, maxSHMSize uint64, maxContentLen uint64, handler ConsumerHandler) (bool, error)
- func (consumer *ShmDataBlockConsumer) Next() (*TagTLV, ShmConsumerStatus)
- func (consumer *ShmDataBlockConsumer) Reset()
- func (consumer *ShmDataBlockConsumer) Start() bool
- type ShmManager
- func (sm *ShmManager) DeleteBlock(blockName string) error
- func (sm *ShmManager) Init() (err error)
- func (sm *ShmManager) InitWithKey(key, usedBlockSize int64) (err error)
- func (sm *ShmManager) ReadBlock(blockName string) ([]byte, error)
- func (sm *ShmManager) Show()
- func (sm *ShmManager) WriteBlock(blockName string, data []byte) (int, error)
- type ShmSubscriber
- type Stack
- type TLVCallBack
- type TagTL
- type TagTLV
- type UpdateContent
Constants ¶
const ( IpcNone = 0 IpcCreate SharedMemoryFlags = C.IPC_CREAT IpcExclusive = C.IPC_EXCL HugePages = C.SHM_HUGETLB NoReserve = C.SHM_NORESERVE )
Variables ¶
var Counter int64 = 0
var DEBUG bool
DEBUG decide print some debug info or not
var MCL uint = 102400
var MTL uint = 64
var ST1 time.Time
var ST2 time.Time
Functions ¶
func Bytes2String ¶
func CmdAndChangeDirToShow ¶
func DestroySegment ¶
DestroySegment destroy a shared memory segment by its ID
func HasKeyofSHM ¶
func RegisterConverter ¶
RegisterConverter ...
func SHMInfoStructToBytes ¶
func SizeStruct ¶
func SizeStruct(data interface{}) int
func StartSubscribe ¶
func StartSubscribe(key int64, callBack TLVCallBack) bool
func StringToByteArr ¶
func TagTLVStructToBytes ¶
func UpdateCtx ¶
func UpdateCtx(shmparam CreateSHMParam, updatectx UpdateContent) (index int, err error)
Types ¶
type ConsumerHandler ¶
type ContentData ¶
type Converter ¶
type Converter interface { Marshal(interface{}) ([]byte, error) Unmarshal([]byte, interface{}) error }
Converter is the interface to convert obj to []byte
type CreateSHMParam ¶
type DefaultConverter ¶
type DefaultConverter struct{}
DefaultConverter is the default Converter using reflect
func (DefaultConverter) Marshal ¶
func (df DefaultConverter) Marshal(v interface{}) ([]byte, error)
Marshal ...
func (DefaultConverter) Unmarshal ¶
func (df DefaultConverter) Unmarshal(data []byte, v interface{}) error
Unmarshal ...
type HeadData ¶
func GetHeadData ¶
type SHMInfo ¶
type SHMInfo struct { MaxTopicLen uint64 MaxContentLen uint64 MaxSHMSize uint64 Count uint64 Key [200]int32 }
todo this will read from key of 999999 SHM typedef struct SHMInfo{ unsigned long long max_topic_len; unsigned long long max_content_len; unsigned long long max_shm_size; unsigned long long count; key_t key[200]; }SHMI;
func BytesToSHMInfoStruct ¶
type Segment ¶
Segment is a native representation of a SysV shared memory segment
func Create ¶
Create a new shared memory segment with the given size (in bytes). The system will automatically round the size up to the nearest memory page boundary (typically 4KB).
func CreateWithKey ¶
func Open ¶
Open an existing shared memory segment located at the given ID. This ID is returned in the struct that is populated by Create(), or by the shmget() system call.
func OpenSegment ¶
OpenSegment creates a shared memory segment of a given size, and also allows for the specification of creation flags supported by the shmget() call, as well as specifying permissions.
func OpenSegmentWithKey ¶
func (*Segment) Attach ¶
Attaches the segment to the current processes resident memory. The pointer that is returned is the actual memory address of the shared memory segment for use with third party libraries that can directly read from memory.
func (*Segment) IsAttached ¶
func (*Segment) ReadChunk ¶
ReadChunk reads some or all of the shared memory segment and return a byte slice.
func (*Segment) ReadChunkWithoutAttach ¶
func (*Segment) Reset ¶
func (s *Segment) Reset()
Resets the internal offset counter for this segment, allowing subsequent calls to Read() or Write() to start from the beginning.
func (*Segment) Seek ¶
Implements the io.Seeker interface for shared memory. Subsequent calls to Read() or Write() will start from this position.
type SharedMemoryFlags ¶
type SharedMemoryFlags int
type ShmCmdEnum ¶
type ShmCmdEnum int32
const ( ShmCmdOK ShmCmdEnum = 0 ShmCmdUnAttach ShmCmdEnum = 1 ShmCmdStop ShmCmdEnum = 2 )
type ShmCommand ¶
type ShmCommand struct {
// contains filtered or unexported fields
}
type ShmConsumerStatus ¶
type ShmConsumerStatus int32
const ( ShmConsumerOk ShmConsumerStatus = 0 ShmConsumerReadErr ShmConsumerStatus = 1 ShmConsumerLenErr ShmConsumerStatus = 2 ShmConsumerInitErr ShmConsumerStatus = 3 ShmConsumerNoData ShmConsumerStatus = 4 ShmConsumerUnAttached ShmConsumerStatus = 5 )
type ShmDataBlockConsumer ¶
type ShmDataBlockConsumer struct { PreTag uint64 CurTag uint64 TopicLen uint64 MaxContentLen uint64 MaxShmSize uint64 CurOffset uint64 PreOffset uint64 SegLen uint64 ShmKey int64 IsRunning bool // contains filtered or unexported fields }
func (*ShmDataBlockConsumer) AutoNext ¶
func (consumer *ShmDataBlockConsumer) AutoNext() (*TagTLV, ShmConsumerStatus)
func (*ShmDataBlockConsumer) Close ¶
func (consumer *ShmDataBlockConsumer) Close()
func (*ShmDataBlockConsumer) Detach ¶
func (consumer *ShmDataBlockConsumer) Detach() error
func (*ShmDataBlockConsumer) GetCmdChannel ¶
func (consumer *ShmDataBlockConsumer) GetCmdChannel() chan ShmCommand
func (*ShmDataBlockConsumer) Init ¶
func (consumer *ShmDataBlockConsumer) Init(key int64, maxSHMSize uint64, maxContentLen uint64, handler ConsumerHandler) (bool, error)
func (*ShmDataBlockConsumer) Next ¶
func (consumer *ShmDataBlockConsumer) Next() (*TagTLV, ShmConsumerStatus)
func (*ShmDataBlockConsumer) Reset ¶
func (consumer *ShmDataBlockConsumer) Reset()
func (*ShmDataBlockConsumer) Start ¶
func (consumer *ShmDataBlockConsumer) Start() bool
type ShmManager ¶
type ShmManager struct {
// contains filtered or unexported fields
}
ShmManager is a tool to manager shm
func (*ShmManager) DeleteBlock ¶
func (sm *ShmManager) DeleteBlock(blockName string) error
DeleteBlock ...
func (*ShmManager) InitWithKey ¶
func (sm *ShmManager) InitWithKey(key, usedBlockSize int64) (err error)
func (*ShmManager) ReadBlock ¶
func (sm *ShmManager) ReadBlock(blockName string) ([]byte, error)
ReadBlock ...
func (*ShmManager) WriteBlock ¶
func (sm *ShmManager) WriteBlock(blockName string, data []byte) (int, error)
WriteBlock ...
type ShmSubscriber ¶
type ShmSubscriber struct {
// contains filtered or unexported fields
}
func (*ShmSubscriber) Close ¶
func (subscriber *ShmSubscriber) Close()
func (*ShmSubscriber) Init ¶
func (subscriber *ShmSubscriber) Init(confShmId int64, handler ConsumerHandler)
func (*ShmSubscriber) Start ¶
func (subscriber *ShmSubscriber) Start()
type TLVCallBack ¶
type TLVCallBack func(*TagTLV)
type TagTLV ¶
type TagTLV struct { Tag int64 Len uint64 TopicLen uint16 EventTypeLen uint16 Topic [30]byte EventType [30]byte Value [40960]byte }
func BytesToTagTLVStruct ¶
type UpdateContent ¶
func GetCtx ¶
func GetCtx(shmparam CreateSHMParam) (*UpdateContent, error)