Skip to content

TCP connection implementation with rate limit in mind.

Notifications You must be signed in to change notification settings

slavash/throttled

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Throttled

TCP networking listener implementation with rate limit in mind

Usage

l, err := net.Listen("tcp4", "localhost:8080")
if err != nil {
    fmt.Println(err)
    return
}

limited := throttled.NewListener(l)
limited.SetLimits(serverLimitBytePerSec, connLimitBytePerSec)

defer func() {
    if e := limited.Close(); e != nil {
        fmt.Printf("faield to shotdown the server: %s\n", e)
    }
}()

fmt.Printf("Listening on %s\n", l.Addr())

for {
    c, err := limited.Accept()
    if err != nil {
        fmt.Println(err)
        return
    }

    go handleConnection(c)
}

About

TCP connection implementation with rate limit in mind.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages