@@ -17,18 +17,27 @@ import (
1717)
1818
1919const (
20- MessageQuit = 0
21- MessageRequest = 1
20+ // MessageQuit causes the processMessages loop to exit
21+ MessageQuit = 0
22+ // MessageRequest sends a request to the server
23+ MessageRequest = 1
24+ // MessageResponse receives a response from the server
2225 MessageResponse = 2
23- MessageFinish = 3
24- MessageTimeout = 4
26+ // MessageFinish indicates the client considers a particular message ID to be finished
27+ MessageFinish = 3
28+ // MessageTimeout indicates the client-specified timeout for a particular message ID has been reached
29+ MessageTimeout = 4
2530)
2631
32+ // PacketResponse contains the packet or error encountered reading a response
2733type PacketResponse struct {
34+ // Packet is the packet read from the server
2835 Packet * ber.Packet
29- Error error
36+ // Error is an error encountered while reading
37+ Error error
3038}
3139
40+ // ReadPacket returns the packet or an error
3241func (pr * PacketResponse ) ReadPacket () (* ber.Packet , error ) {
3342 if (pr == nil ) || (pr .Packet == nil && pr .Error == nil ) {
3443 return nil , NewError (ErrorNetwork , errors .New ("ldap: could not retrieve response" ))
@@ -37,8 +46,10 @@ func (pr *PacketResponse) ReadPacket() (*ber.Packet, error) {
3746}
3847
3948type messageContext struct {
40- id int64
41- done chan struct {}
49+ id int64
50+ // close(done) should only be called from finishMessage()
51+ done chan struct {}
52+ // close(responses) should only be called from processMessages(), and only sent to from sendResponse()
4253 responses chan * PacketResponse
4354}
4455
@@ -140,6 +151,7 @@ func NewConn(conn net.Conn, isTLS bool) *Conn {
140151 }
141152}
142153
154+ // Start initializes goroutines to read responses and process messages
143155func (l * Conn ) Start () {
144156 go l .reader ()
145157 go l .processMessages ()
@@ -167,7 +179,7 @@ func (l *Conn) Close() {
167179 l .wgClose .Wait ()
168180}
169181
170- // Sets the time after a request is sent that a MessageTimeout triggers
182+ // SetTimeout sets the time after a request is sent that a MessageTimeout triggers
171183func (l * Conn ) SetTimeout (timeout time.Duration ) {
172184 if timeout > 0 {
173185 l .requestTimeout = timeout
@@ -253,15 +265,14 @@ func (l *Conn) sendMessageWithFlags(packet *ber.Packet, flags sendMessageFlags)
253265 l .Debug .Printf ("flags&startTLS = %d" , flags & startTLS )
254266 if l .isStartingTLS {
255267 l .messageMutex .Unlock ()
256- return nil , NewError (ErrorNetwork , errors .New ("ldap: connection is in startls phase. " ))
268+ return nil , NewError (ErrorNetwork , errors .New ("ldap: connection is in startls phase" ))
257269 }
258270 if flags & startTLS != 0 {
259271 if l .outstandingRequests != 0 {
260272 l .messageMutex .Unlock ()
261273 return nil , NewError (ErrorNetwork , errors .New ("ldap: cannot StartTLS with outstanding requests" ))
262- } else {
263- l .isStartingTLS = true
264274 }
275+ l .isStartingTLS = true
265276 }
266277 l .outstandingRequests ++
267278
0 commit comments