all repos — captcha @ 7b585d44e115cb4e46a6d033adaba32fb0fddd31

Go package captcha implements generation and verification of image and audio CAPTCHAs.

Fix collection (locking and getting next value).
Dmitry Chestnykh dmitry@codingrobots.com
Sun, 24 Apr 2011 15:53:45 +0200
commit

7b585d44e115cb4e46a6d033adaba32fb0fddd31

parent

90e4f7499bd2ad1e8c4e92fb54e97d79fc53e6b5

1 files changed, 5 insertions(+), 3 deletions(-)

jump to
M store.gostore.go

@@ -40,13 +40,12 @@

// saveCaptcha saves the captcha id and the corresponding digits. func (s *store) saveCaptcha(id string, digits []byte) { s.mu.Lock() - defer s.mu.Unlock() s.ids[id] = digits s.exp.PushBack(expValue{time.Seconds(), id}) s.numStored++ + s.mu.Unlock() if s.numStored > s.collectNum { go s.collect() - s.numStored = 0 } }

@@ -79,14 +78,17 @@ func (s *store) collect() {

now := time.Seconds() s.mu.Lock() defer s.mu.Unlock() - for e := s.exp.Front(); e != nil; e = e.Next() { + s.numStored = 0 + for e := s.exp.Front(); e != nil; { ev, ok := e.Value.(expValue) if !ok { return } if ev.timestamp+s.expiration < now { s.ids[ev.id] = nil, false + next := e.Next() s.exp.Remove(e) + e = next } else { return }