Пример #1
0
        /// <summary>
        /// Receive the next packet for the local user, and information associated with this packet, if it exists.
        /// </summary>
        /// <param name="options">Information about who is requesting the size of their next packet, and how much data can be stored safely</param>
        /// <param name="outPeerId">The Remote User who sent data. Only set if there was a packet to receive.</param>
        /// <param name="outSocketId">The Socket ID of the data that was sent. Only set if there was a packet to receive.</param>
        /// <param name="outChannel">The channel the data was sent on. Only set if there was a packet to receive.</param>
        /// <param name="outData">Buffer to store the data being received. Must be at least <see cref="GetNextReceivedPacketSize" /> in length or data will be truncated</param>
        /// <param name="outBytesWritten">The amount of bytes written to OutData. Only set if there was a packet to receive.</param>
        /// <returns>
        /// <see cref="Result" />::<see cref="Result.Success" /> - If the packet was received successfully
        /// <see cref="Result" />::<see cref="Result.InvalidParameters" /> - If input was invalid
        /// <see cref="Result" />::<see cref="Result.NotFound" /> - If there are no packets available for the requesting user
        /// </returns>
        public Result ReceivePacket(ReceivePacketOptions options, out ProductUserId outPeerId, out SocketId outSocketId, out byte outChannel, out byte[] outData)
        {
            System.IntPtr optionsAddress = new System.IntPtr();
            Helper.TryMarshalSet <ReceivePacketOptionsInternal, ReceivePacketOptions>(ref optionsAddress, options);

            var outPeerIdAddress = System.IntPtr.Zero;

            var outSocketIdInternal = Helper.GetDefault <SocketIdInternal>();

            outChannel = Helper.GetDefault <byte>();

            System.IntPtr outDataAddress  = System.IntPtr.Zero;
            uint          outBytesWritten = MaxPacketSize;

            Helper.TryMarshalAllocate(ref outDataAddress, outBytesWritten);

            var funcResult = EOS_P2P_ReceivePacket(InnerHandle, optionsAddress, ref outPeerIdAddress, ref outSocketIdInternal, ref outChannel, outDataAddress, ref outBytesWritten);

            Helper.TryMarshalDispose(ref optionsAddress);

            Helper.TryMarshalGet(outPeerIdAddress, out outPeerId);

            Helper.TryMarshalGet(outSocketIdInternal, out outSocketId);

            Helper.TryMarshalGet(outDataAddress, out outData, outBytesWritten);
            Helper.TryMarshalDispose(ref outDataAddress);

            return(funcResult);
        }
 public void Set(ReceivePacketOptions other)
 {
     if (other != null)
     {
         m_ApiVersion     = P2PInterface.ReceivepacketApiLatest;
         LocalUserId      = other.LocalUserId;
         MaxDataSizeBytes = other.MaxDataSizeBytes;
         RequestedChannel = other.RequestedChannel;
     }
 }
Пример #3
0
        /// <summary>
        /// 短縮 ReceivePacket
        /// </summary>
        /// <param name="p2p">P2PInterface</param>
        /// <param name="localUserId">ログインユーザーID</param>
        /// <param name="maxDataSizeBytes">受信バイトサイズ</param>
        /// <param name="requestedChannel">チャンネルID</param>
        public static (ProductUserId, SocketId, byte, byte[], uint) ReceivePacket(this P2PInterface p2p, ProductUserId localUserId, uint maxDataSizeBytes, byte requestedChannel)
        {
            var op = new ReceivePacketOptions
            {
                LocalUserId      = localUserId,
                MaxDataSizeBytes = maxDataSizeBytes,
                RequestedChannel = requestedChannel
            };

            // ※ 配列作っておかないとエラーになる
            byte[] rawData = new byte[maxDataSizeBytes];
            var    result  = p2p.ReceivePacket(op, out ProductUserId remoteUserId, out SocketId socketId, out byte channel, ref rawData, out uint outBytesWritten);

            if (result != Result.Success)
            {
                Debug.LogError($"error {DebugTools.GetClassMethodName()}:{result}");
                return(default);