Renamed types (explicit) + moved channels into client (not controller)

This commit is contained in:
xdrm-brackets 2018-04-28 17:50:14 +02:00
parent 3c5d45ee21
commit 15d9d24ce4
2 changed files with 28 additions and 20 deletions

View File

@ -11,9 +11,15 @@ var ErrMalFormed = fmt.Errorf("Malformed Frame")
// Represents an OpCode
type OpCode byte
// Represents a frame metadata
// Represents a frame header
type Header struct {
Fin bool
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
}

View File

@ -10,42 +10,44 @@ const maxBufferLength = 4096
const maxChannelBufferLength = 1
// 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
type Controller struct {
uri *parser.Scheme
fun ControllerFunc
dat chan *Frame // data channel
uri *parser.Scheme // uri scheme
fun ControllerFunc // controller function
}
// Represents a websocket client
type Client struct {
soc net.Conn // communication socket
pro string // choosen protocol (Sec-WebSocket-Protocol)
arg [][]string // URI parameters, index 0 is full URI, then matching groups
sock net.Conn // communication socket
Protocol string // choosen protocol (Sec-WebSocket-Protocol)
Arguments [][]string // URI parameters, index 0 is full URI, then matching groups
ctl *Controller // assigned controller
Dat interface{} // store (for client implementation-specific data)
Controller *Controller // assigned controller
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
type Server struct {
soc net.Listener // listen socket
adr []byte // server listening ip/host
prt uint16 // server listening port
sock net.Listener // listen socket
addr []byte // server listening ip/host
port uint16 // server listening port
cli []*Client // clients
clients map[net.Conn]*Client // clients
def *Controller // default controller
ctl []*Controller // URI-bound controllers
defaultController *Controller // default controller
controllers []*Controller // URI-bound controllers
}
// Represents a websocket frame
type Frame struct {
H frame.Header
Buf []byte
Len uint64
Header frame.Header
Payload frame.Payload
}