libfd

package module
v0.0.0-...-6245abc Latest Latest
Warning

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

Go to latest
Published: Jul 10, 2020 License: Apache-2.0 Imports: 8 Imported by: 0

README

libfd provides a low level Golang FD object that can:

  • Be created from (Dev,Ino) if the file is already open
  • Be used to send or recv (Dev,Inode) across net.UnixConn

Details

Under the covers in Linux (and Posix) everything is an inode.
The pretty file system and socket api we are accustomed to are, in some sense, syntactical sugar coating over that.

Every inode is specified by a (Dev,Ino) pair. On linux these are both uint64.

A file descriptor (fd) is a handle in your process for an inode.

Up at the normal Go library, you have net.Conn and *os.File ... but under the covers: all inodes.

libfd makes all that available and manipulable.

Documentation

Overview

Package libfd provides low level file manipulation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FD

type FD struct {
	Dev       uint64
	Ino       uint64
	FDUintptr uintptr
}

FD - a helpful utility for performing low level actions on a file defined by its Dev and Ino

func FromConn

func FromConn(conn net.Conn) (*FD, error)

FromConn - create and FD for the underlying (Dev,Ino) for a net.Conn. Note: makes a separate file descriptor, so will survive conn.Close

func FromDevIno

func FromDevIno(dev, ino uint64) (*FD, error)

FromDevIno - create FD from (Dev,Ino) - only works if we already have a file open for (Dev,Ino)

func FromFD

func FromFD(fdUintptr uintptr) (*FD, error)

FromFD - makes an FD from a uintptr for underlying file descriptor. Note: makes a copy so will survive close of the original file descriptor

func FromFile

func FromFile(file *os.File) (*FD, error)

FromFile - create and FD for the underlying (Dev,Ino) for a *os.File. Note: makes a separate file descriptor, so will survive file.Close

func FromFilename

func FromFilename(filename string) (*FD, error)

FromFilename - create an FD from a filename.

func FromSyscallRawConn

func FromSyscallRawConn(raw syscall.RawConn) (*FD, error)

FromSyscallRawConn - create and FD for the underlying (Dev,Ino) for a syscall.RawConn. Note: makes a separate file descriptor, so will survive Close of the original thing.

func RecvFromConn

func RecvFromConn(conn net.Conn) (*FD, error)

RecvFromConn - receives a file descriptor over conn if possibleand returns it as an FD. Generally only works for UnixConn

func (*FD) Close

func (fd *FD) Close() error

Close - closes the FD

func (*FD) Dup

func (fd *FD) Dup() (*FD, error)

Dup - creates a duplicate of FD with a distinct file descriptor for the same Dev,Inode

func (*FD) DupFile

func (fd *FD) DupFile() (*os.File, error)

DupFile - creates a duplicate of FD with a distinct file descriptor for the same Dev,Inode and returns it as an *os.File

func (*FD) Filename

func (fd *FD) Filename() string

Filename of FD - returns fmt.Sprintf("/proc/%d/FDUintptr/%d", os.Getpid(), fd.FDUintptr)

func (*FD) SendTo

func (fd *FD) SendTo(conn net.Conn) error

SendTo - Sends this FD as a file descriptor over conn if possible. Generally only works for UnixConn

func (*FD) ToConn

func (fd *FD) ToConn() (net.Conn, error)

ToConn - returns net.Conn for FD *if* FD represents a socket connection

func (*FD) ToFile

func (fd *FD) ToFile() (*os.File, error)

ToFile - Returns file for FD

type FDer

type FDer interface {
	ToFD() *FD
}

FDer - wrapper for things providing ToFD() *FD

Directories

Path Synopsis
internal
imports
DO NOT EDIT - generated by github.com/edwarnicke/imports-gen
DO NOT EDIT - generated by github.com/edwarnicke/imports-gen

Jump to

Keyboard shortcuts

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