Documentation
¶
Index ¶
- Constants
- Variables
- func GInfof(ctx context.Context, format string, v ...interface{})
- func GetLog() *glog.Logger
- func GetLogIns() *glog.Logger
- func NewSevConnector(conn net.Conn, conf SevConnectConf) *sevConnector
- func SetLog(inputLog *glog.Logger)
- 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 DefaultStore
- func (s DefaultStore) Clear(ctx context.Context) error
- func (s DefaultStore) Delete(ctx context.Context, sequenceNumber int32) error
- func (s DefaultStore) Get(ctx context.Context, sequenceNumber int32) (Request, bool)
- func (s DefaultStore) Length(ctx context.Context) (int, error)
- func (s DefaultStore) List(ctx context.Context) []Request
- func (s DefaultStore) Set(ctx context.Context, request Request) error
- type Dialer
- type ErrorCallback
- type PDUCallback
- type PDUErrorCallback
- type RebindCallback
- type Receiver
- type Request
- type RequestStore
- type Response
- type Session
- type SessionOption
- type Settings
- type SevConnectConf
- type State
- type TransceivableOption
- type Transceiver
- type Transmitter
- type WindowedRequestTracking
Constants ¶
const ( Alive int32 = iota Closed )
Variables ¶
var ( ErrWindowSizeEqualZero = errors.New("request window size cannot be 0") ErrExpireCheckTimerNotSet = errors.New("ExpireCheckTimer cannot be 0 if PduExpireTimeOut is set") ErrStoreAccessTimeOutEqualZero = errors.New("StoreAccessTimeOut window size cannot be 0") ErrWindowSizeNotAvailableOnReceiverBinds = errors.New("window size not available on receiver binds") )
var ( // ErrConnectionClosing indicates transmitter is closing. Can not send any PDU. ErrConnectionClosing = errors.New("connection is closing, can not send PDU to SMSC") ErrWindowsFull = errors.New("window full") )
var (
ErrWindowNotConfigured = errors.New("window settings not configured")
)
Functions ¶
func NewSevConnector ¶
func NewSevConnector(conn net.Conn, conf SevConnectConf) *sevConnector
Connection 创建一个服务端连接
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)
GetBindType() pdu.BindingType
}
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 DefaultStore ¶
type DefaultStore struct {
// contains filtered or unexported fields
}
func NewDefaultStore ¶
func NewDefaultStore() DefaultStore
func (DefaultStore) Delete ¶
func (s DefaultStore) Delete(ctx context.Context, sequenceNumber int32) error
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 RequestStore ¶
type RequestStore interface {
Set(ctx context.Context, request Request) error
Get(ctx context.Context, sequenceNumber int32) (Request, bool)
List(ctx context.Context) []Request
Delete(ctx context.Context, sequenceNumber int32) error
Clear(ctx context.Context) error
Length(ctx context.Context) (int, error)
}
RequestStore interface used for WindowedRequestTracking
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, opts ...SessionOption) (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) GetWindowSize ¶
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 SessionOption ¶
type SessionOption func(session *Session)
func WithRequestStore ¶
func WithRequestStore(store RequestStore) SessionOption
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 or WindowedRequestTracking 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
//
// Will be ignored if WindowedRequestTracking is set
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
// SMPP Bind Window tracking feature config
*WindowedRequestTracking
// 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 TransceivableOption ¶
type TransceivableOption func(session *Session)
type Transceiver ¶
Transceiver interface.
type Transmitter ¶
Transmitter interface.
type WindowedRequestTracking ¶
type WindowedRequestTracking struct {
// OnReceivedPduRequest handles received PDU request from SMSC.
//
// User can also decide to close bind by retuning true, default is false
OnReceivedPduRequest AllPDUCallback
// OnExpectedPduResponse handles expected PDU response from SMSC.
// Only triggered when the original request is found in the window cache
//
// Handle is optional
// If not set, response will be dropped
OnExpectedPduResponse func(Response)
// OnUnexpectedPduResponse handles unexpected PDU response from SMSC.
// Only triggered if the original request is not found in the window cache
//
// Handle is optional
// If not set, response will be dropped
OnUnexpectedPduResponse func(pdu.PDU)
// OnExpiredPduRequest handles expired PDU request with no response received
//
// Mandatory: the PduExpireTimeOut must be set
// Handle is optional
// If not set, expired PDU will be removed from cache
// the bind can be closed by retuning true on closeBind.
OnExpiredPduRequest func(pdu.PDU) (closeBind bool)
// OnClosePduRequest will return all PDU request found in the store when the bind closes
OnClosePduRequest func(pdu.PDU)
// Set the number of second to expire a request sent to the SMSC
//
// Zero duration disables pdu expire check and the cache may fill up over time with expired PDU request
// Recommended: eual or less to the value set in ReadTimeout + EnquireLink
PduExpireTimeOut time.Duration
// The time period between each check of the expired PDU in the cache
//
// Zero duration disables pdu expire check and the cache may fill up over time with expired PDU request
// Recommended: Less or half the time set in for PduExpireTimeOut
// Don't be too aggressive, there is a performance hit if the check is done often
ExpireCheckTimer time.Duration
// The maximum number of pending request sent to the SMSC
//
// Maximum value is 255
MaxWindowSize uint8
// if enabled, EnquireLink and Unbind request will be responded to automatically
EnableAutoRespond bool
// Set the number of millisecond to expire a request to store or retrieve data from request store
//
// Value must be greater than 0
// 200 to 1000 is a good starting point
StoreAccessTimeOut time.Duration
}
WindowedRequestTracking settings for TX (transmitter) and TRX (transceiver) request store.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
example
|
|
|
transceiver_with_auto_response
command
|
|
|
transceiver_with_manual_response
command
|
|
|
transeiver_with_custom_store
command
|
|