shmstream

package module
v0.0.0-...-52bb1dd Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 7, 2025 License: MIT Imports: 9 Imported by: 1

README

shmstream

A go library for a shared memory data streamer. Its supposed to be fast...

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	BufferSize    uint32
	Bidirectional bool
}

type Reader

type Reader struct {
	// contains filtered or unexported fields
}

func (*Reader) Read

func (r *Reader) Read(p []byte) (n int, err error)

type StreamBuffer

type StreamBuffer struct {
	// contains filtered or unexported fields
}

func New

func New(config Config) (*StreamBuffer, error)

Creates a shared memory block and maps it to the current process. Returns a StreamBuffer representing the memory.

Note: See Open for details on how to use this.

func Open

func Open(path string) (*StreamBuffer, error)

Maps memory pointed by path to the current process. Returns a StreamBuffer representing the memory.

Use case: You created a StreamBuffer with New, and now wants to share it with another process. So, you'd use call Open in the second process with path argument as what is returned by calling [Path] on StreamBuffer in the first process. Basically:

  1. In first process, call New and get StreamBuffer
  2. Call [Path] on that StreamBuffer and send it to the second process (using environment variable, file, etc. go figure)
  3. In second process, call Open with the path sent by first process.
  4. Now you have a structure representing the same memory in both processes. Do your thing with [NewReader] or [NewWriter]

func (*StreamBuffer) BufferSize

func (s *StreamBuffer) BufferSize() uint32

func (*StreamBuffer) Close

func (s *StreamBuffer) Close()

Unmaps the shared memory from the process and closes the file descriptor pointing to the memory

func (*StreamBuffer) Fd

func (s *StreamBuffer) Fd() uintptr

Return the File Descriptor of the shared memory file (which is an anonymous file in our case, see manpage of memfd_create) opened by the process

func (*StreamBuffer) HalfBufferSize

func (s *StreamBuffer) HalfBufferSize() uint32

func (*StreamBuffer) IsBidirectional

func (s *StreamBuffer) IsBidirectional() bool

func (*StreamBuffer) NewReader

func (s *StreamBuffer) NewReader() (io.Reader, error)

func (*StreamBuffer) NewWriter

func (s *StreamBuffer) NewWriter() (io.Writer, error)

func (*StreamBuffer) Path

func (s *StreamBuffer) Path() string

This function only returns correct result when being called by an instance returned by New i.e. from the process which called memfd_create

type Writer

type Writer struct {
	// contains filtered or unexported fields
}

func (*Writer) Write

func (w *Writer) Write(p []byte) (n int, err error)

Directories

Path Synopsis
internal
futex
package futex implements wrappers for futex system call.
package futex implements wrappers for futex system call.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL