ing
This commit is contained in:
parent
8a0c8265ee
commit
24629d21f6
|
@ -6,8 +6,8 @@ import (
|
|||
|
||||
type ServerRequest struct {
|
||||
Method string `json:"method"`
|
||||
Params *json.RawMessage `json:"params"`
|
||||
Id *json.RawMessage `json:"id"`
|
||||
Params []string `json:"params,omitempty"`
|
||||
Id *json.RawMessage `json:"id,omitempty"`
|
||||
}
|
||||
|
||||
func (r *ServerRequest) reset() {
|
||||
|
|
|
@ -5,7 +5,7 @@ import (
|
|||
)
|
||||
|
||||
type ServerResponse struct {
|
||||
Id *json.RawMessage `json:"id"`
|
||||
Result interface{} `json:"result"`
|
||||
Error interface{} `json:"error"`
|
||||
Id *json.RawMessage `json:"id,omitempty"`
|
||||
Result interface{} `json:"result,omitempty"`
|
||||
Error interface{} `json:"error,omitempty"`
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@ package overflow_gateway_websocket
|
|||
|
||||
import (
|
||||
"net/http"
|
||||
"sync"
|
||||
|
||||
"git.loafle.net/overflow/overflow_gateway_websocket/websocket"
|
||||
"github.com/valyala/fasthttp"
|
||||
|
@ -19,6 +20,7 @@ type server struct {
|
|||
_upgrader *websocket.Upgrader
|
||||
_handlers map[string]*SocketOptions
|
||||
_sockets map[string]Socket
|
||||
_socketsMtx sync.Mutex
|
||||
_addSocketCh chan Socket
|
||||
_removeSocketCh chan Socket
|
||||
}
|
||||
|
@ -91,11 +93,15 @@ func (s *server) listenHandler() {
|
|||
select {
|
||||
// Add new a socket
|
||||
case soc := <-s._addSocketCh:
|
||||
s._socketsMtx.Lock()
|
||||
s._sockets[soc.ID()] = soc
|
||||
s._socketsMtx.Unlock()
|
||||
|
||||
// remove a socket
|
||||
case soc := <-s._removeSocketCh:
|
||||
s._socketsMtx.Lock()
|
||||
delete(s._sockets, soc.ID())
|
||||
s._socketsMtx.Unlock()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user