Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

Package splice wraps the splice system call.

License

NotificationsYou must be signed in to change notification settings

hslam/splice

Repository files navigation

PkgGoDevBuild StatuscodecovGo Report CardLICENSE

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 mainimport ("fmt""github.com/hslam/splice""io""net""time")funcmain() {contents:="Hello world"lis,err:=net.Listen("tcp",":9999")iferr!=nil {panic(err)}deferlis.Close()done:=make(chanbool)gofunc() {conn,_:=lis.Accept()deferconn.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.


[8]ページ先頭

©2009-2025 Movatter.jp