Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Update scope of using.
  • Loading branch information
huoyaoyuan committed Aug 3, 2021
commit 83d2fecc32525c3b55679a4fa17e35df42f4f1ec
Original file line number Diff line number Diff line change
Expand Up @@ -191,21 +191,19 @@ private void SendFileInternal(string? fileName, ReadOnlySpan<byte> preBuffer, Re
{
CheckTransmitFileOptions(flags);

// Open the file, if any
// Open it before we send the preBuffer so that any exception happens first
SafeFileHandle? fileHandle = OpenFileHandle(fileName);

SocketError errorCode = SocketError.Success;

// Send the preBuffer, if any
// This will throw on error
if (!preBuffer.IsEmpty)
// Open the file, if any
// Open it before we send the preBuffer so that any exception happens first
using (SafeFileHandle? fileHandle = OpenFileHandle(fileName))
{
Send(preBuffer);
}
// Send the preBuffer, if any
// This will throw on error
if (!preBuffer.IsEmpty)
{
Send(preBuffer);
}

using (fileHandle)
{
// Send the file, if any
if (fileHandle != null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -397,11 +397,10 @@ private Socket GetOrCreateAcceptSocket(Socket? acceptSocket, bool checkDisconnec

private void SendFileInternal(string? fileName, ReadOnlySpan<byte> preBuffer, ReadOnlySpan<byte> postBuffer, TransmitFileOptions flags)
{
// Open the file, if any
SafeFileHandle? fileHandle = OpenFileHandle(fileName);
SocketError errorCode;

using (fileHandle)
// Open the file, if any
using (SafeFileHandle? fileHandle = OpenFileHandle(fileName))
{
// This can throw ObjectDisposedException.
errorCode = SocketPal.SendFile(_handle, fileHandle, preBuffer, postBuffer, flags);
Expand Down