Skip to content

Commit

Permalink
Added function to close conection
Browse files Browse the repository at this point in the history
  • Loading branch information
John Mac authored and mikejs committed Jun 18, 2010
1 parent 22aae34 commit 6a020ea
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions mongo/mongo.go
Expand Up @@ -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))
Expand All @@ -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 {
Expand Down

0 comments on commit 6a020ea

Please sign in to comment.