PkgGoDev Build Status codecov Go Report Card LICENSE
Package splice wraps the splice system call.
go get github.com/hslam/splice
import "github.com/hslam/splice"
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 }
Hello world
This package is licensed under a MIT license (Copyright (c) 2020 Meng Huang)
splice was written by Meng Huang.