Merge pull request #96 from DennisDenuto/denuto/master

plugins/meta/bandwidth: traffic shaping plugin
This commit is contained in:
Gabe Rosenhouse
2018-03-14 08:11:28 -07:00
committed by GitHub
15 changed files with 1619 additions and 5 deletions

View File

@ -68,7 +68,7 @@ var _ = Describe("Echosvr", func() {
Expect(err).NotTo(HaveOccurred())
defer conn.Close()
fmt.Fprintf(conn, "hello")
fmt.Fprintf(conn, "hello\n")
Expect(ioutil.ReadAll(conn)).To(Equal([]byte("hello")))
})
})

View File

@ -7,8 +7,13 @@
package main
import (
"bufio"
"fmt"
"io"
"net"
"os"
"strings"
"time"
)
func main() {
@ -31,8 +36,22 @@ func main() {
}
func handleConnection(conn net.Conn) {
buf := make([]byte, 512)
nBytesRead, _ := conn.Read(buf)
conn.Write(buf[0:nBytesRead])
conn.Close()
conn.SetReadDeadline(time.Now().Add(1 * time.Minute))
content, err := bufio.NewReader(conn).ReadString('\n')
if err != nil && err != io.EOF {
fmt.Fprint(os.Stderr, err.Error())
return
}
conn.SetWriteDeadline(time.Now().Add(1 * time.Minute))
if _, err = conn.Write([]byte(strings.TrimSuffix(content, "\n"))); err != nil {
fmt.Fprint(os.Stderr, err.Error())
return
}
if err = conn.Close(); err != nil {
fmt.Fprint(os.Stderr, err.Error())
return
}
}