Skip to content

Commit

Permalink
Added function to get the request ID.
Browse files Browse the repository at this point in the history
  • Loading branch information
John Mac authored and mikejs committed Jun 23, 2010
1 parent fdd2f0d commit d652cfe
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions mongo/main.go
Original file line number Original file line Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2009,2010 The 'gomongo' Authors. All rights reserved. // Copyright 2010 The 'gomongo' Authors. All rights reserved.
// Use of this source code is governed by the New BSD License // Use of this source code is governed by the New BSD License
// that can be found in the LICENSE file. // that can be found in the LICENSE file.


Expand All @@ -14,6 +14,8 @@ import (
// Like BSON documents, all data in the mongo wire protocol is little-endian. // Like BSON documents, all data in the mongo wire protocol is little-endian.
var pack = binary.LittleEndian var pack = binary.LittleEndian


var lastRequestID int32



func init() { func init() {
// Uses the 'urandom' device to get a seed which will be used by 'rand'. // Uses the 'urandom' device to get a seed which will be used by 'rand'.
Expand All @@ -32,8 +34,17 @@ func init() {
// *** Utility functions // *** Utility functions
// *** // ***


func randToi32() int32 { /* Gets a random request identifier different to the last one.
return rand.Int31() */
func getRequestID() int32 {
id := rand.Int31()

if id == lastRequestID {
return getRequestID()
}
lastRequestID = id

return id
} }


// *** Bits data // *** Bits data
Expand Down

0 comments on commit d652cfe

Please sign in to comment.