-
Notifications
You must be signed in to change notification settings - Fork 64
/
transport.go
57 lines (49 loc) · 1.61 KB
/
transport.go
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package socketio
import (
"fmt"
"http"
"io"
"os"
)
var (
// ErrNotConnected is used when some action required the connection to be online,
// but it wasn't.
ErrNotConnected = os.NewError("not connected")
// ErrConnected is used when some action required the connection to be offline,
// but it wasn't.
ErrConnected = os.NewError("already connected")
emptyResponse = []byte{}
okResponse = []byte("ok")
)
// DefaultTransports holds the defaults
var DefaultTransports = []Transport{
NewXHRPollingTransport(10e9, 5e9),
NewXHRMultipartTransport(0, 5e9),
NewWebsocketTransport(0, 5e9),
NewHTMLFileTransport(0, 5e9),
NewFlashsocketTransport(0, 5e9),
NewJSONPPollingTransport(0, 5e9),
}
// Transport is the interface that wraps the Resource and newSocket methods.
//
// Resource returns the resource name of the transport, e.g. "websocket".
// NewSocket creates a new socket that embeds the corresponding transport
// mechanisms.
type Transport interface {
Resource() string
newSocket() socket
}
// Socket is the interface that wraps the basic Read, Write, Close and String
// methods. Additionally it has Transport and accept methods.
//
// Transport returns the Transport that created this socket.
// Accept takes the http.ResponseWriter / http.Request -pair from a http handler
// and hijacks the connection for itself. The third parameter is a function callback
// that will be invoked when the connection has been succesfully hijacked and the socket
// is ready to be used.
type socket interface {
io.ReadWriteCloser
fmt.Stringer
Transport() Transport
accept(http.ResponseWriter, *http.Request, func()) os.Error
}