當前位置: 首頁>>代碼示例>>Golang>>正文


Golang Body.Header方法代碼示例

本文整理匯總了Golang中github.com/fiorix/go-smpp/smpp/pdu.Body.Header方法的典型用法代碼示例。如果您正苦於以下問題:Golang Body.Header方法的具體用法?Golang Body.Header怎麽用?Golang Body.Header使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/fiorix/go-smpp/smpp/pdu.Body的用法示例。


在下文中一共展示了Body.Header方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: do

func (t *Transmitter) do(p pdu.Body) (*tx, error) {
	t.conn.Lock()
	notbound := t.conn.client == nil
	t.conn.Unlock()
	if notbound {
		return nil, ErrNotBound
	}
	rc := make(chan *tx, 1)
	seq := p.Header().Seq
	t.tx.Lock()
	t.tx.inflight[seq] = rc
	t.tx.Unlock()
	defer func() {
		close(rc)
		t.tx.Lock()
		delete(t.tx.inflight, seq)
		t.tx.Unlock()
	}()
	err := t.conn.Write(p)
	if err != nil {
		return nil, err
	}
	select {
	case resp := <-rc:
		return resp, nil
	case <-time.After(time.Second):
		return nil, errors.New("timeout waiting for response")
	}
}
開發者ID:rinor,項目名稱:sms-api-server,代碼行數:29,代碼來源:transmitter.go

示例2: Handler

// Handler handles DeliverSM coming from a Transceiver SMPP connection.
// It broadcasts received delivery receipt to all registered peers.
func (pool *deliveryPool) Handler(p pdu.Body) {
	switch p.Header().ID {
	case pdu.DeliverSMID:
		f := p.Fields()
		dr := &DeliveryReceipt{
			Src:  f[pdufield.SourceAddr].String(),
			Dst:  f[pdufield.DestinationAddr].String(),
			Text: f[pdufield.ShortMessage].String(),
		}
		pool.Broadcast(dr)
	}
}
開發者ID:DisruptiveMind,項目名稱:go-smpp,代碼行數:14,代碼來源:pool.go

示例3: do

func (t *Transmitter) do(p pdu.Body) (*tx, error) {
	t.conn.Lock()
	notbound := t.conn.client == nil
	t.conn.Unlock()
	if notbound {
		return nil, ErrNotBound
	}
	if t.conn.WindowSize > 0 {
		inflight := uint(atomic.AddInt32(&t.tx.count, 1))
		defer func(t *Transmitter) { atomic.AddInt32(&t.tx.count, -1) }(t)
		if inflight > t.conn.WindowSize {
			return nil, ErrMaxWindowSize
		}
	}
	rc := make(chan *tx, 1)
	seq := p.Header().Seq
	t.tx.Lock()
	t.tx.inflight[seq] = rc
	t.tx.Unlock()
	defer func() {
		close(rc)
		t.tx.Lock()
		delete(t.tx.inflight, seq)
		t.tx.Unlock()
	}()
	err := t.conn.Write(p)
	if err != nil {
		return nil, err
	}
	select {
	case resp := <-rc:
		if resp.Err != nil {
			return nil, resp.Err
		}
		return resp, nil
	case <-t.conn.respTimeout():
		return nil, errors.New("timeout waiting for response")
	}
}
開發者ID:fiorix,項目名稱:go-smpp,代碼行數:39,代碼來源:transmitter.go

示例4: pduHandler

func pduHandler(c smpptest.Conn, p pdu.Body) {
	src := p.Fields()[pdufield.SourceAddr]
	fail := src != nil && src.String() == "root"
	switch p.Header().ID {
	case pdu.SubmitSMID:
		r := pdu.NewSubmitSMResp()
		r.Header().Seq = p.Header().Seq
		if fail {
			r.Header().Status = 0x00000045 // submitsm failed
		} else {
			r.Fields().Set(pdufield.MessageID, "foobar")
		}
		c.Write(r)
		rd := p.Fields()[pdufield.RegisteredDelivery]
		if rd == nil || rd.Bytes()[0] == 0 {
			return
		}
		r = pdu.NewDeliverSM()
		rf := r.Fields()
		pf := p.Fields()
		rf.Set(pdufield.SourceAddr, pf[pdufield.SourceAddr])
		rf.Set(pdufield.DestinationAddr, pf[pdufield.DestinationAddr])
		rf.Set(pdufield.ShortMessage, "delivery receipt here")
		c.Write(r)
	case pdu.QuerySMID:
		r := pdu.NewQuerySMResp()
		r.Header().Seq = p.Header().Seq
		if fail {
			r.Header().Status = 0x00000067 // querysm failed
		} else {
			pf := p.Fields()
			rf := r.Fields()
			rf.Set(pdufield.MessageID, pf[pdufield.MessageID])
			rf.Set(pdufield.MessageState, 2) // DELIVERED
		}
		c.Write(r)
	default:
		smpptest.EchoHandler(c, p)
	}
}
開發者ID:DisruptiveMind,項目名稱:go-smpp,代碼行數:40,代碼來源:main_test.go


注:本文中的github.com/fiorix/go-smpp/smpp/pdu.Body.Header方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。