Browse files

Added function to close conection

  • Loading branch information...
1 parent 22aae34 commit 6a020ea54996bef936d3c0d77b08f891af95b8bb John Mac committed with Jun 17, 2010
Showing with 15 additions and 7 deletions.
  1. +15 −7 mongo/mongo.go
View
22 mongo/mongo.go
@@ -42,6 +42,15 @@ type Connection struct {
conn *net.TCPConn
}
+func header(length, reqID, respTo, opCode int32) []byte {
+ b := make([]byte, 16)
+ binary.LittleEndian.PutUint32(b[0:4], uint32(length))
+ binary.LittleEndian.PutUint32(b[4:8], uint32(reqID))
+ binary.LittleEndian.PutUint32(b[8:12], uint32(respTo))
+ binary.LittleEndian.PutUint32(b[12:16], uint32(opCode))
+ return b
+}
+
func Connect(host string, port int) (*Connection, os.Error) {
laddr, _ := net.ResolveTCPAddr("localhost")
addr, _ := net.ResolveTCPAddr(fmt.Sprintf("%s:%d", host, port))
@@ -54,13 +63,12 @@ func Connect(host string, port int) (*Connection, os.Error) {
return &Connection{host, port, conn}, nil
}
-func header(length, reqID, respTo, opCode int32) []byte {
- b := make([]byte, 16)
- binary.LittleEndian.PutUint32(b[0:4], uint32(length))
- binary.LittleEndian.PutUint32(b[4:8], uint32(reqID))
- binary.LittleEndian.PutUint32(b[8:12], uint32(respTo))
- binary.LittleEndian.PutUint32(b[12:16], uint32(opCode))
- return b
+/* Closes the conection to the Database. */
+func (self *Connection) Close() os.Error {
+ if err := self.conn.Close(); err != nil {
+ return err
+ }
+ return nil
}
func (c *Connection) writeMessage(m message) os.Error {

0 comments on commit 6a020ea

Please sign in to comment.