-
Notifications
You must be signed in to change notification settings - Fork 26
/
transfer.go
46 lines (39 loc) · 918 Bytes
/
transfer.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
// Copyright 2018-2024 go-m3ua authors. All rights reserved.
// Use of this source code is governed by a MIT-style license that can be
// found in the LICENSE file.
package m3ua
import (
"context"
"errors"
"github.com/wmnsk/go-m3ua/messages"
)
func (c *Conn) handleData(ctx context.Context, data *messages.Data) {
err := func() error {
c.mu.Lock()
defer c.mu.Unlock()
if c.state != StateAspActive {
c.errChan <- NewErrUnexpectedMessage(data)
return errors.New(data.String())
}
return nil
}()
if err != nil {
// it has already emitted the error into the errChan, early exit
return
}
pd, err := data.ProtocolData.ProtocolData()
if err != nil {
c.errChan <- ErrFailedToPeelOff
return
}
if c.cfg.OriginatingPointCode != pd.DestinationPointCode {
c.errChan <- NewErrUnexpectedMessage(data)
return
}
select {
case c.dataChan <- pd:
return
case <-ctx.Done():
return
}
}