diff --git a/muxr/client.go b/muxr/client.go index abffa56..64630bb 100644 --- a/muxr/client.go +++ b/muxr/client.go @@ -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") } diff --git a/muxr/muxr_test.go b/muxr/muxr_test.go index b7d397a..8be3360 100644 --- a/muxr/muxr_test.go +++ b/muxr/muxr_test.go @@ -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") diff --git a/muxr/server.go b/muxr/server.go index 609f1ef..b51d554 100644 --- a/muxr/server.go +++ b/muxr/server.go @@ -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") } @@ -169,7 +169,7 @@ func (s *WsServer) wsServerHandler(writer http.ResponseWriter, request *http.Req isAlive = false return } - stream.ReciverChan <- data + stream.ReceiverChan <- data }() } } diff --git a/muxr/stream.go b/muxr/stream.go index c918d42..231fc3f 100644 --- a/muxr/stream.go +++ b/muxr/stream.go @@ -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") @@ -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 } @@ -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() @@ -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 }