Permalink
Browse files

Added function to get the request ID.

  • Loading branch information...
1 parent fdd2f0d commit d652cfe6f85eec7df57c5ecf0f1453a134c0a61c John Mac committed with Jun 19, 2010
Showing with 14 additions and 3 deletions.
  1. +14 −3 mongo/main.go
View
@@ -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
// that can be found in the LICENSE file.
@@ -14,6 +14,8 @@ import (
// Like BSON documents, all data in the mongo wire protocol is little-endian.
var pack = binary.LittleEndian
+var lastRequestID int32
+
func init() {
// Uses the 'urandom' device to get a seed which will be used by 'rand'.
@@ -32,8 +34,17 @@ func init() {
// *** Utility functions
// ***
-func randToi32() int32 {
- return rand.Int31()
+/* Gets a random request identifier different to the last one.
+ */
+func getRequestID() int32 {
+ id := rand.Int31()
+
+ if id == lastRequestID {
+ return getRequestID()
+ }
+ lastRequestID = id
+
+ return id
}
// *** Bits data

0 comments on commit d652cfe

Please sign in to comment.