https://github.com/hslam/splice
Package splice wraps the splice system call.
https://github.com/hslam/splice
go golang linux pipe socket splice zero-copy zerocopy
Last synced: 23 days ago
JSON representation
Package splice wraps the splice system call.
- Host: GitHub
- URL: https://github.com/hslam/splice
- Owner: hslam
- License: mit
- Created: 2020-12-10T01:05:08.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2021-03-01T07:01:07.000Z (about 4 years ago)
- Last Synced: 2025-03-30T11:32:44.068Z (about 2 months ago)
- Topics: go, golang, linux, pipe, socket, splice, zero-copy, zerocopy
- Language: Go
- Homepage:
- Size: 36.1 KB
- Stars: 16
- Watchers: 3
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# splice
[](https://pkg.go.dev/github.com/hslam/splice)
[](https://github.com/hslam/splice/actions)
[](https://codecov.io/gh/hslam/splice)
[](https://goreportcard.com/report/github.com/hslam/splice)
[](https://github.com/hslam/splice/blob/master/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
```go
package mainimport (
"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.