Documentation ¶
Index ¶
- Constants
- Variables
- func WithAddressRange(addressRange pdu.AddressRange) connectorOption
- type AllPDUCallback
- type Auth
- type BindError
- type ClosedCallback
- type Connection
- func (c *Connection) Close() error
- func (c *Connection) LocalAddr() net.Addr
- func (c *Connection) Read(b []byte) (n int, err error)
- func (c *Connection) RemoteAddr() net.Addr
- func (c *Connection) SetDeadline(t time.Time) error
- func (c *Connection) SetReadDeadline(t time.Time) error
- func (c *Connection) SetReadTimeout(t time.Duration) error
- func (c *Connection) SetWriteDeadline(t time.Time) error
- func (c *Connection) SetWriteTimeout(t time.Duration) error
- func (c *Connection) Write(b []byte) (n int, err error)
- func (c *Connection) WritePDU(p pdu.PDU) (n int, err error)
- type Connector
- type Dialer
- type ErrorCallback
- type PDUCallback
- type PDUErrorCallback
- type RebindCallback
- type Receiver
- type Session
- type Settings
- type State
- type Transceiver
- type Transmitter
Constants ¶
const ( Alive int32 = iota Closed )
Variables ¶
var ErrConnectionClosing = fmt.Errorf("connection is closing, can not send PDU to SMSC")
ErrConnectionClosing indicates transmitter is closing. Can not send any PDU.
NonTLSDialer is non-tls connection dialer.
Functions ¶
func WithAddressRange ¶
func WithAddressRange(addressRange pdu.AddressRange) connectorOption
Types ¶
type AllPDUCallback ¶
AllPDUCallback handles all received PDU.
This pdu is NOT responded to automatically, manual response/handling is needed and the bind can be closed by retuning true on closeBind.
type Auth ¶
type Auth struct { // SMSC is SMSC address. SMSC string SystemID string Password string SystemType string }
Auth represents basic authentication to SMSC.
type BindError ¶
type BindError struct {
CommandStatus data.CommandStatusType
}
type ClosedCallback ¶
type ClosedCallback func(State)
ClosedCallback notifies closed event due to State.
type Connection ¶
type Connection struct {
// contains filtered or unexported fields
}
Connection wraps over net.Conn with buffered data reader.
func NewConnection ¶
func NewConnection(conn net.Conn) (c *Connection)
NewConnection returns a Connection.
func (*Connection) Close ¶
func (c *Connection) Close() error
Close closes the connection. Any blocked Read or Write operations will be unblocked and return errors.
func (*Connection) LocalAddr ¶
func (c *Connection) LocalAddr() net.Addr
LocalAddr returns the local network address.
func (*Connection) Read ¶
func (c *Connection) Read(b []byte) (n int, err error)
Read reads data from the connection. Read can be made to time out and return an Error with Timeout() == true after a fixed time limit; see SetDeadline and SetReadDeadline.
func (*Connection) RemoteAddr ¶
func (c *Connection) RemoteAddr() net.Addr
RemoteAddr returns the remote network address.
func (*Connection) SetDeadline ¶
func (c *Connection) SetDeadline(t time.Time) error
SetDeadline sets the read and write deadlines associated with the connection. It is equivalent to calling both SetReadDeadline and SetWriteDeadline.
A deadline is an absolute time after which I/O operations fail with a timeout (see type Error) instead of blocking. The deadline applies to all future and pending I/O, not just the immediately following call to Read or Write. After a deadline has been exceeded, the connection can be refreshed by setting a deadline in the future.
An idle timeout can be implemented by repeatedly extending the deadline after successful Read or Write calls.
A zero value for t means I/O operations will not time out.
Note that if a TCP connection has keep-alive turned on, which is the default unless overridden by Dialer.KeepAlive or ListenConfig.KeepAlive, then a keep-alive failure may also return a timeout error. On Unix systems a keep-alive failure on I/O can be detected using errors.Is(err, syscall.ETIMEDOUT).
func (*Connection) SetReadDeadline ¶
func (c *Connection) SetReadDeadline(t time.Time) error
SetReadDeadline sets the deadline for future Read calls and any currently-blocked Read call. A zero value for t means Read will not time out.
func (*Connection) SetReadTimeout ¶
func (c *Connection) SetReadTimeout(t time.Duration) error
SetReadTimeout is equivalent to ReadDeadline(now + timeout)
func (*Connection) SetWriteDeadline ¶
func (c *Connection) SetWriteDeadline(t time.Time) error
SetWriteDeadline sets the deadline for future Write calls and any currently-blocked Write call. Even if write times out, it may return n > 0, indicating that some of the data was successfully written. A zero value for t means Write will not time out.
func (*Connection) SetWriteTimeout ¶
func (c *Connection) SetWriteTimeout(t time.Duration) error
SetWriteTimeout is equivalent to WriteDeadline(now + timeout)
type Connector ¶
type Connector interface {
Connect() (conn *Connection, err error)
}
Connector is connection factory interface.
func RXConnector ¶
RXConnector returns a Receiver (RX) connector.
func TRXConnector ¶
TRXConnector returns a Transceiver (TRX) connector.
func TXConnector ¶
TXConnector returns a Transmitter (TX) connector.
type ErrorCallback ¶
type ErrorCallback func(error)
ErrorCallback notifies happened error while reading PDU.
type PDUCallback ¶
PDUCallback handles received PDU.
type PDUErrorCallback ¶
PDUErrorCallback notifies fail-to-submit PDU with along error.
type Session ¶
type Session struct {
// contains filtered or unexported fields
}
Session represents session for TX, RX, TRX.
func NewSession ¶
func NewSession(c Connector, settings Settings, rebindingInterval time.Duration) (session *Session, err error)
NewSession creates new session for TX, RX, TRX.
Session will `non-stop`, automatically rebind (create new and authenticate connection with SMSC) when unexpected error happened.
`rebindingInterval` indicates duration that Session has to wait before rebinding again.
Setting `rebindingInterval <= 0` will disable `auto-rebind` functionality.
func (*Session) Transceiver ¶
func (s *Session) Transceiver() Transceiver
Transceiver returns bound Transceiver.
func (*Session) Transmitter ¶
func (s *Session) Transmitter() Transmitter
Transmitter returns bound Transmitter.
type Settings ¶
type Settings struct { // ReadTimeout is timeout for reading PDU from SMSC. // Underlying net.Conn will be stricted with ReadDeadline(now + timeout). // This setting is very important to detect connection failure. // // Must: ReadTimeout > max(0, EnquireLink) ReadTimeout time.Duration // WriteTimeout is timeout for submitting PDU. WriteTimeout time.Duration // EnquireLink periodically sends EnquireLink to SMSC. // The duration must not be smaller than 1 minute. // // Zero duration disables auto enquire link. EnquireLink time.Duration // OnPDU handles received PDU from SMSC. // // `Responded` flag indicates this pdu is responded automatically, // no manual respond needed. // // Will be ignored if OnAllPDU is set OnPDU PDUCallback // OnAllPDU handles all received PDU from SMSC. // // This pdu is NOT responded to automatically, // manual response/handling is needed // // User can also decide to close bind by retuning true, default is false OnAllPDU AllPDUCallback // OnReceivingError notifies happened error while reading PDU // from SMSC. OnReceivingError ErrorCallback // OnSubmitError notifies fail-to-submit PDU with along error. OnSubmitError PDUErrorCallback // OnRebindingError notifies error while rebinding. OnRebindingError ErrorCallback // OnClosed notifies `closed` event due to State. OnClosed ClosedCallback // OnRebind notifies `rebind` event due to State. OnRebind RebindCallback // contains filtered or unexported fields }
Settings for TX (transmitter), RX (receiver), TRX (transceiver).
type State ¶
type State byte
State represents Transmitter/Receiver/Transceiver state.
const ( // ExplicitClosing indicates that Transmitter/Receiver/Transceiver is closed // explicitly (from outside). ExplicitClosing State = iota // StoppingProcessOnly stops daemons but does not close underlying net conn. StoppingProcessOnly // InvalidStreaming indicates Transceiver/Receiver data reading state is // invalid due to network connection or SMSC responsed with an invalid PDU // which potentially damages other following PDU(s). // // In both cases, Transceiver/Receiver is closed implicitly. InvalidStreaming // ConnectionIssue indicates that Transmitter/Receiver/Transceiver is closed // due to network connection issue or SMSC is not available anymore. ConnectionIssue // UnbindClosing indicates Receiver got unbind request from SMSC and closed due to this request. UnbindClosing )
type Transceiver ¶
Transceiver interface.