Esempio n. 1
0
        static void c_aio_handler(int err, IntPtr size, IntPtr h)
        {
            int idx2 = (int)h;
            var hr   = GlobalInterOpLookupTable.GetRelease(idx2) as AioHandler;

            hr(new ErrorCode(err), size.ToInt32());
        }
Esempio n. 2
0
        // TODO: what if the task is cancelled
        static void c_task_handler(IntPtr h)
        {
            int idx2 = (int)h;
            var hr   = GlobalInterOpLookupTable.GetRelease(idx2) as task_handler;

            hr();
        }
Esempio n. 3
0
        //
        // this gives you the task handle so you can wait or cancel
        // the task, with the cost of add/ref the task handle
        //
        public static SafeTaskHandle CallAsync2(
            TaskCode evt,
            Servicelet callbackOwner,
            task_handler callback,
            int hash = 0,
            int delay_milliseconds          = 0,
            int timer_interval_milliseconds = 0
            )
        {
            int    idx = GlobalInterOpLookupTable.Put(callback);
            IntPtr task;

            if (timer_interval_milliseconds == 0)
            {
                task = Native.dsn_task_create(evt, _c_task_handler_holder, (IntPtr)idx, hash);
            }
            else
            {
                task = Native.dsn_task_create_timer(evt, _c_task_handler_holder, (IntPtr)idx, hash, timer_interval_milliseconds);
            }

            var ret = new SafeTaskHandle(task);

            Native.dsn_task_call(task, callbackOwner != null ? callbackOwner.tracker() : IntPtr.Zero, delay_milliseconds);
            return(ret);
        }
Esempio n. 4
0
        //
        // this gives you the task handle so you can wait or cancel
        // the task, with the cost of add/ref the task handle
        //
        public static SafeTaskHandle RpcCallAsync2(
            RpcAddress server,
            RpcWriteStream requestStream,
            Clientlet callbackOwner,
            RpcResponseHandler callback,
            int replyHash = 0
            )
        {
            Logging.dassert(requestStream.IsFlushed(),
                            "RpcWriteStream must be flushed after write in the same thread");

            var idx  = GlobalInterOpLookupTable.Put(callback);
            var task = Native.dsn_rpc_create_response_task(
                requestStream.DangerousGetHandle(),
                _c_rpc_response_handler_holder,
                (IntPtr)idx,
                replyHash,
                callbackOwner?.tracker() ?? IntPtr.Zero
                );

            var ret = new SafeTaskHandle(task, idx);

            Native.dsn_rpc_call(server.addr, task);
            return(ret);
        }
Esempio n. 5
0
        static void c_timer_task_handler(IntPtr h)
        {
            var idx2 = (int)h;
            var hr   = GlobalInterOpLookupTable.Get(idx2) as task_handler;

            hr();
        }
Esempio n. 6
0
File: Utils.cs Progetto: zmyer/rDSN
 public bool Cancel(bool waitFinished, out bool finished)
 {
     if (Native.dsn_task_cancel2(handle, waitFinished, out finished))
     {
         GlobalInterOpLookupTable.GetRelease(_callback_index);
         return(true);
     }
     return(false);
 }
Esempio n. 7
0
        public static void CallAsync(
            TaskCode evt,
            Clientlet callbackOwner,
            task_handler callback,
            int hash = 0,
            int delay_milliseconds = 0
            )
        {
            var idx  = GlobalInterOpLookupTable.Put(callback);
            var task = Native.dsn_task_create(evt, _c_task_handler_holder, (IntPtr)idx, hash, callbackOwner?.tracker() ?? IntPtr.Zero);

            Native.dsn_task_call(task, delay_milliseconds);
        }
Esempio n. 8
0
        static void c_rpc_response_handler(int err, IntPtr reqc, IntPtr respc, IntPtr h)
        {
            int idx2 = (int)h;
            var hr   = GlobalInterOpLookupTable.GetRelease(idx2) as RpcResponseHandler;

            if (err == 0)
            {
                var rms = new RpcReadStream(respc, false);
                hr(new ErrorCode(err), rms);
            }
            else
            {
                hr(new ErrorCode(err), null);
            }
        }
