Skip to content

Commit

Permalink
introduce buffering for connection reader (go-ldap#299)
Browse files Browse the repository at this point in the history
Since asn1-ber ends up reading single bytes, we wrap the network
connection into a buffered reader to avoid a syscall for every read.

Co-authored-by: David Bimmler <[email protected]>
Co-authored-by: John Weldon <[email protected]>
  • Loading branch information
3 people authored Dec 22, 2020
1 parent 28651e0 commit c9551dc
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 3 additions & 1 deletion conn.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package ldap

import (
"bufio"
"crypto/tls"
"errors"
"fmt"
Expand Down Expand Up @@ -532,12 +533,13 @@ func (l *Conn) reader() {
}
}()

bufConn := bufio.NewReader(l.conn)
for {
if cleanstop {
l.Debug.Printf("reader clean stopping (without closing the connection)")
return
}
packet, err := ber.ReadPacket(l.conn)
packet, err := ber.ReadPacket(bufConn)
if err != nil {
// A read error is expected here if we are closing the connection...
if !l.IsClosing() {
Expand Down
4 changes: 3 additions & 1 deletion v3/conn.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package ldap

import (
"bufio"
"crypto/tls"
"errors"
"fmt"
Expand Down Expand Up @@ -532,12 +533,13 @@ func (l *Conn) reader() {
}
}()

bufConn := bufio.NewReader(l.conn)
for {
if cleanstop {
l.Debug.Printf("reader clean stopping (without closing the connection)")
return
}
packet, err := ber.ReadPacket(l.conn)
packet, err := ber.ReadPacket(bufConn)
if err != nil {
// A read error is expected here if we are closing the connection...
if !l.IsClosing() {
Expand Down

0 comments on commit c9551dc

Please sign in to comment.