本文整理汇总了Golang中github.com/spinlock/xserver/pkg/xserver/amf/amf0.Reader类的典型用法代码示例。如果您正苦于以下问题:Golang Reader类的具体用法?Golang Reader怎么用?Golang Reader使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Reader类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: onPlay
func (h *streamHandler) onPlay(callback float64, r *amf0.Reader) error {
if err := h.disenage(); err != nil {
return errors.New("stream.onPlay.disenage")
}
if stream, err := r.ReadString(); err != nil {
return errors.New("stream.onPlay.read stream")
} else {
if p := newPublication(stream); p.add(h) {
if err := h.newPlayResetResponse(stream, callback); err != nil {
return errors.New("stream.onPlay.reset response")
}
if err := h.newPlaySuccessResponse(stream, callback); err != nil {
return errors.New("stream.onPlay.play response")
}
h.play.p = p
h.play.callback = callback
h.bound++
if err := h.newPlayBoundResponse(h.bound); err != nil {
return errors.New("stream.onPlay.bound response")
}
} else {
if err := h.newPlayFailedResponse(stream, callback); err != nil {
return errors.New("stream.onPlay.failed response")
}
}
return nil
}
}
开发者ID:Yuhang,项目名称:xserver,代码行数:28,代码来源:stream.go
示例2: onDefault
func (h *streamHandler) onDefault(name string, callback float64, r *amf0.Reader) error {
if p := h.publish.p; p == nil {
xlog.OutLog.Printf("[session]: xid = %d, reader.fid = %d, writer.fid = %d, message on non-published stream\n", h.session.xid, h.fr.fid, h.fw.fid)
return nil
} else if p.rpc {
xlog.OutLog.Printf("[session]: xid = %d, reader.fid = %d, writer.fid = %d, unhandled call on rpc stream\n", h.session.xid, h.fr.fid, h.fw.fid)
return nil
} else {
if w, err := newAmfBytesWriter(name); err != nil {
return errors.New("stream.onAmfData.write name")
} else if err := w.WriteBytes(r.Bytes()); err != nil {
return errors.New("stream.onAmfData.write body")
} else {
data := split(w.Bytes())
call := func(x *streamHandler) {
s := x.session
s.Lock()
defer s.Unlock()
if s.closed || x.play.p != p {
return
}
defer s.flush()
x.fw.AddFragments(p.reliable, data...)
}
async.Call(p.gid, func() {
if l, ok := p.list(); ok && l != nil {
for e := l.Front(); e != nil; e = e.Next() {
call(e.Value.(*streamHandler))
}
}
})
}
return nil
}
}
开发者ID:Yuhang,项目名称:xserver,代码行数:35,代码来源:stream.go
示例3: onSetPeerInfo
func (h *connHandler) onSetPeerInfo(callback float64, r *amf0.Reader) error {
const (
keepAliveServer, keepAlivePeer = 1000 * 20, 1000 * 5
)
addrs := []*net.UDPAddr{}
for r.Len() != 0 {
if s, err := r.ReadString(); err != nil {
return errors.New("conn.onSetPeerInfo.read address")
} else if len(s) != 0 {
if addr, err := net.ResolveUDPAddr("udp", s); err == nil {
if ip4 := addr.IP.To4(); ip4 != nil {
addr.IP = ip4
}
addrs = append(addrs, addr)
} else {
xlog.ErrLog.Printf("[session]: parse addr = %s, error = '%v', addr = [%s]\n", s, addr)
}
}
}
h.session.addrs = addrs
if err := h.newKeepAliveResponse(keepAliveServer, keepAlivePeer); err != nil {
return errors.New("conn.onSetPeerInfo.keep alive response")
}
return nil
}
开发者ID:Yuhang,项目名称:xserver,代码行数:25,代码来源:conn.go
示例4: onConnect
func (h *connHandler) onConnect(callback float64, r *amf0.Reader) error {
if obj, err := r.ReadObject(); err != nil {
return errors.New("conn.onConnect.read object")
} else if amfx, ok := obj.GetNumber("objectEncoding"); !ok {
return errors.New("conn.onConnect.amf version")
} else if amfx == 0 {
if err := h.newAmf0RejectResponse(callback); err != nil {
return errors.New("conn.onConnect.reject amf0 response")
}
} else {
if err := h.newSuccessResponse(callback, h.session.xid, h.session.raddr); err != nil {
return errors.New("conn.onConnect.success response")
}
}
return nil
}
开发者ID:Yuhang,项目名称:xserver,代码行数:16,代码来源:conn.go
示例5: onBroadcastByXid
func (h *streamHandler) onBroadcastByXid(callback float64, r *amf0.Reader, reliable bool) error {
if s, err := r.ReadString(); err != nil {
return errors.New("stream.onBroadcastByXid.read xids")
} else if len(s) == 0 {
return nil
} else {
xids := make([]uint32, 0, 32)
for _, v := range strings.Split(s, "_") {
if x, err := strconv.ParseInt(v, 10, 64); err != nil {
return errors.New("stream.onBroadcastByXid.parse xid")
} else {
xids = append(xids, uint32(x))
}
}
BroadcastByXid(xids, r.Bytes(), h.session.xid, reliable)
return nil
}
}
开发者ID:Yuhang,项目名称:xserver,代码行数:18,代码来源:stream.go
示例6: handleAmfMessage
func handleAmfMessage(h messageHandler, r *amf0.Reader, withcallback bool) error {
var err error
name := ""
if name, err = r.ReadString(); err != nil {
return errors.New("message.amf.read name")
}
callback := float64(0)
if withcallback {
if callback, err = r.ReadNumber(); err != nil {
return errors.New("message.amf.read callback")
}
if r.Len() != 0 && r.TestNull() {
if err := r.ReadNull(); err != nil {
return errors.New("message.amf.read null")
}
}
}
return h.OnAmfMessage(name, callback, r)
}
开发者ID:Yuhang,项目名称:xserver,代码行数:19,代码来源:message.go
示例7: onPublish
func (h *streamHandler) onPublish(callback float64, r *amf0.Reader) error {
if err := h.disenage(); err != nil {
return errors.New("stream.onPublish.disenage")
}
if stream, err := r.ReadString(); err != nil {
return errors.New("stream.onPublish.read stream")
} else {
if p := newPublication(stream); p.start(h) {
if err := h.newPublishSuccessResponse(stream, callback); err != nil {
return errors.New("stream.onPublish.publish response")
}
h.publish.p, h.unstable = p, !p.reliable
h.publish.callback = callback
if !p.rpc {
call := func(x *streamHandler) {
s := x.session
s.Lock()
defer s.Unlock()
if s.closed || x.play.p != p {
return
}
defer s.flush()
x.newPublishNotifyResponse(p.name, x.play.callback)
}
async.Call(p.gid, func() {
if l, _ := p.list(); l != nil {
for e := l.Front(); e != nil; e = e.Next() {
call(e.Value.(*streamHandler))
}
}
})
}
} else {
if err := h.newPublishFailedResponse(stream, callback); err != nil {
return errors.New("stream.onPublish.failed response")
}
}
return nil
}
}
开发者ID:Yuhang,项目名称:xserver,代码行数:40,代码来源:stream.go
示例8: onRelay
func (h *connHandler) onRelay(callback float64, r *amf0.Reader) error {
if pidss, err := r.ReadString(); err != nil {
return errors.New("conn.onRelay.read pid")
} else if pidbs, err := hex.DecodeString(pidss); err != nil || len(pidbs) != 0x20 {
return errors.New("conn.onRelay.decode pid")
} else if bs, err := newRelayMessage(h.session.pid, r.Bytes()); err != nil {
return errors.New("conn.onRelay.generate response")
} else {
async.Call(uint64(h.session.xid), func() {
if s := FindByPid(string(pidbs)); s != nil {
s.Lock()
defer s.Unlock()
if s.closed {
return
}
defer s.flush()
if fw := s.mainfw; fw != nil {
fw.AddFragments(true, split(bs)...)
}
}
})
return nil
}
}
开发者ID:Yuhang,项目名称:xserver,代码行数:24,代码来源:conn.go
示例9: onProxySend
func (h *streamHandler) onProxySend(callback float64, r *amf0.Reader, reliable bool) error {
rpc.Call(h.session.xid, h.session.raddr, 0, r.Bytes(), reliable)
return nil
}
开发者ID:Yuhang,项目名称:xserver,代码行数:4,代码来源:stream.go
示例10: onRequest
func (h *connHandler) onRequest(callback float64, r *amf0.Reader) error {
rpc.Call(h.session.xid, h.session.raddr, callback, r.Bytes(), true)
return nil
}
开发者ID:Yuhang,项目名称:xserver,代码行数:4,代码来源:conn.go
注:本文中的github.com/spinlock/xserver/pkg/xserver/amf/amf0.Reader类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论