~rogpeppe/+junk/mgo-tagged-log-messages

« back to all changes in this revision

Viewing changes to socket.go

  • Committer: Roger Peppe
  • Date: 2014-03-14 18:11:33 UTC
  • mfrom: (263.1.8 master)
  • Revision ID: roger.peppe@canonical.com-20140314181133-107ag3xpitk9682u
merge trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
46
46
        nextRequestId uint32
47
47
        replyFuncs    map[uint32]replyFunc
48
48
        references    int
49
 
        auth          []authInfo
50
 
        logout        []authInfo
 
49
        creds         []Credential
 
50
        logout        []Credential
51
51
        cachedNonce   string
52
52
        gotNonce      sync.Cond
53
53
        dead          error
303
303
        server := socket.server
304
304
        socket.server = nil
305
305
        socket.Unlock()
306
 
        for _, f := range replyFuncs {
 
306
        for _, replyFunc := range replyFuncs {
307
307
                socket.logf("Socket %p to %s: notifying replyFunc of closed socket: %s", socket, socket.addr, err.Error())
308
 
                f(err, nil, -1, nil)
 
308
                replyFunc(err, nil, -1, nil)
309
309
        }
310
310
        if abend {
311
311
                server.AbendSocket(socket)
428
428
                        }
429
429
 
430
430
                default:
431
 
                        panic("Internal error: unknown operation type")
 
431
                        panic("internal error: unknown operation type")
432
432
                }
433
433
 
434
434
                setInt32(buf, start, int32(len(buf)-start))
537
537
                stats.receivedDocs(int(reply.replyDocs))
538
538
 
539
539
                socket.Lock()
540
 
                replyFunc, replyFuncFound := socket.replyFuncs[uint32(responseTo)]
 
540
                replyFunc, ok := socket.replyFuncs[uint32(responseTo)]
 
541
                if ok {
 
542
                        delete(socket.replyFuncs, uint32(responseTo))
 
543
                }
541
544
                socket.Unlock()
542
545
 
543
546
                if replyFunc != nil && reply.replyDocs == 0 {
546
549
                        for i := 0; i != int(reply.replyDocs); i++ {
547
550
                                err := fill(conn, s)
548
551
                                if err != nil {
 
552
                                        if replyFunc != nil {
 
553
                                                replyFunc(err, nil, -1, nil)
 
554
                                        }
549
555
                                        socket.kill(err, true)
550
556
                                        return
551
557
                                }
560
566
 
561
567
                                err = fill(conn, b[4:])
562
568
                                if err != nil {
 
569
                                        if replyFunc != nil {
 
570
                                                replyFunc(err, nil, -1, nil)
 
571
                                        }
563
572
                                        socket.kill(err, true)
564
573
                                        return
565
574
                                }
579
588
                        }
580
589
                }
581
590
 
582
 
                // Only remove replyFunc after iteration, so that kill() will see it.
583
591
                socket.Lock()
584
 
                if replyFuncFound {
585
 
                        delete(socket.replyFuncs, uint32(responseTo))
586
 
                }
587
592
                if len(socket.replyFuncs) == 0 {
588
593
                        // Nothing else to read for now. Disable deadline.
589
594
                        socket.conn.SetReadDeadline(time.Time{})