Renamed types (explicit) + moved channels into client (not controller)
This commit is contained in:
parent
3c5d45ee21
commit
15d9d24ce4
|
@ -11,9 +11,15 @@ var ErrMalFormed = fmt.Errorf("Malformed Frame")
|
||||||
// Represents an OpCode
|
// Represents an OpCode
|
||||||
type OpCode byte
|
type OpCode byte
|
||||||
|
|
||||||
// Represents a frame metadata
|
// Represents a frame header
|
||||||
type Header struct {
|
type Header struct {
|
||||||
Fin bool
|
Fin bool
|
||||||
Opc OpCode
|
Opc OpCode
|
||||||
Msk []byte // len: 4 if set, else empty
|
Msk []byte // len() = 4 if set, else empty
|
||||||
|
}
|
||||||
|
|
||||||
|
// Represents a frame message
|
||||||
|
type Payload struct {
|
||||||
|
Buffer []byte
|
||||||
|
Length uint64
|
||||||
}
|
}
|
38
ws/types.go
38
ws/types.go
|
@ -10,42 +10,44 @@ const maxBufferLength = 4096
|
||||||
const maxChannelBufferLength = 1
|
const maxChannelBufferLength = 1
|
||||||
|
|
||||||
// Represents a websocket controller callback function
|
// Represents a websocket controller callback function
|
||||||
type ControllerFunc func(*Client, chan *Frame)
|
type ControllerFunc func(*Client, <-chan *Frame, chan<- []byte, <-chan func())
|
||||||
|
|
||||||
// Represents a websocket controller
|
// Represents a websocket controller
|
||||||
type Controller struct {
|
type Controller struct {
|
||||||
uri *parser.Scheme
|
uri *parser.Scheme // uri scheme
|
||||||
fun ControllerFunc
|
fun ControllerFunc // controller function
|
||||||
dat chan *Frame // data channel
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Represents a websocket client
|
// Represents a websocket client
|
||||||
type Client struct {
|
type Client struct {
|
||||||
soc net.Conn // communication socket
|
sock net.Conn // communication socket
|
||||||
pro string // choosen protocol (Sec-WebSocket-Protocol)
|
Protocol string // choosen protocol (Sec-WebSocket-Protocol)
|
||||||
arg [][]string // URI parameters, index 0 is full URI, then matching groups
|
Arguments [][]string // URI parameters, index 0 is full URI, then matching groups
|
||||||
|
|
||||||
ctl *Controller // assigned controller
|
Controller *Controller // assigned controller
|
||||||
Dat interface{} // store (for client implementation-specific data)
|
Store struct{} // store (for client implementation-specific data)
|
||||||
|
|
||||||
|
recvc chan *Frame // Receive channel
|
||||||
|
sendc chan []byte // sending channel
|
||||||
|
closec chan func() // closing channel
|
||||||
}
|
}
|
||||||
|
|
||||||
// Represents a websocket srever
|
// Represents a websocket srever
|
||||||
type Server struct {
|
type Server struct {
|
||||||
soc net.Listener // listen socket
|
sock net.Listener // listen socket
|
||||||
adr []byte // server listening ip/host
|
addr []byte // server listening ip/host
|
||||||
prt uint16 // server listening port
|
port uint16 // server listening port
|
||||||
|
|
||||||
cli []*Client // clients
|
clients map[net.Conn]*Client // clients
|
||||||
|
|
||||||
def *Controller // default controller
|
defaultController *Controller // default controller
|
||||||
ctl []*Controller // URI-bound controllers
|
controllers []*Controller // URI-bound controllers
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Represents a websocket frame
|
// Represents a websocket frame
|
||||||
type Frame struct {
|
type Frame struct {
|
||||||
H frame.Header
|
Header frame.Header
|
||||||
Buf []byte
|
Payload frame.Payload
|
||||||
Len uint64
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue