Пример #1
0
 public void Dispose()
 {
     this._output   = null;
     this._writelog = null;
     NATIVE_TO_KCP.Remove(this._ikcpcb);
     KCPInterface.ikcp_release(this._ikcpcb);
 }
Пример #2
0
 internal KCPProxy(ushort id, KCP.OutputHandler output, KCP.LoggerHandler writelog)
 {
     if (NetworkConfig.USE_KCP_NATIVE)
     {
         KCPNative kcpNative;
         this._kcp = kcpNative = new KCPNative(NetworkConfig.CONN_KEY, id, output, writelog);
         kcpNative.SetLogMask(int.MaxValue);
     }
     else
     {
         this._kcp = new KCP(NetworkConfig.CONN_KEY, id, output, writelog);
     }
     this._kcp.NoDelay(NetworkConfig.KCP_NO_DELAY, NetworkConfig.KCP_INTERVAL, NetworkConfig.KCP_RESEND,
                       NetworkConfig.KCP_NC);
     this._kcp.WndSize(NetworkConfig.KCP_SND_WIN, NetworkConfig.KCP_REV_WIN);
     this._kcp.SetMtu(NetworkConfig.KCP_MTU);
 }
Пример #3
0
        public KCPNative(uint conv, uint user, KCP.OutputHandler output, KCP.LoggerHandler writelog)
        {
            int    size   = Marshal.SizeOf(user);
            IntPtr intPtr = Marshal.AllocHGlobal(size);

            Marshal.StructureToPtr(user, intPtr, false);
            this._ikcpcb = KCPInterface.ikcp_create(conv, intPtr);
            Marshal.FreeHGlobal(intPtr);
            NATIVE_TO_KCP[this._ikcpcb] = this;
            this._output   = output;
            this._writelog = writelog;
            IntPtr outputPtr = Marshal.GetFunctionPointerForDelegate(OUTPUT_DELEGATE);

            KCPInterface.ikcp_setoutput(this._ikcpcb, outputPtr);
            IntPtr logPtr = Marshal.GetFunctionPointerForDelegate(LOG_DELEGATE);

            KCPInterface.ikcp_setlog(this._ikcpcb, logPtr);
        }