internal static bool GetCommunicationModuleOffset(this IMessagePassingEndpoint storage, string moduleName, out ushort synReqOffset, out ushort synReqRspOffset, out ushort asynReqOffset, out ushort asynReqRspOffset) { /****************** * Comm. protocol: * - REQUEST : [char_cnt, char[] moduleName] * - RESPONSE: [int synReqOffset, int synReqRspOffset, int asynReqOffset, int asynReqRspOffset] * An response error code other than E_SUCCESS indicates failure of remote module lookup. ******************/ using (TrinityMessage tm = new TrinityMessage( TrinityMessageType.PRESERVED_SYNC_WITH_RSP, (ushort)RequestType.GetCommunicationModuleOffsets, size: sizeof(int) + sizeof(char) * moduleName.Length)) { PointerHelper sp = PointerHelper.New(tm.Buffer + TrinityMessage.Offset); *sp.ip++ = moduleName.Length; BitHelper.WriteString(moduleName, sp.bp); TrinityResponse response = null; bool ret; try { storage.SendMessage(tm, out response); ret = (response.ErrorCode == TrinityErrorCode.E_SUCCESS); } catch (System.IO.IOException) { ret = false; } if (ret) { sp.bp = response.Buffer + response.Offset; int synReq_msg = *sp.ip++; int synReqRsp_msg = *sp.ip++; int asynReq_msg = *sp.ip++; int asynReqRsp_msg = *sp.ip++; synReqOffset = (ushort)synReq_msg; synReqRspOffset = (ushort)synReqRsp_msg; asynReqOffset = (ushort)asynReq_msg; asynReqRspOffset = (ushort)asynReqRsp_msg; } else { synReqOffset = 0; synReqRspOffset = 0; asynReqOffset = 0; asynReqRspOffset = 0; } response?.Dispose(); return(ret); } }
public unsafe TrinityErrorCode LoadCell(long cellId, out byte[] cellBuff, out ushort cellType) { using (var req = new __CellIdStructWriter(cellId)) { TrinityResponse rsp = null; TrinityErrorCode errcode = TrinityErrorCode.E_RPC_EXCEPTION; cellBuff = null; cellType = 0; try { var sp = PointerHelper.New(req.buffer); *sp.ip++ = TrinityProtocol.TrinityMsgHeader + sizeof(long); *sp.sp++ = (short)TrinityMessageType.SYNC_WITH_RSP; *sp.sp++ = (short)TSL.CommunicationModule.TrinityClientModule.SynReqRspMessageType.LoadCell; m_mod.SendMessage(m_ep, req.buffer, req.BufferLength, out rsp); sp = PointerHelper.New(rsp.Buffer); errcode = (TrinityErrorCode)(*sp.ip++); if (errcode == TrinityErrorCode.E_SUCCESS) { var length = *sp.ip++; cellType = (ushort)(*sp.sp++); cellBuff = new byte[length]; fixed(byte *p = cellBuff) { Memory.memcpy(p, sp.bp, (ulong)length); } } /* otherwise, fails with returned error code */ } finally { rsp?.Dispose(); } return(errcode); } }
private unsafe TrinityErrorCode _SendCellPayload(long cellId, byte *buff, int size, ushort?cellType, short msgId) { //header: cellId, size, type int header_len = TrinityProtocol.MsgHeader + sizeof(long) + sizeof(int) + (cellType.HasValue? sizeof(ushort): 0); byte * header = stackalloc byte[header_len]; byte ** holder = stackalloc byte *[2]; int * length = stackalloc int[2]; PointerHelper sp = PointerHelper.New(header); *sp.ip++ = header_len + size - TrinityProtocol.SocketMsgHeader; *sp.sp++ = (short)TrinityMessageType.SYNC_WITH_RSP; *sp.sp++ = msgId; *sp.lp++ = cellId; *sp.ip++ = size; if (cellType.HasValue) { *sp.sp++ = (short)cellType; } holder[0] = header; holder[1] = buff; length[0] = header_len; length[1] = size; TrinityResponse rsp = null; try { m_mod.SendMessage(m_ep, holder, length, 2, out rsp); return(*(TrinityErrorCode *)(rsp.Buffer)); } finally { rsp?.Dispose(); } }