另客网go项目公用的代码库

hook.go 527B

12345678910111213141516171819202122232425262728293031
  1. package linker
  2. import (
  3. "net"
  4. "sync"
  5. "github.com/gorilla/websocket"
  6. )
  7. // fix panic as websocket concurrency write
  8. type webSocketConn struct {
  9. mutex sync.Mutex
  10. conn *websocket.Conn
  11. }
  12. func (ws *webSocketConn) WriteMessage(messageType int, data []byte) error {
  13. ws.mutex.Lock()
  14. err := ws.conn.WriteMessage(messageType, data)
  15. ws.mutex.Unlock()
  16. return err
  17. }
  18. func (ws *webSocketConn) LocalAddr() net.Addr {
  19. return ws.conn.LocalAddr()
  20. }
  21. func (ws *webSocketConn) RemoteAddr() net.Addr {
  22. return ws.conn.RemoteAddr()
  23. }