mirror of https://github.com/tidwall/redcon.git
connection context
This commit is contained in:
parent
eadbf61d4c
commit
349b9006f1
12
redcon.go
12
redcon.go
|
@ -37,6 +37,10 @@ type Conn interface {
|
||||||
WriteNull()
|
WriteNull()
|
||||||
// SetReadBuffer updates the buffer read size for the connection
|
// SetReadBuffer updates the buffer read size for the connection
|
||||||
SetReadBuffer(bytes int)
|
SetReadBuffer(bytes int)
|
||||||
|
// Context returns a user-defined context
|
||||||
|
Context() interface{}
|
||||||
|
// SetContext sets a user-defined context
|
||||||
|
SetContext(v interface{})
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
@ -149,6 +153,7 @@ func (s *Server) ListenServeAndSignal(signal chan error) error {
|
||||||
newWriter(tcpc),
|
newWriter(tcpc),
|
||||||
newReader(tcpc),
|
newReader(tcpc),
|
||||||
tcpc.RemoteAddr().String(),
|
tcpc.RemoteAddr().String(),
|
||||||
|
nil,
|
||||||
}
|
}
|
||||||
if accept != nil && !accept(c) {
|
if accept != nil && !accept(c) {
|
||||||
c.Close()
|
c.Close()
|
||||||
|
@ -221,6 +226,7 @@ type conn struct {
|
||||||
wr *writer
|
wr *writer
|
||||||
rd *reader
|
rd *reader
|
||||||
addr string
|
addr string
|
||||||
|
ctx interface{}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *conn) Close() error {
|
func (c *conn) Close() error {
|
||||||
|
@ -228,6 +234,12 @@ func (c *conn) Close() error {
|
||||||
c.conn.Close() // close the connection. ignore this error
|
c.conn.Close() // close the connection. ignore this error
|
||||||
return err // return the writer error only
|
return err // return the writer error only
|
||||||
}
|
}
|
||||||
|
func (c *conn) Context() interface{} {
|
||||||
|
return c.ctx
|
||||||
|
}
|
||||||
|
func (c *conn) SetContext(v interface{}) {
|
||||||
|
c.ctx = v
|
||||||
|
}
|
||||||
func (c *conn) WriteString(str string) {
|
func (c *conn) WriteString(str string) {
|
||||||
c.wr.WriteString(str)
|
c.wr.WriteString(str)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue