本文介绍了Socket.SendFile 发送大文件错误 87的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用发送文件的标准方法.

I use the standard method of sending a file.

internal bool SendToServer(string filename)
    {

        if (null == _netSocket || !_netSocket.Connected) CreateSocketConnect();

        try
        {

            _netSocket.SendFile(filename);

            File.Delete(filename);

            return true;
        }
        catch (SocketException ex)
        {
            CloseSocketConnect();
            string error = string.Format("exception: {0} error code: {1} stacktrace: {2}", ex.Message, ex.ErrorCode, ex.StackTrace);
            _twriter.AddMessage(string.Format("-> {0}", error));
            Logger.Instance.WriteLine(ex.Message);
        }

        return false;
    }

但是有一个问题.如果文件很大,超过 1.5 GB,则会出现错误WSA_INVALID_PARAMETER - 87

But there is one problem. If the file is large, more than 1.5 GB, then I get an errorWSA_INVALID_PARAMETER - 87

我该如何解决这个问题,我什至可以这样做还是寻找其他发送文件的选项?

How can I fix this and can I even do it or look for another option for sending the file?

推荐答案

根据 Windows Socket 错误代码,

WSA_INVALID_PARAMETER87一个或多个参数无效.一个应用程序使用了一个 Windows Sockets 函数,该函数>直接映射到一个 Windows 函数.Windows > 函数指示一个或多个 > 参数有问题.请注意,此错误是由 >操作系统返回的,因此在 >Windows 的未来版本中,错误编号可能会发生变化.

我们只能猜测可能的无效参数.我们应该是你使用完整的文件路径.还要确保正确接收文件.要找到错误的根本原因,您必须捕获一个 网络跟踪.首先通过添加config entry 并重现该问题,您应该获得详细的跟踪文件.我们可以阅读它以了解根本原因

We can only guess the possible invalid parameter. We should be you using Full file path. Also make sure to receive the file correctly. To get to the root cause of the error,You have to capture a network trace .First enable the tracing by adding a config entry and reproduce the issue,you should get a detailed trace file.We can read it to understand root cause

网络trace中没有太多细节,所以我查看了Socket.SendFile 实现.看起来这个电话只是要WinSock TransmitFile 和这个 TransmitFile 抛出了无效参数错误.所以这是一个 winsock 错误,这里是 winsock PInvoke 发生

There is not much details in the network trace,so I looked at the source code of Socket.SendFile implementation . It looks like the call is simply going toWinSock TransmitFile and this TransmitFile is throwing the invalid parameter error .So this is a winsock error ,here's the winsock PInvoke happening

// This can throw ObjectDisposedException.
                if (fileHandle != null ?
                    !UnsafeNclNativeMethods.OSSOCK.TransmitFile_Blocking(m_Handle.DangerousGetHandle(), fileHandle, 0, 0, SafeNativeOverlapped.Zero, asyncResult.TransmitFileBuffers, flags) :
                    !UnsafeNclNativeMethods.OSSOCK.TransmitFile_Blocking2(m_Handle.DangerousGetHandle(), IntPtr.Zero, 0, 0, SafeNativeOverlapped.Zero, asyncResult.TransmitFileBuffers, flags))
                {
                    errorCode = (SocketError) Marshal.GetLastWin32Error();
                }

这篇关于Socket.SendFile 发送大文件错误 87的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 10:24