1
0
Fork 0
mirror of https://codeberg.org/forgejo/forgejo.git synced 2024-12-25 13:19:37 -05:00
forgejo/vendor/github.com/ngaut/tso/client/conn.go
Thomas Boerger b6a95a8cb3 Integrate public as bindata optionally (#293)
* 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
2016-11-30 00:26:36 +08:00

50 lines
1 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)
}