Skip to content

Commit

Permalink
feat: remove keep alive, add check for conn state
Browse files Browse the repository at this point in the history
Signed-off-by: 1998-felix <[email protected]>
  • Loading branch information
felixgateru committed May 21, 2024
1 parent b236eb6 commit 13fc3c0
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 17 deletions.
4 changes: 4 additions & 0 deletions coap/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ func (c *client) Token() string {
}

func (c *client) Handle(msg *messaging.Message) error {
if err := c.conn.Ping(c.conn.Context()); err != nil {
return nil
}

pm := c.conn.AcquireMessage(c.conn.Context())
defer c.conn.ReleaseMessage(pm)
pm.SetCode(codes.Content)
Expand Down
18 changes: 1 addition & 17 deletions internal/server/coap/coap.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ import (
"github.com/absmach/magistrala/internal/server"
gocoap "github.com/plgd-dev/go-coap/v3"
"github.com/plgd-dev/go-coap/v3/mux"
"github.com/plgd-dev/go-coap/v3/options"
udpServer "github.com/plgd-dev/go-coap/v3/udp/server"
)

const (
Expand Down Expand Up @@ -42,27 +40,13 @@ func New(ctx context.Context, cancel context.CancelFunc, name string, config ser
}
}

type udpNilMonitor struct{}

func (u *udpNilMonitor) UDPServerApply(cfg *udpServer.Config) {
cfg.CreateInactivityMonitor = nil
}

var _ udpServer.Option = (*udpNilMonitor)(nil)

func NewUDPNilMonitor() udpServer.Option {
return &udpNilMonitor{}
}

func (s *Server) Start() error {
errCh := make(chan error)
s.Logger.Info(fmt.Sprintf("%s service started using http, exposed port %s", s.Name, s.Address))
s.Logger.Info(fmt.Sprintf("%s service %s server listening at %s without TLS", s.Name, s.Protocol, s.Address))

opts := []any{}
opts = append(opts, options.WithMux(s.handler), NewUDPNilMonitor())
go func() {
errCh <- gocoap.ListenAndServeWithOptions("udp", s.Address, opts...)
errCh <- gocoap.ListenAndServe("udp", s.Address, s.handler)
}()

select {
Expand Down

0 comments on commit 13fc3c0

Please sign in to comment.