Documentation ¶
Index ¶
- Constants
- Variables
- type Auth
- 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 Receiver
- type Session
- type Settings
- type State
- type Transceiver
- type Transmitter
Constants ¶
const ( Alive int32 = iota Closed )
Variables ¶
var ( // ErrConnectionClosing indicates transmitter is closing. Can not send any PDU. ErrConnectionClosing = fmt.Errorf("connection is closing, can not send PDU to SMSC") )
Functions ¶
This section is empty.
Types ¶
type Auth ¶ added in v0.1.4
type Auth struct { // SMSC is SMSC address. SMSC string SystemID string Password string SystemType string }
Auth represents basic authentication to SMSC.
type ClosedCallback ¶ added in v0.1.4
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 ¶ added in v0.1.4
func NewConnection(conn net.Conn) (c *Connection)
NewConnection returns a Connection.
func (*Connection) Close ¶ added in v0.1.4
func (c *Connection) Close() error
Close closes the connection. Any blocked Read or Write operations will be unblocked and return errors.
func (*Connection) LocalAddr ¶ added in v0.1.4
func (c *Connection) LocalAddr() net.Addr
LocalAddr returns the local network address.
func (*Connection) Read ¶ added in v0.1.4
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 ¶ added in v0.1.4
func (c *Connection) RemoteAddr() net.Addr
RemoteAddr returns the remote network address.
func (*Connection) SetDeadline ¶ added in v0.1.4
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 ¶ added in v0.1.4
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 ¶ added in v0.1.4
func (c *Connection) SetReadTimeout(t time.Duration) error
SetReadTimeout is equivalent to ReadDeadline(now + timeout)
func (*Connection) SetWriteDeadline ¶ added in v0.1.4
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 ¶ added in v0.1.4
func (c *Connection) SetWriteTimeout(t time.Duration) error
SetWriteTimeout is equivalent to WriteDeadline(now + timeout)
type Connector ¶ added in v0.1.4
type Connector interface {
Connect() (conn *Connection, err error)
}
Connector is connection factory interface.
func RXConnector ¶ added in v0.1.4
RXConnector returns a Receiver (RX) connector.
func TRXConnector ¶ added in v0.1.4
TRXConnector returns a Transceiver (TRX) connector.
func TXConnector ¶ added in v0.1.4
TXConnector returns a Transmitter (TX) connector.
type ErrorCallback ¶ added in v0.1.4
type ErrorCallback func(error)
ErrorCallback notifies happened error while reading PDU.
type PDUCallback ¶ added in v0.1.4
PDUCallback handles received PDU.
type PDUErrorCallback ¶ added in v0.1.4
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 ¶ added in v0.1.4
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 ¶ added in v0.1.4
func (s *Session) Transceiver() Transceiver
Transceiver returns bound Transceiver.
func (*Session) Transmitter ¶ added in v0.1.4
func (s *Session) Transmitter() Transmitter
Transmitter returns bound Transmitter.
type Settings ¶ added in v0.1.4
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. OnPDU PDUCallback // 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 // contains filtered or unexported fields }
Settings for TX (transmitter), RX (receiver), TRX (transceiver).
type State ¶ added in v0.1.4
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 ¶ added in v0.1.4
Transceiver interface.