Skip to content

Commit

Permalink
reload
Browse files Browse the repository at this point in the history
  • Loading branch information
OkutaniDaichi0106 committed Dec 24, 2024
1 parent 113e2c4 commit 5ae391b
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 72 deletions.
76 changes: 38 additions & 38 deletions datagram.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,12 @@ type SentDatagram interface {
Group
}

func newSentDatagram(group SentGroup, payload []byte) SentDatagram {
return &sentDatagram{
SentGroup: group,
payload: payload,
}
}
// func newSentDatagram(group SentGroup, payload []byte) SentDatagram {
// return &sentDatagram{
// SentGroup: group,
// payload: payload,
// }
// }

var _ SentDatagram = (*sentDatagram)(nil)

Expand All @@ -116,46 +116,46 @@ func (d *sentDatagram) Write(buf []byte) (int, error) {
return copy(d.payload, buf), nil
}

type sentDatagramQueue struct {
mu sync.Mutex
queue []SentDatagram
ch chan struct{}
}
// type sentDatagramQueue struct {
// mu sync.Mutex
// queue []SentDatagram
// ch chan struct{}
// }

func (q *sentDatagramQueue) Len() int {
q.mu.Lock()
defer q.mu.Unlock()
// func (q *sentDatagramQueue) Len() int {
// q.mu.Lock()
// defer q.mu.Unlock()

return len(q.queue)
}
// return len(q.queue)
// }

func (q *sentDatagramQueue) Chan() <-chan struct{} {
// func (q *sentDatagramQueue) Chan() <-chan struct{} {

return q.ch
}
// return q.ch
// }

func (q *sentDatagramQueue) Enqueue(datagram SentDatagram) {
q.mu.Lock()
defer q.mu.Unlock()
// func (q *sentDatagramQueue) Enqueue(datagram SentDatagram) {
// q.mu.Lock()
// defer q.mu.Unlock()

q.queue = append(q.queue, datagram)
// q.queue = append(q.queue, datagram)

select {
case q.ch <- struct{}{}:
default:
}
}
// select {
// case q.ch <- struct{}{}:
// default:
// }
// }

func (q *sentDatagramQueue) Dequeue() SentDatagram {
q.mu.Lock()
defer q.mu.Unlock()
// func (q *sentDatagramQueue) Dequeue() SentDatagram {
// q.mu.Lock()
// defer q.mu.Unlock()

if len(q.queue) == 0 {
return nil
}
// if len(q.queue) == 0 {
// return nil
// }

next := q.queue[0]
q.queue = q.queue[1:]
// next := q.queue[0]
// q.queue = q.queue[1:]

return next
}
// return next
// }
59 changes: 26 additions & 33 deletions priority.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,44 +15,37 @@ const (
DESCENDING GroupOrder = 0x2
)

type priorityArgs struct {
TrackPriority TrackPriority
groupOrder GroupOrder
subscribeID SubscribeID
groupSequence GroupSequence
groupPriority GroupPriority
type data interface {
//
SubscribeID() SubscribeID
TrackPriority() TrackPriority
GroupOrder() GroupOrder

//
GroupPriority() GroupPriority
GroupSequence() GroupSequence
}

func comparePriority(arg1, arg2 priorityArgs) bool {
if arg1.TrackPriority != arg2.TrackPriority {
return arg1.TrackPriority > arg2.TrackPriority
func schedule(a, b data) bool {
if a.SubscribeID() == b.SubscribeID() {
switch a.GroupOrder() {
case DEFAULT:
return a.GroupPriority() < b.GroupPriority()
case ASCENDING:
return a.GroupSequence() < b.GroupSequence()
case DESCENDING:
return a.GroupSequence() > b.GroupSequence()
default:
return false
}
}

if arg1.groupPriority != arg2.groupPriority {
return arg1.groupPriority > arg2.groupPriority
if a.TrackPriority() != b.TrackPriority() {
return a.TrackPriority() < b.TrackPriority()
}

if arg1.subscribeID != arg2.subscribeID {

// TODO:
return true
}

// if arg1.TrackPath != arg2.TrackPath {
// return false // TODO: handle this situation as an error
// }
if arg1.groupOrder != arg2.groupOrder {
return false // TODO: handle this situation as an error
}

switch arg1.groupOrder {
case DEFAULT:
return true
case ASCENDING:
return arg1.groupSequence < arg2.groupSequence
case DESCENDING:
return arg1.groupSequence > arg2.groupSequence
default:
return false
if a.GroupPriority() != b.GroupPriority() {
return a.GroupPriority() < b.GroupPriority()
}
return a.GroupSequence() < b.GroupSequence()
}
2 changes: 1 addition & 1 deletion setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ type SetupRequest struct {
once bool
}

func (r SetupRequest) init() error {
func (r *SetupRequest) init() error {
if r.once {
return nil
}
Expand Down

0 comments on commit 5ae391b

Please sign in to comment.