splice

package module
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Mar 1, 2021 License: MIT Imports: 8 Imported by: 4

README

splice

PkgGoDev Build Status codecov Go Report Card LICENSE

Package splice wraps the splice system call.

Get started

Install
go get github.com/hslam/splice
Import
import "github.com/hslam/splice"
Usage
Example
package main

import (
	"fmt"
	"github.com/hslam/splice"
	"io"
	"net"
	"time"
)

func main() {
	contents := "Hello world"
	lis, err := net.Listen("tcp", ":9999")
	if err != nil {
		panic(err)
	}
	defer lis.Close()
	done := make(chan bool)
	go func() {
		conn, _ := lis.Accept()
		defer conn.Close()
		time.Sleep(time.Millisecond * 100)
		if _, err := splice.Splice(conn, conn, 1024); err != nil && err != io.EOF {
			panic(err)
		}
		close(done)
	}()
	conn, _ := net.Dial("tcp", "127.0.0.1:9999")
	conn.Write([]byte(contents))
	buf := make([]byte, 64)
	n, _ := conn.Read(buf)
	fmt.Println(string(buf[:n]))
	conn.Close()
	<-done
}
Output
Hello world
License

This package is licensed under a MIT license (Copyright (c) 2020 Meng Huang)

Author

splice was written by Meng Huang.

Documentation

Overview

Package splice wraps the splice system call.

Index

Constants

View Source
const (

	// EAGAIN will be returned when resource temporarily unavailable.
	EAGAIN = syscall.EAGAIN
)

Variables

View Source
var (

	// EOF is the error returned by Read when no more input is available.
	// Functions should return EOF only to signal a graceful end of input.
	// If the EOF occurs unexpectedly in a structured data stream,
	// the appropriate error is either ErrUnexpectedEOF or some other error
	// giving more detail.
	EOF = io.EOF

	// ErrNotHandled will be returned when the splice is not supported.
	ErrNotHandled = errors.New("The splice is not supported")
)
View Source
var ErrSyscallConn = errors.New("The net.Conn do not implements the syscall.Conn interface")

ErrSyscallConn will be returned when the net.Conn do not implements the syscall.Conn interface.

Functions

func MaxIdleContextsPerBucket added in v1.0.3

func MaxIdleContextsPerBucket(max int)

MaxIdleContextsPerBucket sets the maxIdleContexts per bucket.

func Splice

func Splice(dst, src net.Conn, len int64) (n int64, err error)

Splice wraps the splice system call.

splice() moves data between two file descriptors without copying between kernel address space and user address space. It transfers up to len bytes of data from the file descriptor rfd to the file descriptor wfd, where one of the descriptors must refer to a pipe.

Types

This section is empty.

Jump to

Keyboard shortcuts

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