コード例 #1
0
ファイル: socket.cs プロジェクト: svermeulen/iris
        private IAsyncResult BeginDownLevelSendFile(
            string fileName,
            bool flowContext,
            AsyncCallback callback,
            object state)
        {
            if(Logging.On)Logging.Enter(Logging.Sockets, this, "BeginSendFile", "");

            if (CleanedUp) {
                throw new ObjectDisposedException(this.GetType().FullName);
            }

            if (!Connected) {
                throw new NotSupportedException(SR.GetString(SR.net_notconnected));
            }

            GlobalLog.Print("Socket#" + ValidationHelper.HashString(this) + "::BeginDownLevelSendFile() SRC:" + ValidationHelper.ToString(LocalEndPoint) + " DST:" + ValidationHelper.ToString(RemoteEndPoint) + " fileName:" + fileName);

            FileStream fileStream = null;
            if (fileName != null && fileName.Length>0) {
                fileStream = new FileStream(fileName,FileMode.Open,FileAccess.Read,FileShare.Read);
            }

            DownLevelSendFileAsyncResult asyncResult = null;
            IAsyncResult fileResult = null;
            try
            {
                asyncResult = new DownLevelSendFileAsyncResult(fileStream, this, state, callback);

                // If we're flowing context, indicate that here.
                if (flowContext)
                {
                    asyncResult.StartPostingAsyncOp(false);
                }

                fileResult = fileStream.BeginRead(asyncResult.buffer, 0, asyncResult.buffer.Length, new AsyncCallback(DownLevelSendFileCallback), asyncResult);
            }
            catch(Exception e)
            {
                if (!NclUtilities.IsFatal(e))
                {
                    DownLevelSendFileCleanup(fileStream);
                }
                throw;
            }

            if (fileResult.CompletedSynchronously)
            {
                DoDownLevelSendFileCallback(fileResult, asyncResult);
            }

            // Finished without throwing - seal up the result and give it out.  NOP if we're not flowing.
            asyncResult.FinishPostingAsyncOp(ref Caches.SendClosureCache);
            if(Logging.On)Logging.Exit(Logging.Sockets, this, "BeginSendFile",0);

            return asyncResult;
        }
コード例 #2
0
 private IAsyncResult BeginDownLevelSendFile(string fileName, bool flowContext, AsyncCallback callback, object state)
 {
     if (s_LoggingEnabled)
     {
         Logging.Enter(Logging.Sockets, this, "BeginSendFile", "");
     }
     if (this.CleanedUp)
     {
         throw new ObjectDisposedException(base.GetType().FullName);
     }
     if (!this.Connected)
     {
         throw new NotSupportedException(SR.GetString("net_notconnected"));
     }
     FileStream stream = null;
     if ((fileName != null) && (fileName.Length > 0))
     {
         stream = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read);
     }
     DownLevelSendFileAsyncResult result = null;
     IAsyncResult result2 = null;
     try
     {
         result = new DownLevelSendFileAsyncResult(stream, this, state, callback);
         if (flowContext)
         {
             result.StartPostingAsyncOp(false);
         }
         result2 = stream.BeginRead(result.buffer, 0, result.buffer.Length, new AsyncCallback(Socket.DownLevelSendFileCallback), result);
     }
     catch (Exception exception)
     {
         if (!NclUtilities.IsFatal(exception))
         {
             DownLevelSendFileCleanup(stream);
         }
         throw;
     }
     if (result2.CompletedSynchronously)
     {
         DoDownLevelSendFileCallback(result2, result);
     }
     result.FinishPostingAsyncOp(ref this.Caches.SendClosureCache);
     if (s_LoggingEnabled)
     {
         Logging.Exit(Logging.Sockets, this, "BeginSendFile", 0);
     }
     return result;
 }