forked from Shiloh/githaven
b6a95a8cb3
* Dropped unused codekit config * Integrated dynamic and static bindata for public * Ignore public bindata * Add a general generate make task * Integrated flexible public assets into web command * Updated vendoring, added all missiong govendor deps * Made the linter happy with the bindata and dynamic code * Moved public bindata definition to modules directory * Ignoring the new bindata path now * Updated to the new public modules import path * Updated public bindata command and drop the new prefix
51 lines
1.0 KiB
Go
51 lines
1.0 KiB
Go
package client
|
|
|
|
import (
|
|
"bufio"
|
|
"net"
|
|
"time"
|
|
|
|
"github.com/ngaut/deadline"
|
|
)
|
|
|
|
// Conn is the connection for timestamp oracle server, it is not thread safe.
|
|
type Conn struct {
|
|
addr string
|
|
net.Conn
|
|
closed bool
|
|
r *bufio.Reader
|
|
w *bufio.Writer
|
|
netTimeout time.Duration
|
|
}
|
|
|
|
// NewConnection creates a conn.
|
|
func NewConnection(addr string, netTimeout time.Duration) (*Conn, error) {
|
|
conn, err := net.DialTimeout("tcp", addr, netTimeout)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return &Conn{
|
|
addr: addr,
|
|
Conn: conn,
|
|
r: bufio.NewReaderSize(deadline.NewDeadlineReader(conn, netTimeout), 512*1024),
|
|
w: bufio.NewWriterSize(deadline.NewDeadlineWriter(conn, netTimeout), 512*1024),
|
|
netTimeout: netTimeout,
|
|
}, nil
|
|
}
|
|
|
|
// Read reads data and stores it into p.
|
|
func (c *Conn) Read(p []byte) (int, error) {
|
|
return c.r.Read(p)
|
|
}
|
|
|
|
// Flush flushs buffered data.
|
|
func (c *Conn) Flush() error {
|
|
return c.w.Flush()
|
|
}
|
|
|
|
// Write writes p.
|
|
func (c *Conn) Write(p []byte) (int, error) {
|
|
return c.w.Write(p)
|
|
}
|