Skip to content

Commit

Permalink
2024-09-28 20:25:50
Browse files Browse the repository at this point in the history
  • Loading branch information
mohanson committed Sep 28, 2024
1 parent 183f2be commit d46cdad
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
8 changes: 4 additions & 4 deletions protocol/czar/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,13 @@ func (s *Server) Run() error {
mux := NewMuxServer(cli)
go func() {
defer mux.Close()
for cli := range mux.Accept() {
for con := range mux.Accept() {
idx++
ctx := &daze.Context{Cid: idx}
log.Printf("conn: %08x accept remote=%s", ctx.Cid, mux.con.RemoteAddr())
log.Printf("conn: %08x accept remote=%s", ctx.Cid, cli.RemoteAddr())
go func() {
defer cli.Close()
if err := s.Serve(ctx, cli); err != nil {
defer con.Close()
if err := s.Serve(ctx, con); err != nil {
log.Printf("conn: %08x error %s", ctx.Cid, err)
}
log.Printf("conn: %08x closed", ctx.Cid)
Expand Down
11 changes: 5 additions & 6 deletions protocol/czar/mux.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package czar
import (
"encoding/binary"
"io"
"net"
"sync"

"github.com/mohanson/daze/lib/doa"
Expand Down Expand Up @@ -143,7 +142,7 @@ func NewWither(idx uint8, mux *Mux) *Stream {
// Mux is used to wrap a reliable ordered connection and to multiplex it into multiple streams.
type Mux struct {
ach chan *Stream
con net.Conn
con io.ReadWriteCloser
idp *Sip
pri *priority.Priority
rer *Err
Expand All @@ -161,7 +160,7 @@ func (m *Mux) Close() error {
return m.con.Close()
}

// Open is used to create a new stream as a net.Conn.
// Open is used to create a new stream as a io.ReadWriteCloser.
func (m *Mux) Open() (*Stream, error) {
var (
err error
Expand Down Expand Up @@ -246,7 +245,7 @@ func (m *Mux) Recv() {
}

// NewMux returns a new Mux.
func NewMux(conn net.Conn) *Mux {
func NewMux(conn io.ReadWriteCloser) *Mux {
mux := &Mux{
ach: make(chan *Stream),
con: conn,
Expand All @@ -259,7 +258,7 @@ func NewMux(conn net.Conn) *Mux {
}

// NewMuxServer returns a new MuxServer.
func NewMuxServer(conn net.Conn) *Mux {
func NewMuxServer(conn io.ReadWriteCloser) *Mux {
mux := NewMux(conn)
for i := range 256 {
mux.usb[i] = NewWither(uint8(i), mux)
Expand All @@ -269,7 +268,7 @@ func NewMuxServer(conn net.Conn) *Mux {
}

// NewMuxClient returns a new MuxClient.
func NewMuxClient(conn net.Conn) *Mux {
func NewMuxClient(conn io.ReadWriteCloser) *Mux {
mux := NewMux(conn)
go mux.Recv()
return mux
Expand Down

0 comments on commit d46cdad

Please sign in to comment.