Esempio n. 9
0
        public static dsn_task_t CopyRemoteDirectory(
            dsn_address_t remote,
            string source_dir,
            string dest_dir,
            bool overwrite,
            TaskCode callbackCode,
            Servicelet callbackOwner,
            AioHandler callback,
            int hash = 0
            )
        {
            int        idx  = GlobalInterOpLookupTable.Put(callback);
            dsn_task_t task = Native.dsn_file_create_aio_task(callbackCode, _c_aio_handler_holder, (IntPtr)idx, hash);

            Native.dsn_file_copy_remote_directory(remote, source_dir, dest_dir, overwrite, task, callbackOwner != null ? callbackOwner.tracker() : IntPtr.Zero);
            return(task);
        }
Esempio n. 10
0
        public static dsn_task_t FileWrite(
            dsn_handle_t hFile,
            byte[] buffer,
            int count,
            UInt64 offset,
            TaskCode callbackCode,
            Servicelet callbackOwner,
            AioHandler callback,
            int hash = 0
            )
        {
            int        idx  = GlobalInterOpLookupTable.Put(callback);
            dsn_task_t task = Native.dsn_file_create_aio_task(callbackCode, _c_aio_handler_holder, (IntPtr)idx, hash);

            Native.dsn_file_write(hFile, buffer, count, offset, task, callbackOwner != null ? callbackOwner.tracker() : IntPtr.Zero);
            return(task);
        }
Esempio n. 11
0
        public static SafeTaskHandle CopyRemoteDirectory(
            ulong remote,
            string source_dir,
            string dest_dir,
            bool overwrite,
            TaskCode callbackCode,
            Clientlet callbackOwner,
            AioHandler callback,
            int hash = 0
            )
        {
            var idx  = GlobalInterOpLookupTable.Put(callback);
            var task = Native.dsn_file_create_aio_task(callbackCode, _c_aio_handler_holder, (IntPtr)idx, hash, callbackOwner?.tracker() ?? IntPtr.Zero);

            Native.dsn_file_copy_remote_directory(remote, source_dir, dest_dir, overwrite, task);
            return(new SafeTaskHandle(task, idx));
        }
Esempio n. 12
0
        public static SafeTaskHandle FileWrite(
            dsn_handle_t hFile,
            byte[] buffer,
            int count,
            ulong offset,
            TaskCode callbackCode,
            Clientlet callbackOwner,
            AioHandler callback,
            int hash = 0
            )
        {
            var idx  = GlobalInterOpLookupTable.Put(callback);
            var task = Native.dsn_file_create_aio_task(callbackCode, _c_aio_handler_holder, (IntPtr)idx, hash, callbackOwner?.tracker() ?? IntPtr.Zero);

            Native.dsn_file_write(hFile, buffer, count, offset, task);
            return(new SafeTaskHandle(task, idx));
        }
Esempio n. 13
0
        //
        // this gives you the task handle so you can wait or cancel
        // the task, with the cost of add/ref the task handle
        //
        public static SafeTaskHandle CallAsync2(
            TaskCode evt,
            Clientlet callbackOwner,
            task_handler callback,
            int hash = 0,
            int delay_milliseconds          = 0,
            int timer_interval_milliseconds = 0
            )
        {
            var idx = GlobalInterOpLookupTable.Put(callback);

            var task = timer_interval_milliseconds == 0 ? Native.dsn_task_create(evt, _c_task_handler_holder, (IntPtr)idx, hash, callbackOwner?.tracker() ?? IntPtr.Zero) : Native.dsn_task_create_timer(evt, _c_timer_task_handler_holder, (IntPtr)idx, hash, timer_interval_milliseconds, callbackOwner?.tracker() ?? IntPtr.Zero);

            var ret = new SafeTaskHandle(task, idx);

            Native.dsn_task_call(task, delay_milliseconds);
            return(ret);
        }
Esempio n. 14
0
        public static void RpcCallAsync(
            RpcAddress server,
            RpcWriteStream requestStream,
            Servicelet callbackOwner,
            RpcResponseHandler callback,
            int replyHash = 0
            )
        {
            Logging.dassert(requestStream.IsFlushed(),
                            "RpcWriteStream must be flushed after write in the same thread");

            var        idx  = GlobalInterOpLookupTable.Put(callback);
            dsn_task_t task = Native.dsn_rpc_create_response_task(
                requestStream.DangerousGetHandle(),
                _c_rpc_response_handler_holder,
                (IntPtr)idx,
                replyHash
                );

            Native.dsn_rpc_call(server, task, callbackOwner != null ? callbackOwner.tracker() : IntPtr.Zero);
        }