Skip to content

Commit 99c37fd

Browse files
committed
Renamed the nested Socket class as TcpSocket
[skip ci[
1 parent dfed569 commit 99c37fd

File tree

2 files changed

+30
-34
lines changed

2 files changed

+30
-34
lines changed

HttpWebClient/HttpWebClientSocket.cs

Lines changed: 20 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
//The MIT License(MIT)
1+
// The MIT License(MIT)
22
//
3-
//Copyright(c) 2015-2017 Ripcord Software Ltd
3+
// Copyright(c) 2015-2017 Ripcord Software Ltd
44
//
55
// Permission is hereby granted, free of charge, to any person obtaining a copy
66
// of this software and associated documentation files (the "Software"), to deal
@@ -21,6 +21,7 @@
2121
// SOFTWARE.
2222

2323
using System;
24+
using System.Net.Sockets;
2425

2526
namespace RipcordSoftware.HttpWebClient
2627
{
@@ -32,25 +33,24 @@ public interface IHttpWebClientSocket : IDisposable
3233

3334
void KeepAliveOnClose(int? timeout = null);
3435

35-
int Receive(byte[] buffer, int offset, int count, bool peek = false, System.Net.Sockets.SocketFlags flags = System.Net.Sockets.SocketFlags.None);
36+
int Receive(byte[] buffer, int offset, int count, bool peek = false, SocketFlags flags = SocketFlags.None);
3637

37-
int Send(byte[] buffer, int offset, int count, System.Net.Sockets.SocketFlags flags = System.Net.Sockets.SocketFlags.None);
38+
int Send(byte[] buffer, int offset, int count, SocketFlags flags = SocketFlags.None);
3839

3940
bool Connected { get; }
4041
int Available { get; }
4142
int Timeout { get; set; }
4243
bool NoDelay { get; set; }
4344
bool ForceClose { set; }
44-
IntPtr Handle { get; }
4545
}
4646

4747
public class HttpWebClientSocket : IHttpWebClientSocket
4848
{
4949
#region Types
50-
protected internal class Socket : IDisposable
50+
protected internal class TcpSocket : IDisposable
5151
{
5252
#region Private fields
53-
private System.Net.Sockets.Socket _socket;
53+
private Socket _socket;
5454

5555
private int _timeout;
5656

@@ -60,7 +60,7 @@ protected internal class Socket : IDisposable
6060
#endregion
6161

6262
#region Constructor
63-
public Socket(string hostname, int port, int timeout = 30000)
63+
public TcpSocket(string hostname, int port, int timeout = 30000)
6464
{
6565
Hostname = hostname;
6666
Port = port;
@@ -84,13 +84,13 @@ public void Flush()
8484
}
8585
}
8686

87-
public int Receive(byte[] buffer, int offset, int count, bool peek = false, System.Net.Sockets.SocketFlags flags = System.Net.Sockets.SocketFlags.None)
87+
public int Receive(byte[] buffer, int offset, int count, bool peek = false, SocketFlags flags = SocketFlags.None)
8888
{
89-
flags |= peek ? System.Net.Sockets.SocketFlags.Peek : System.Net.Sockets.SocketFlags.None;
89+
flags |= peek ? SocketFlags.Peek : SocketFlags.None;
9090
return _socket.Receive(buffer, offset, count, flags);
9191
}
9292

93-
public int Send(byte[] buffer, int offset, int count, System.Net.Sockets.SocketFlags flags = System.Net.Sockets.SocketFlags.None)
93+
public int Send(byte[] buffer, int offset, int count, SocketFlags flags = SocketFlags.None)
9494
{
9595
return _socket.Send(buffer, offset, count, flags);
9696
}
@@ -132,19 +132,17 @@ public void ResetKeepAlive()
132132
public bool IsKeepAliveExpired { get { return _keepAliveTimeout.HasValue ? (_keepAliveStarted + _keepAliveTimeout) < Now : false; } }
133133

134134
public bool NoDelay { get { return _socket.NoDelay; } set { _socket.NoDelay = value; } }
135-
136-
public IntPtr Handle { get { return _socket.Handle; } }
137135
#endregion
138136

139137
#region Private properties
140138
private static long Now { get { return DateTime.UtcNow.Ticks / TimeSpan.TicksPerMillisecond; } }
141139
#endregion
142140

143141
#region Private methods
144-
private static System.Net.Sockets.Socket NewSocket(string hostname, int port)
142+
private static Socket NewSocket(string hostname, int port)
145143
{
146-
var socket = new System.Net.Sockets.Socket(System.Net.Sockets.AddressFamily.InterNetwork, System.Net.Sockets.SocketType.Stream, System.Net.Sockets.ProtocolType.Tcp);
147-
socket.SetSocketOption(System.Net.Sockets.SocketOptionLevel.Socket, System.Net.Sockets.SocketOptionName.KeepAlive, true);
144+
var socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
145+
socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.KeepAlive, true);
148146
return socket;
149147
}
150148
#endregion
@@ -159,19 +157,19 @@ public void Dispose()
159157
#endregion
160158

161159
#region Private fields
162-
private Socket _socket;
160+
private TcpSocket _socket;
163161
private bool _forceClose = false;
164162
#endregion
165163

166164
#region Contructor
167165
protected HttpWebClientSocket(string hostname, int port, int timeout = 30000)
168166
{
169-
_socket = new Socket(hostname, port, timeout);
167+
_socket = new TcpSocket(hostname, port, timeout);
170168
}
171169

172-
protected internal HttpWebClientSocket(HttpWebClientSocket.Socket socket)
170+
protected internal HttpWebClientSocket(HttpWebClientSocket.TcpSocket socket)
173171
{
174-
this._socket = socket;
172+
_socket = socket;
175173
}
176174
#endregion
177175

@@ -201,12 +199,12 @@ public void Flush()
201199
_socket.Flush();
202200
}
203201

204-
public int Receive(byte[] buffer, int offset, int count, bool peek = false, System.Net.Sockets.SocketFlags flags = System.Net.Sockets.SocketFlags.None)
202+
public int Receive(byte[] buffer, int offset, int count, bool peek = false, SocketFlags flags = SocketFlags.None)
205203
{
206204
return _socket.Receive(buffer, offset, count, peek, flags);
207205
}
208206

209-
public int Send(byte[] buffer, int offset, int count, System.Net.Sockets.SocketFlags flags = System.Net.Sockets.SocketFlags.None)
207+
public int Send(byte[] buffer, int offset, int count, SocketFlags flags = SocketFlags.None)
210208
{
211209
return _socket.Send(buffer, offset, count, flags);
212210
}
@@ -250,8 +248,6 @@ public void KeepAliveOnClose(int? timeout = null)
250248
public bool NoDelay { get { return _socket.NoDelay; } set { _socket.NoDelay = value; } }
251249

252250
public bool ForceClose { set { _forceClose = value; } }
253-
254-
public IntPtr Handle { get { return _socket.Handle; } }
255251
#endregion
256252

257253
#region IDisposable implementation

HttpWebClient/HttpWebClientSocketCache.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
//The MIT License(MIT)
1+
// The MIT License(MIT)
22
//
3-
//Copyright(c) 2015-2017 Ripcord Software Ltd
3+
// Copyright(c) 2015-2017 Ripcord Software Ltd
44
//
55
// Permission is hereby granted, free of charge, to any person obtaining a copy
66
// of this software and associated documentation files (the "Software"), to deal
@@ -28,19 +28,19 @@ namespace RipcordSoftware.HttpWebClient
2828
internal static class HttpWebClientSocketCache
2929
{
3030
#region Private fields
31-
private static ConcurrentDictionary<string, ConcurrentQueue<HttpWebClientSocket.Socket>> _socketCache = new ConcurrentDictionary<string, ConcurrentQueue<HttpWebClientSocket.Socket>>();
31+
private static ConcurrentDictionary<string, ConcurrentQueue<HttpWebClientSocket.TcpSocket>> _socketCache = new ConcurrentDictionary<string, ConcurrentQueue<HttpWebClientSocket.TcpSocket>>();
3232
#endregion
3333

3434
#region Public methods
35-
public static HttpWebClientSocket.Socket GetSocket(string hostname, int port, int timeout)
35+
public static HttpWebClientSocket.TcpSocket GetSocket(string hostname, int port, int timeout)
3636
{
37-
HttpWebClientSocket.Socket socket = null;
37+
HttpWebClientSocket.TcpSocket socket = null;
3838
var key = MakeKey(hostname, port);
3939

40-
ConcurrentQueue<HttpWebClientSocket.Socket> socketQueue;
40+
ConcurrentQueue<HttpWebClientSocket.TcpSocket> socketQueue;
4141
if (_socketCache.TryGetValue(key, out socketQueue))
4242
{
43-
HttpWebClientSocket.Socket temp = null;
43+
HttpWebClientSocket.TcpSocket temp = null;
4444
while (socketQueue.Count > 0 && socketQueue.TryDequeue(out temp))
4545
{
4646
if (!temp.IsKeepAliveExpired && temp.Connected)
@@ -57,18 +57,18 @@ public static HttpWebClientSocket.Socket GetSocket(string hostname, int port, in
5757
return socket;
5858
}
5959

60-
public static void ReleaseSocket(HttpWebClientSocket.Socket socket)
60+
public static void ReleaseSocket(HttpWebClientSocket.TcpSocket socket)
6161
{
6262
bool released = false;
6363

6464
if (socket.Connected)
6565
{
6666
var key = MakeKey(socket.Hostname, socket.Port);
6767

68-
ConcurrentQueue<HttpWebClientSocket.Socket> socketQueue;
68+
ConcurrentQueue<HttpWebClientSocket.TcpSocket> socketQueue;
6969
if (!_socketCache.TryGetValue(key, out socketQueue))
7070
{
71-
socketQueue = new ConcurrentQueue<HttpWebClientSocket.Socket>();
71+
socketQueue = new ConcurrentQueue<HttpWebClientSocket.TcpSocket>();
7272
if (!_socketCache.TryAdd(key, socketQueue))
7373
{
7474
socketQueue = null;

0 commit comments

Comments
 (0)