Skip to content

Commit e87db76

Browse files
authored
Merge pull request #5 from aliyun/danieldev
use httpclient directly
2 parents 22cf0c7 + 837d8d5 commit e87db76

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

sdk/Aliyun/OTS/OTSClient.cs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
using Aliyun.OTS.Handler;
1919
using Aliyun.OTS.DataModel.ConditionalUpdate;
2020
using System;
21+
using System.Net;
22+
using System.Net.Http;
2123

2224
namespace Aliyun.OTS
2325
{
@@ -47,7 +49,8 @@ public class OTSClient
4749
{
4850
#region Fields & Properties
4951

50-
private OTSConnectionPool ConnectionPool;
52+
private HttpClient client;
53+
5154
private OTSHandler OTSHandler;
5255
private OTSClientConfig ClientConfig;
5356

@@ -78,11 +81,9 @@ public OTSClient(OTSClientConfig config)
7881
ClientConfig = config;
7982
OTSHandler = new OTSHandler();
8083

81-
ConnectionPool = new OTSConnectionPool(
82-
ClientConfig.EndPoint,
83-
ClientConfig.ConnectionLimit
84-
);
85-
84+
client = new HttpClient();
85+
client.BaseAddress = new Uri(ClientConfig.EndPoint);
86+
ServicePointManager.DefaultConnectionLimit = config.ConnectionLimit;
8687
OTSClientTestHelper.Reset();
8788
}
8889

@@ -674,13 +675,13 @@ private Task<TResponse> CallAsync<TRequest, TResponse>(string apiName, TRequest
674675
otsContext.APIName = apiName;
675676
otsContext.OTSRequest = request;
676677
otsContext.OTSReponse = new TResponse();
677-
otsContext.HttpClient = ConnectionPool.TakeHttpClient();
678+
otsContext.HttpClient = client;
678679

679680
OTSHandler.HandleBefore(otsContext);
680681

681682
return otsContext.HttpTask.ContinueWith((t) =>
682683
{
683-
ConnectionPool.ReturnHttpClient(otsContext.HttpClient);
684+
// ConnectionPool.ReturnHttpClient(otsContext.HttpClient);
684685
OTSHandler.HandleAfter(otsContext);
685686
return (TResponse)otsContext.OTSReponse;
686687
});

0 commit comments

Comments
 (0)