Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Android Cocos2dxDownloader OkHttpClient 超时设置 #2612

Open
justbilt opened this issue Jun 23, 2020 · 1 comment
Open

Android Cocos2dxDownloader OkHttpClient 超时设置 #2612

justbilt opened this issue Jun 23, 2020 · 1 comment

Comments

@justbilt
Copy link

https://github.com/cocos-creator/cocos2d-x-lite/blob/v2.4.1/cocos/platform/android/java/src/org/cocos2dx/lib/Cocos2dxDownloader.java#L98

new OkHttpClient().newBuilder()
                    .followRedirects(true)
                    .followSslRedirects(true)
                    .callTimeout(timeoutInSeconds, TimeUnit.SECONDS)
                    .build();

根据 OkHttp 的 callTimeout 文档 应该是整个请求的完成时间, 这与我们的设计是否有出入? 这里使用 callTimeout 是否合理?


经过测试, 如果这个时间设置的较小, 下载文件的时间大于这个时间时必然会下载失败:

java.net.SocketException: Socket closed

okhttp3.internal.http2.StreamResetException: stream was reset: CANCEL

经过测试, 将 callTimeout 换为 connectTimeout/writeTimeout/readTimeout 可以满足需求.

new OkHttpClient().newBuilder()
                    .followRedirects(true)
                    .followSslRedirects(true)
                    .connectTimeout(timeoutInSeconds, TimeUnit.SECONDS)
                    .writeTimeout(timeoutInSeconds, TimeUnit.SECONDS)
                    .readTimeout(timeoutInSeconds, TimeUnit.SECONDS)
                    .build();
@Visow
Copy link

Visow commented Nov 3, 2023

new jsb.Downloader({
            timeoutInSeconds: 45 * 60,
            countOfMaxProcessingTasks: 6,
            tempFileNameSuffix: ".tmp",
        });

可以按照需求自己加参数。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants