mirror of
https://github.com/fatedier/frp.git
synced 2025-07-10 07:49:34 +07:00
more e2e tests (#1845)
This commit is contained in:
@ -6,26 +6,35 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
func SendTCPRequest(port int, content []byte, timeout time.Duration) (res string, err error) {
|
||||
func SendTCPRequest(port int, content []byte, timeout time.Duration) (string, error) {
|
||||
c, err := net.Dial("tcp", fmt.Sprintf("127.0.0.1:%d", port))
|
||||
if err != nil {
|
||||
err = fmt.Errorf("connect to tcp server error: %v", err)
|
||||
return
|
||||
return "", fmt.Errorf("connect to tcp server error: %v", err)
|
||||
}
|
||||
defer c.Close()
|
||||
|
||||
c.SetDeadline(time.Now().Add(timeout))
|
||||
return sendTCPRequestByConn(c, content)
|
||||
return sendRequestByConn(c, content)
|
||||
}
|
||||
|
||||
func sendTCPRequestByConn(c net.Conn, content []byte) (res string, err error) {
|
||||
func SendUDPRequest(port int, content []byte, timeout time.Duration) (string, error) {
|
||||
c, err := net.Dial("udp", fmt.Sprintf("127.0.0.1:%d", port))
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("connect to udp server error: %v", err)
|
||||
}
|
||||
defer c.Close()
|
||||
|
||||
c.SetDeadline(time.Now().Add(timeout))
|
||||
return sendRequestByConn(c, content)
|
||||
}
|
||||
|
||||
func sendRequestByConn(c net.Conn, content []byte) (string, error) {
|
||||
c.Write(content)
|
||||
|
||||
buf := make([]byte, 2048)
|
||||
n, errRet := c.Read(buf)
|
||||
if errRet != nil {
|
||||
err = fmt.Errorf("read from tcp error: %v", errRet)
|
||||
return
|
||||
n, err := c.Read(buf)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("read error: %v", err)
|
||||
}
|
||||
return string(buf[:n]), nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user