-
Notifications
You must be signed in to change notification settings - Fork 2
/
stream.go
44 lines (35 loc) · 973 Bytes
/
stream.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
package http2
import (
"fmt"
)
type Stream struct {
Conn *Connection
ID uint32
WindowSize uint16
State STATE
}
// 65535 should be defined in connection
func NewStream(connection *Connection, streamID uint32) *Stream {
return &Stream{connection, streamID, 65535, IDLE}
}
func (self *Stream) ChangeState(state STATE) {
self.State = state
}
func (self *Stream) GetState() STATE {
return self.State
}
func (self *Stream) DecreaseWindow(size uint16) {
self.WindowSize -= size
}
func (self *Stream) Send(frame Frame) {
// do something to self
fmt.Printf("%s: \t%s\n\t%s\n", SendC.Apply("Send"), self.String(), frame.String())
(*self.Conn).Conn.Write(frame.GetWire())
}
func (self *Stream) EvaluateFrame(frame Frame) {
frame.Evaluate(*self)
// do something to self, also error handling
}
func (self *Stream) String() string {
return fmt.Sprintf("Stream: ID=%d, Status=%s, WindowSize=%d", self.ID, self.State.String(), self.WindowSize)
}