]> git.lizzy.rs Git - mt.git/commitdiff
Add WaitGroup to SerializePkt master
authorLizzy Fleckenstein <eliasfleckenstein@web.de>
Sun, 12 Feb 2023 19:08:52 +0000 (20:08 +0100)
committerLizzy Fleckenstein <eliasfleckenstein@web.de>
Sun, 12 Feb 2023 19:08:52 +0000 (20:08 +0100)
proto.go

index 597e146d54b4c00e9e5d646dd3f124c049c9a6a7..c5566f038ad3546ea6fbfafde66a2c30e404b89a 100644 (file)
--- a/proto.go
+++ b/proto.go
@@ -4,6 +4,7 @@ import (
        "fmt"
        "io"
        "net"
+       "sync"
 
        "github.com/dragonfireclient/mt/rudp"
 )
@@ -19,7 +20,7 @@ type Peer struct {
        *rudp.Conn
 }
 
-func SerializePkt(pkt Cmd, w io.WriteCloser, toSrv bool) bool {
+func SerializePkt(pkt Cmd, w io.WriteCloser, toSrv bool, wg *sync.WaitGroup) bool {
        var cmdNo uint16
        if toSrv {
                cmdNo = pkt.(ToSrvCmd).toSrvCmdNo()
@@ -31,7 +32,9 @@ func SerializePkt(pkt Cmd, w io.WriteCloser, toSrv bool) bool {
                return false
        }
 
+       wg.Add(1)
        go func() (err error) {
+               defer wg.Done()
                // defer w.CloseWithError(err)
                defer w.Close()
 
@@ -48,7 +51,7 @@ func SerializePkt(pkt Cmd, w io.WriteCloser, toSrv bool) bool {
 
 func (p Peer) Send(pkt Pkt) (ack <-chan struct{}, err error) {
        r, w := io.Pipe()
-       if !SerializePkt(pkt.Cmd, w, p.IsSrv()) {
+       if !SerializePkt(pkt.Cmd, w, p.IsSrv(), &sync.WaitGroup{}) {
                return nil, p.Close()
        }