Skip to content

Commit

Permalink
feat: expose TransportBufferSize for more control how much buffering …
Browse files Browse the repository at this point in the history
…should be used when reading from connection #145
  • Loading branch information
emiago committed Dec 5, 2024
1 parent 8710278 commit 56322bf
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 5 deletions.
5 changes: 3 additions & 2 deletions sip/transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ var (
// 0 - close connection immediatelly after transaction terminate
// 1 - keep connection idle after transaction termination
IdleConnection int = 1

// TransportBufferSize sets this buffer size to use on reading SIP messages.
TransportBufferSize uint16 = 65535
)

const (
Expand All @@ -34,8 +37,6 @@ const (
TransportWS = "WS"
TransportWSS = "WSS"

transportBufferSize uint16 = 65535

// TransportFixedLengthMessage sets message size limit for parsing and avoids stream parsing
TransportFixedLengthMessage uint16 = 0
)
Expand Down
2 changes: 1 addition & 1 deletion sip/transport_tcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ func (t *transportTCP) initConnection(conn net.Conn, raddr string, handler Messa

// This should performe better to avoid any interface allocation
func (t *transportTCP) readConnection(conn *TCPConnection, laddr string, raddr string, handler MessageHandler) {
buf := make([]byte, transportBufferSize)
buf := make([]byte, TransportBufferSize)
defer t.pool.Delete(laddr)
defer t.pool.CloseAndDelete(conn, raddr)

Expand Down
2 changes: 1 addition & 1 deletion sip/transport_udp.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ func (t *transportUDP) readUDPConnection(conn *UDPConnection, raddr string, ladd
} */

func (t *transportUDP) readListenerConnection(conn *UDPConnection, laddr string, handler MessageHandler) {
buf := make([]byte, transportBufferSize)
buf := make([]byte, TransportBufferSize)
defer t.pool.CloseAndDelete(conn, laddr)
defer t.log.Debug().Str("addr", laddr).Msg("Read listener connection stopped")

Expand Down
2 changes: 1 addition & 1 deletion sip/transport_ws.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ func (t *transportWS) initConnection(conn net.Conn, raddr string, clientSide boo

// This should performe better to avoid any interface allocation
func (t *transportWS) readConnection(conn *WSConnection, laddr string, raddr string, handler MessageHandler) {
buf := make([]byte, transportBufferSize)
buf := make([]byte, TransportBufferSize)
// defer conn.Close()
// defer t.pool.Del(raddr)
defer t.pool.Delete(laddr)
Expand Down

0 comments on commit 56322bf

Please sign in to comment.