Example #1
0
        public static int onReceiveFileNameReturn(IntPtr handle, FSP_ServiceCode code, int result)
        {
            if (code != FSP_ServiceCode.FSP_NotifyDataReady || result < 0)
            {
                FSPAPI.Dispose(handle);
                finished = true;
                return(-1);
            }

            if (result == 0)
            {
                Console.WriteLine("No filename returned. onReceiveFileNameReturn called more than once?");
                return(0);
            }

            // The byte length, result, included the terminating zero which should be excluded
            // TODO: should add some configurable work directory
            String filePath = DEFAULT_RECV_DIR + Encoding.UTF8.GetString(fileName, 0, result - 1);

            Console.WriteLine("{0}", filePath);
            try
            {
                // TODO: exploit to GetDiskFreeSpace to take use of SECTOR size
                // _aligned_malloc
                // the client should take use of 'FILE_FLAG_NO_BUFFERING | FILE_FLAG_WRITE_THROUGH' for ultimate integrity
                hFile = File.Create(filePath, 4096, FileOptions.Asynchronous | FileOptions.SequentialScan | FileOptions.WriteThrough);
                //    , GENERIC_WRITE
                //    , 0	// shared none
                //    , NULL
                //    , CREATE_NEW
                //    , FILE_FLAG_POSIX_SEMANTICS | FILE_FLAG_WRITE_THROUGH
                //    , NULL);
                //// | FILE_FLAG_NO_BUFFERING [require data block alignment which condition is too strict]
                //
                Console.WriteLine("To read content with inline buffering...");
                FSPAPI.RecvInline(handle, new CallbackPeeked(onReceiveNextBlock));
            }
            catch (Exception e)
            {
                Console.WriteLine("Unfortunately exception occured:");
                Console.WriteLine(e.Message);
                finished = true;
                FSPAPI.Dispose(handle); // may raise second-chance exceptions?
            }

            return(0);
        }
Example #2
0
        // This time it is really shutdown
        public static int onAcknowledgeSent(IntPtr h, FSP_ServiceCode c, int r)
        {
            Console.WriteLine("Result of sending the acknowledgement: {0}", r);
            if (r < 0)
            {
                finished = true;
                FSPAPI.Dispose(h);
                return(0);
            }

            if (FSPAPI.Shutdown(h, new NotifyOrReturn(onShutdown)) < 0)
            {
                Console.WriteLine("Cannot shutdown gracefully in the final stage.");
                FSPAPI.Dispose(h);
                finished = true;
                return(-1);
            }

            return(0);
        }
Example #3
0
        public static int onPublicKeySent(IntPtr handle, FSP_ServiceCode code, int result)
        {
            Console.WriteLine("onPublicKeySent: Handle = {0:X}, code = {1}, result = {2}", handle, code, result);
            if (result < 0)
            {
                FSPAPI.Dispose(handle);
                finished = true;
                return(-1);
            }

            Console.Write("To read the filename directly...\t");
            if (FSPAPI.ReadFrom(handle, fileName, fileName.Length, new NotifyOrReturn(onReceiveFileNameReturn)) < 0)
            {
                FSPAPI.Dispose(handle);
                finished = true;
                return(-1);
            }

            return(0);
        }
Example #4
0
 public static int onNotified(IntPtr handle, FSP_ServiceCode code, int result)
 {
     Console.WriteLine("Handle = {0:X}, code = {1}, result = {2}", handle, code, result);
     return(0);
 }
Example #5
0
 public static int onShutdown(IntPtr handle, FSP_ServiceCode code, int result)
 {
     Console.WriteLine("onShutdown: Handle = {0:X}, code = {1}, result = {2}", handle, code, result);
     FSPAPI.Dispose(handle);
     return(0);
 }