summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Harris <git@peter.is-a-geek.org>2010-12-24 14:05:29 -0500
committerPeter Harris <git@peter.is-a-geek.org>2010-12-28 20:30:06 -0500
commit8a31a4fcff4840b3dbb3ecb74991df42eab50263 (patch)
treed23c4d889de68cb3d755e1ebf80ebf0f598f6ff3
parent0ddd54a11b14525d77e0b9aa7fbe46ee704f85a3 (diff)
Buffer output
This roughly doubles the speed of the noop test app.
-rw-r--r--xgob.go12
1 files changed, 9 insertions, 3 deletions
diff --git a/xgob.go b/xgob.go
index 47ec431..8c8e4e5 100644
--- a/xgob.go
+++ b/xgob.go
@@ -43,6 +43,7 @@ type Connection struct {
Setup ConnectionBlock
Event chan Event
conn io.ReadWriteCloser
+ out *bufio.Writer
reply map[uint64]chan interface {}
replyMutex sync.Mutex
writeMutex sync.Mutex
@@ -335,6 +336,7 @@ func (c *Connection)connect_auth(name string, data string) {
c.Disconnect()
return
}
+ c.out = bufio.NewWriter(c.conn)
c.Event = make (chan Event, events_before_readblock)
c.reply = make (map [uint64]chan interface{})
go c.read(in)
@@ -379,14 +381,14 @@ func (c *Connection) WriteMultiRequest (req []byte, expected int) chan interface
defer c.writeMutex.Unlock()
c.registerReply(rv)
- c.conn.Write(req)
+ c.out.Write(req)
if replier {
c.lastReplierSent = c.lastRequestWritten
} else {
if c.lastRequestWritten - c.lastReplierSent >= 65534 {
c.registerReply(make(chan interface{}, 1))
- c.conn.Write([]byte{43,0,0,1})
+ c.out.Write([]byte{43,0,0,1})
c.lastReplierSent = c.lastRequestWritten
}
}
@@ -403,7 +405,11 @@ func (c *Connection) WriteReplyRequest (req []byte) chan interface{} {
}
func (c *Connection) Flush () {
- // TODO buffer WriteRequest
+ if c == nil || c.conn == nil {
+ return
+ }
+
+ c.out.Flush()
}
func (c *Connection) HasError () bool {