new feature plugin and unix domian socket plugin

This commit is contained in:
fatedier
2017-05-21 22:42:42 +08:00
parent faf584e1dd
commit 738e5dad22
12 changed files with 274 additions and 26 deletions

View File

@@ -4,12 +4,15 @@ import (
"bufio"
"fmt"
"io"
"net"
"os"
"syscall"
"github.com/fatedier/frp/utils/net"
frpNet "github.com/fatedier/frp/utils/net"
)
func StartEchoServer() {
l, err := net.ListenTcp("127.0.0.1", 10701)
l, err := frpNet.ListenTcp("127.0.0.1", 10701)
if err != nil {
fmt.Printf("echo server listen error: %v\n", err)
return
@@ -27,7 +30,7 @@ func StartEchoServer() {
}
func StartUdpEchoServer() {
l, err := net.ListenUDP("127.0.0.1", 10703)
l, err := frpNet.ListenUDP("127.0.0.1", 10703)
if err != nil {
fmt.Printf("udp echo server listen error: %v\n", err)
return
@@ -44,6 +47,27 @@ func StartUdpEchoServer() {
}
}
func StartUnixDomainServer() {
unixPath := "/tmp/frp_echo_server.sock"
os.Remove(unixPath)
syscall.Umask(0)
l, err := net.Listen("unix", unixPath)
if err != nil {
fmt.Printf("unix domain server listen error: %v\n", err)
return
}
for {
c, err := l.Accept()
if err != nil {
fmt.Printf("unix domain server accept error: %v\n", err)
return
}
go echoWorker(c)
}
}
func echoWorker(c net.Conn) {
br := bufio.NewReader(c)
for {