Permalink
Browse files

Cursor.Close()

  • Loading branch information...
1 parent d943789 commit d9f1a23263add3170077d429cafb87e493e664ae @mikejs committed Nov 20, 2009
Showing with 36 additions and 0 deletions.
  1. +36 −0 mongo.go
View
36 mongo.go
@@ -165,6 +165,18 @@ func (c *Cursor) GetMore() os.Error {
return nil;
}
+func (c *Cursor) Close() os.Error {
+ if c.id == 0 {
+ // not open on server
+ return nil
+ }
+
+ req_id := rand.Int31();
+ km := &killMsg{1, []int64{c.id}, req_id};
+ conn := c.collection.db.conn;
+ return conn.writeMessage(km);
+}
+
func (c *Collection) fullName() string { return c.db.name + "." + c.name }
type indexDesc struct {
@@ -427,3 +439,27 @@ func (u *updateMsg) Bytes() []byte {
return buf.Bytes();
}
+
+type killMsg struct {
+ numberOfCursorIDs int32;
+ cursorIDs []int64;
+ requestID int32;
+}
+
+func (k *killMsg) OpCode() int32 { return _OP_KILL_CURSORS }
+func (k *killMsg) RequestID() int32 { return k.requestID }
+func (k *killMsg) Bytes() []byte {
+ buf := bytes.NewBuffer(make([]byte, 4));
+
+ b := make([]byte, 4);
+ binary.LittleEndian.PutUint32(b, uint32(k.numberOfCursorIDs));
+ buf.Write(b);
+
+ b = make([]byte, 8);
+ for _, id := range k.cursorIDs {
+ binary.LittleEndian.PutUint64(b, uint64(id));
+ buf.Write(b);
+ }
+
+ return buf.Bytes();
+}

0 comments on commit d9f1a23

Please sign in to comment.