Commit f108db1d authored by AlexStocks's avatar AlexStocks

Fix: delete Empty

parent 6a7f8a34
...@@ -23,7 +23,6 @@ import ( ...@@ -23,7 +23,6 @@ import (
import ( import (
"github.com/AlexStocks/goext/net" "github.com/AlexStocks/goext/net"
"github.com/AlexStocks/goext/sync"
log "github.com/AlexStocks/log4go" log "github.com/AlexStocks/log4go"
"github.com/gorilla/websocket" "github.com/gorilla/websocket"
jerrors "github.com/juju/errors" jerrors "github.com/juju/errors"
...@@ -52,10 +51,10 @@ type client struct { ...@@ -52,10 +51,10 @@ type client struct {
endPointType EndPointType endPointType EndPointType
newSession NewSessionCallback newSession NewSessionCallback
ssMap map[Session]gxsync.Empty ssMap map[Session]struct{}
sync.Once sync.Once
done chan gxsync.Empty done chan struct{}
wg sync.WaitGroup wg sync.WaitGroup
} }
...@@ -68,7 +67,7 @@ func (c *client) init(opts ...ClientOption) { ...@@ -68,7 +67,7 @@ func (c *client) init(opts ...ClientOption) {
func newClient(t EndPointType, opts ...ClientOption) *client { func newClient(t EndPointType, opts ...ClientOption) *client {
c := &client{ c := &client{
endPointType: t, endPointType: t,
done: make(chan gxsync.Empty), done: make(chan struct{}),
} }
c.init(opts...) c.init(opts...)
...@@ -77,7 +76,7 @@ func newClient(t EndPointType, opts ...ClientOption) *client { ...@@ -77,7 +76,7 @@ func newClient(t EndPointType, opts ...ClientOption) *client {
panic(fmt.Sprintf("client type:%s, @connNum:%d, @serverAddr:%s", t, c.number, c.addr)) panic(fmt.Sprintf("client type:%s, @connNum:%d, @serverAddr:%s", t, c.number, c.addr))
} }
c.ssMap = make(map[Session]gxsync.Empty, c.number) c.ssMap = make(map[Session]struct{}, c.number)
return c return c
} }
...@@ -362,7 +361,7 @@ func (c *client) connect() { ...@@ -362,7 +361,7 @@ func (c *client) connect() {
// ss.RunEventLoop() // ss.RunEventLoop()
ss.(*session).run() ss.(*session).run()
c.Lock() c.Lock()
c.ssMap[ss] = gxsync.Empty{} c.ssMap[ss] = struct{}{}
c.Unlock() c.Unlock()
ss.SetAttribute(sessionClientKey, c) ss.SetAttribute(sessionClientKey, c)
break break
......
...@@ -14,7 +14,7 @@ import ( ...@@ -14,7 +14,7 @@ import (
) )
var ( var (
errTooManySessions = jerrors.New("too many echo sessions") errTooManySessions = jerrors.New("too many sessions")
) )
type rpcSession struct { type rpcSession struct {
...@@ -44,7 +44,7 @@ func NewRpcServerHandler(maxSessionNum int, sessionTimeout time.Duration) *RpcSe ...@@ -44,7 +44,7 @@ func NewRpcServerHandler(maxSessionNum int, sessionTimeout time.Duration) *RpcSe
func (h *RpcServerHandler) OnOpen(session getty.Session) error { func (h *RpcServerHandler) OnOpen(session getty.Session) error {
var err error var err error
h.rwlock.RLock() h.rwlock.RLock()
if h.maxSessionNum < len(h.sessionMap) { if h.maxSessionNum <= len(h.sessionMap) {
err = errTooManySessions err = errTooManySessions
} }
h.rwlock.RUnlock() h.rwlock.RUnlock()
......
...@@ -23,7 +23,6 @@ import ( ...@@ -23,7 +23,6 @@ import (
import ( import (
"github.com/AlexStocks/goext/net" "github.com/AlexStocks/goext/net"
"github.com/AlexStocks/goext/sync"
"github.com/AlexStocks/goext/time" "github.com/AlexStocks/goext/time"
log "github.com/AlexStocks/log4go" log "github.com/AlexStocks/log4go"
"github.com/gorilla/websocket" "github.com/gorilla/websocket"
...@@ -46,7 +45,7 @@ type server struct { ...@@ -46,7 +45,7 @@ type server struct {
server *http.Server // for ws or wss server server *http.Server // for ws or wss server
sync.Once sync.Once
done chan gxsync.Empty done chan struct{}
wg sync.WaitGroup wg sync.WaitGroup
} }
...@@ -59,7 +58,7 @@ func (s *server) init(opts ...ServerOption) { ...@@ -59,7 +58,7 @@ func (s *server) init(opts ...ServerOption) {
func newServer(t EndPointType, opts ...ServerOption) *server { func newServer(t EndPointType, opts ...ServerOption) *server {
s := &server{ s := &server{
endPointType: t, endPointType: t,
done: make(chan gxsync.Empty), done: make(chan struct{}),
} }
s.init(opts...) s.init(opts...)
......
...@@ -27,7 +27,6 @@ import ( ...@@ -27,7 +27,6 @@ import (
import ( import (
"github.com/AlexStocks/goext/context" "github.com/AlexStocks/goext/context"
"github.com/AlexStocks/goext/sync"
"github.com/AlexStocks/goext/time" "github.com/AlexStocks/goext/time"
) )
...@@ -68,7 +67,7 @@ type session struct { ...@@ -68,7 +67,7 @@ type session struct {
writer Writer writer Writer
listener EventListener listener EventListener
once sync.Once once sync.Once
done chan gxsync.Empty done chan struct{}
// errFlag bool // errFlag bool
period time.Duration period time.Duration
...@@ -89,7 +88,7 @@ func newSession(endPoint EndPoint, conn Connection) *session { ...@@ -89,7 +88,7 @@ func newSession(endPoint EndPoint, conn Connection) *session {
endPoint: endPoint, endPoint: endPoint,
maxMsgLen: maxReadBufLen, maxMsgLen: maxReadBufLen,
Connection: conn, Connection: conn,
done: make(chan gxsync.Empty), done: make(chan struct{}),
period: period, period: period,
wait: pendingDuration, wait: pendingDuration,
attrs: gxcontext.NewValuesContext(nil), attrs: gxcontext.NewValuesContext(nil),
...@@ -129,7 +128,7 @@ func newWSSession(conn *websocket.Conn, endPoint EndPoint) Session { ...@@ -129,7 +128,7 @@ func newWSSession(conn *websocket.Conn, endPoint EndPoint) Session {
func (s *session) Reset() { func (s *session) Reset() {
s.name = defaultSessionName s.name = defaultSessionName
s.once = sync.Once{} s.once = sync.Once{}
s.done = make(chan gxsync.Empty) s.done = make(chan struct{})
// s.errFlag = false // s.errFlag = false
s.period = period s.period = period
s.wait = pendingDuration s.wait = pendingDuration
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment