Permalink
Browse files

moved method writeMessage() from file message

  • Loading branch information...
John Mac authored and mikejs committed Jun 18, 2010
1 parent 595a150 commit 4a1afa3a09acb58a82e3365d08b9fe84ba2d8824
Showing with 19 additions and 7 deletions.
  1. +19 −7 mongo/connection.go
View
@@ -5,6 +5,7 @@
package mongo
import (
+ "bytes"
"fmt"
"net"
"os"
@@ -35,6 +36,16 @@ func ConnectByAddr(addr *net.TCPAddr) (*Connection, os.Error) {
return &Connection{addr, conn}, nil
}
+/* Reconnects using the same address `Addr`. */
+func (self *Connection) Reconnect() (*Connection, os.Error) {
+ connection, err := ConnectByAddr(self.Addr)
+ if err != nil {
+ return nil, err
+ }
+
+ return connection, nil
+}
+
/* Disconnects the conection from MongoDB. */
func (self *Connection) Disconnect() os.Error {
if err := self.conn.Close(); err != nil {
@@ -43,13 +54,14 @@ func (self *Connection) Disconnect() os.Error {
return nil
}
-/* Reconnects using the same address `Addr`. */
-func (self *Connection) Reconnect() (*Connection, os.Error) {
- connection, err := ConnectByAddr(self.Addr)
- if err != nil {
- return nil, err
- }
+func (c *Connection) writeMessage(m message) os.Error {
+ body := m.Bytes()
+ hb := header(int32(len(body)+16), m.RequestID(), 0, m.OpCode())
+ msg := bytes.Add(hb, body)
- return connection, nil
+ _, err := c.conn.Write(msg)
+
+ last_req = m.RequestID()
+ return err
}

0 comments on commit 4a1afa3

Please sign in to comment.