Skip to content

Commit

Permalink
refactor: ✏️ typo
Browse files Browse the repository at this point in the history
  • Loading branch information
onionj committed Apr 15, 2024
1 parent 9a3e8d0 commit 7b68be0
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 18 deletions.
2 changes: 1 addition & 1 deletion muxr/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func (c *Client) Start() error {
defer stream.Unlock()
if !stream.isClosed {
select {
case stream.ReciverChan <- data[NUM_BYTES_HEADER : NUM_BYTES_HEADER+length]:
case stream.ReceiverChan <- data[NUM_BYTES_HEADER : NUM_BYTES_HEADER+length]:
default:
fmt.Println("muxr: stream buffer is full")
}
Expand Down
2 changes: 1 addition & 1 deletion muxr/muxr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func TestPingPongWithMuxrClientAndServer(t *testing.T) {

// TestPingPongWithGorillaClientAndMuxrServer tests ping-pong communication between a Gorilla WebSocket client and a muxr server.
func TestPingPongWithGorillaClientAndMuxrServer(t *testing.T) {
totalLoop := 50
totalLoop := 100

go func() {
server := NewServer(":19882")
Expand Down
4 changes: 2 additions & 2 deletions muxr/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ func (s *WsServer) wsServerHandler(writer http.ResponseWriter, request *http.Req
defer stream.Unlock()
if !stream.isClosed {
select {
case stream.ReciverChan <- data[NUM_BYTES_HEADER : NUM_BYTES_HEADER+lenght]:
case stream.ReceiverChan <- data[NUM_BYTES_HEADER : NUM_BYTES_HEADER+lenght]:
default:
fmt.Println("muxr: stream buffer is full")
}
Expand Down Expand Up @@ -169,7 +169,7 @@ func (s *WsServer) wsServerHandler(writer http.ResponseWriter, request *http.Req
isAlive = false
return
}
stream.ReciverChan <- data
stream.ReceiverChan <- data
}()
}
}
Expand Down
28 changes: 14 additions & 14 deletions muxr/stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ import (

type Stream struct {
sync.Mutex
id uint32
isClosed bool
ReciverChan chan []byte
ConnAdaptor *ConnAdaptor
id uint32
isClosed bool
ReceiverChan chan []byte
ConnAdaptor *ConnAdaptor
}

var ErrStreamClosed = errors.New("stream closed")
Expand All @@ -23,16 +23,16 @@ func newStream(
receiverChanSize int,
) *Stream {
return &Stream{
id: id,
isClosed: false,
ReciverChan: make(chan []byte, receiverChanSize),
ConnAdaptor: connAdaptor,
id: id,
isClosed: false,
ReceiverChan: make(chan []byte, receiverChanSize),
ConnAdaptor: connAdaptor,
}
}

// Read reads data from the stream's receiver channel.
func (st *Stream) Read() ([]byte, error) {
data, ok := <-st.ReciverChan
data, ok := <-st.ReceiverChan
if !ok {
return nil, io.EOF
}
Expand All @@ -55,11 +55,11 @@ func (st *Stream) Write(data []byte) error {

// Close closes the stream.
func (st *Stream) Close() {
st.ConnAdaptor.WritePacket(TYPE_CLOSE, st.id, []byte{})
_ = st.ConnAdaptor.WritePacket(TYPE_CLOSE, st.id, []byte{})
st.Kill()
}

// kill marks the stream as closed and closes its receiver channel.
// Kill marks the stream as closed and closes its receiver channel.
func (st *Stream) Kill() {

st.Lock()
Expand All @@ -70,15 +70,15 @@ func (st *Stream) Kill() {
}

st.isClosed = true
close(st.ReciverChan)
close(st.ReceiverChan)
}

// IsClosed returns true if the stream is closed, otherwise false.
// IsClose returns true if the stream is closed, otherwise false.
func (st *Stream) IsClose() bool {
return st.isClosed
}

// ID returns the ID of the stream.
// Id returns the ID of the stream.
func (st *Stream) Id() uint32 {
return st.id
}
Expand Down

0 comments on commit 7b68be0

Please sign in to comment.