|
@@ -6,11 +6,11 @@ import (
|
|
|
"time"
|
|
|
)
|
|
|
|
|
|
-
|
|
|
-type ConnectionReadOptions func(conn net.Conn) error
|
|
|
+
|
|
|
+type connectionReadOptions func(conn net.Conn) error
|
|
|
|
|
|
-
|
|
|
-func WithReadDeadline(duration time.Duration) ConnectionReadOptions {
|
|
|
+
|
|
|
+func withReadDeadline(duration time.Duration) connectionReadOptions {
|
|
|
return func(conn net.Conn) error {
|
|
|
if duration == 0 {
|
|
|
return nil
|
|
@@ -25,11 +25,11 @@ func WithReadDeadline(duration time.Duration) ConnectionReadOptions {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-type ConnectionWriteOptions func(conn net.Conn) error
|
|
|
+
|
|
|
+type connectionWriteOptions func(conn net.Conn) error
|
|
|
|
|
|
-
|
|
|
-func WithWriteDeadline(duration time.Duration) ConnectionWriteOptions {
|
|
|
+
|
|
|
+func withWriteDeadline(duration time.Duration) connectionWriteOptions {
|
|
|
return func(conn net.Conn) error {
|
|
|
if duration == 0 {
|
|
|
return nil
|
|
@@ -45,7 +45,7 @@ func WithWriteDeadline(duration time.Duration) ConnectionWriteOptions {
|
|
|
}
|
|
|
|
|
|
|
|
|
-func readUDP(conn *net.UDPConn, bufferSize int, opts ...ConnectionReadOptions) ([]byte, *net.UDPAddr, error) {
|
|
|
+func readUDP(conn *net.UDPConn, bufferSize int, opts ...connectionReadOptions) ([]byte, *net.UDPAddr, error) {
|
|
|
buffer := make([]byte, bufferSize)
|
|
|
|
|
|
for _, opt := range opts {
|
|
@@ -64,7 +64,7 @@ func readUDP(conn *net.UDPConn, bufferSize int, opts ...ConnectionReadOptions) (
|
|
|
}
|
|
|
|
|
|
|
|
|
-func writeUDPWithRemoteAddr(conn *net.UDPConn, rAddr *net.UDPAddr, data []byte, opts ...ConnectionWriteOptions) error {
|
|
|
+func writeUDPWithRemoteAddr(conn *net.UDPConn, rAddr *net.UDPAddr, data []byte, opts ...connectionWriteOptions) error {
|
|
|
for _, opt := range opts {
|
|
|
err := opt(conn)
|
|
|
if err != nil {
|
|
@@ -81,7 +81,7 @@ func writeUDPWithRemoteAddr(conn *net.UDPConn, rAddr *net.UDPAddr, data []byte,
|
|
|
}
|
|
|
|
|
|
|
|
|
-func WriteUDP(conn *net.UDPConn, data []byte, opts ...ConnectionWriteOptions) error {
|
|
|
+func WriteUDP(conn *net.UDPConn, data []byte, opts ...connectionWriteOptions) error {
|
|
|
for _, opt := range opts {
|
|
|
err := opt(conn)
|
|
|
if err != nil {
|
|
@@ -98,7 +98,7 @@ func WriteUDP(conn *net.UDPConn, data []byte, opts ...ConnectionWriteOptions) er
|
|
|
}
|
|
|
|
|
|
|
|
|
-func ReadTCP(conn net.Conn, bufferSize int, readCallback func(data []byte) (bool, error), opts ...ConnectionReadOptions) error {
|
|
|
+func ReadTCP(conn net.Conn, bufferSize int, readCallback func(data []byte) (bool, error), opts ...connectionReadOptions) error {
|
|
|
for {
|
|
|
buffer := make([]byte, bufferSize)
|
|
|
|
|
@@ -128,7 +128,7 @@ func ReadTCP(conn net.Conn, bufferSize int, readCallback func(data []byte) (bool
|
|
|
}
|
|
|
|
|
|
|
|
|
-func WriteTCP(conn net.Conn, data []byte, opts ...ConnectionWriteOptions) error {
|
|
|
+func WriteTCP(conn net.Conn, data []byte, opts ...connectionWriteOptions) error {
|
|
|
writeBytesCount := 0
|
|
|
|
|
|
for {
|