func (cu *CUClient) closeSource(clientID uint32, id string) { var err error proto := new(base.Proto) proto.RD.BaseHD.CommandId = base.CLOSE_RESOURCE_CMD proto.RD.HD.ClientIdent = clientID proto.RD.HD.ContextType = base.CONTEXT_JSON proto.RD.HD.TransferType = base.TRANSFER_RAW resourceJson := base.CloseResParamJson{id} requestJson := base.RequestJson{"", "ns", "close", resourceJson} b, err := json.Marshal(requestJson) if err != nil { cu.handleError(err) return } proto.EncodeBody(b) result := proto.EncodeHdr() n, err := cu.connSocket.Write(result.Bytes()) if err != nil { cu.handleError(err) return } n = n _, bErr := cu.connSocket.Write(proto.BD.Data) if err != nil { cu.handleError(bErr) } return }
func (chn *Channel) handleWriteSocket(proto *base.Proto) { if atomic.CompareAndSwapUint32(&chn.valid, 0, 0) { return } cmdID := proto.RD.BaseHD.CommandId & 0x7f if cmdID == base.HEART_CMD { heartHdr := new(base.BaseHeader) heartHdr.CommandId = proto.RD.BaseHD.CommandId msg := heartHdr.Encode() _, err := chn.connSocket.Write(msg.Bytes()) if err != nil { chn.handleError(base.DTerror{"Send Error"}) } return } fmt.Println("handleWriteSocket ", cmdID) msg := proto.EncodeHdr() _, err := chn.connSocket.Write(msg.Bytes()) if err != nil { chn.handleError(base.DTerror{"Send Error"}) } _, dErr := chn.connSocket.Write(proto.BD.Data) if dErr != nil { chn.handleError(base.DTerror{"Send Error"}) } base.PutProto(proto) }
func (cu *CUClient) openSource(clientID uint32, id string) error { proto := new(base.Proto) proto.RD.BaseHD.CommandId = base.OPEN_RESOURCE_CMD proto.RD.HD.ClientIdent = clientID proto.RD.HD.ContextType = base.CONTEXT_JSON proto.RD.HD.TransferType = base.TRANSFER_RAW resourceJson := base.OpenResParamJson{id, 10} requestJson := base.RequestJson{cu.token, "ns", "open", resourceJson} b, err := json.Marshal(requestJson) if err != nil { cu.handleError(err) return err } proto.EncodeBody(b) result := proto.EncodeHdr() n, err := cu.connSocket.Write(result.Bytes()) if err != nil { cu.handleError(err) return err } n = n _, bErr := cu.connSocket.Write(proto.BD.Data) if err != nil { cu.handleError(bErr) return err } go cu.timerClear() return err }
func (pu *PUDevice) handleWriteSocket(proto *base.Proto) { if atomic.CompareAndSwapUint32(&pu.Valid, 0, 0) { return } cmdID := proto.RD.BaseHD.CommandId & 0x7f if cmdID == base.HEART_CMD { heartHdr := new(base.BaseHeader) heartHdr.CommandId = proto.RD.BaseHD.CommandId msg := heartHdr.Encode() _, err := pu.connSocket.Write(msg.Bytes()) if err != nil { pu.handleError(base.DTerror{"Send Error " + err.Error()}) } return } msg := proto.EncodeHdr() _, err := pu.connSocket.Write(msg.Bytes()) if err != nil { pu.handleError(base.DTerror{"Send Error " + err.Error()}) return } _, dErr := pu.connSocket.Write(proto.BD.Data) if dErr != nil { pu.handleError(base.DTerror{"Send Error" + err.Error()}) return } }