forked from googollee/go-socket.io
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtransport.go
More file actions
42 lines (35 loc) · 744 Bytes
/
transport.go
File metadata and controls
42 lines (35 loc) · 744 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package socketio
import (
"io"
"sync"
)
type Transport interface {
Send([]byte) error
Read() (io.Reader, error)
}
var (
DefaultTransports = NewTransportManager()
)
type TransportManager struct {
mutex sync.RWMutex
transports map[string]bool
}
func NewTransportManager() *TransportManager {
return &TransportManager{
transports: make(map[string]bool),
}
}
func (tm *TransportManager) RegisterTransport(name string) {
tm.mutex.Lock()
defer tm.mutex.Unlock()
tm.transports[name] = true
}
func (tm *TransportManager) GetTransportNames() (names []string) {
tm.mutex.RLock()
defer tm.mutex.RUnlock()
names = make([]string, 0, len(tm.transports))
for k, _ := range tm.transports {
names = append(names, k)
}
return
}