diff --git a/ws/frame/types.go b/ws/frame/types.go index fad9e45..ce7ea06 100644 --- a/ws/frame/types.go +++ b/ws/frame/types.go @@ -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 } \ No newline at end of file diff --git a/ws/types.go b/ws/types.go index 9617c46..f83a9ed 100644 --- a/ws/types.go +++ b/ws/types.go @@ -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 } \ No newline at end of file