comparison Net/TCPStream.cs @ 105:4ba4fd48e1da

Removed old TCP socket (non)blocking code
author Ivo Smits <Ivo@UCIS.nl>
date Sat, 11 Oct 2014 14:06:11 +0200
parents 4b78cc5f116b
children 819fb56a56ea
comparison
equal deleted inserted replaced
104:327be9216006 105:4ba4fd48e1da
17 private byte _PeekByte; 17 private byte _PeekByte;
18 private bool _HasPeekByte; 18 private bool _HasPeekByte;
19 private ulong _BytesWritten; 19 private ulong _BytesWritten;
20 private ulong _BytesRead; 20 private ulong _BytesRead;
21 private DateTime _StartTime; 21 private DateTime _StartTime;
22 private bool _Blocking;
23 22
24 public event EventHandler Closed; 23 public event EventHandler Closed;
25 24
26 public TCPStream(Socket Socket) { 25 public TCPStream(Socket Socket) {
27 _Socket = Socket; 26 _Socket = Socket;
28 _HasPeekByte = false; 27 _HasPeekByte = false;
29 _StartTime = DateTime.Now; 28 _StartTime = DateTime.Now;
30 _Blocking = _Socket.Blocking;
31 } 29 }
32 30
33 public Socket Socket { 31 public Socket Socket {
34 get { return _Socket; } 32 get { return _Socket; }
35 } 33 }
37 public DateTime CreationTime { 35 public DateTime CreationTime {
38 get { return _StartTime; } 36 get { return _StartTime; }
39 } 37 }
40 38
41 public bool Blocking { 39 public bool Blocking {
42 get { return _Blocking; } 40 get { return _Socket.Blocking; }
43 set { 41 set { Socket.Blocking = value; }
44 Socket.Blocking = value;
45 _Blocking = value;
46 }
47 } 42 }
48 43
49 public bool NoDelay { 44 public bool NoDelay {
50 get { return Socket.NoDelay; } 45 get { return Socket.NoDelay; }
51 set { Socket.NoDelay = value; } 46 set { Socket.NoDelay = value; }
89 try { 84 try {
90 if (size > 0) Count += Socket.Receive(buffer, offset, size, SocketFlags.None); 85 if (size > 0) Count += Socket.Receive(buffer, offset, size, SocketFlags.None);
91 } catch (SocketException ex) { 86 } catch (SocketException ex) {
92 switch (ex.SocketErrorCode) { 87 switch (ex.SocketErrorCode) {
93 case SocketError.WouldBlock: 88 case SocketError.WouldBlock:
94 _Socket.Blocking = _Blocking;
95 throw new TimeoutException("The receive operation would block", ex); 89 throw new TimeoutException("The receive operation would block", ex);
96 case SocketError.TimedOut: 90 case SocketError.TimedOut:
97 throw new TimeoutException("The receive operation timed out", ex); 91 throw new TimeoutException("The receive operation timed out", ex);
98 case SocketError.ConnectionReset: 92 case SocketError.ConnectionReset:
99 case SocketError.Disconnecting: 93 case SocketError.Disconnecting:
210 offset += sent; 204 offset += sent;
211 } 205 }
212 } catch (SocketException ex) { 206 } catch (SocketException ex) {
213 switch (ex.SocketErrorCode) { 207 switch (ex.SocketErrorCode) {
214 case SocketError.WouldBlock: 208 case SocketError.WouldBlock:
215 _Socket.Blocking = _Blocking;
216 throw new TimeoutException("The send operation would block", ex); 209 throw new TimeoutException("The send operation would block", ex);
217 case SocketError.TimedOut: 210 case SocketError.TimedOut:
218 throw new TimeoutException("The send operation timed out", ex); 211 throw new TimeoutException("The send operation timed out", ex);
219 case SocketError.ConnectionReset: 212 case SocketError.ConnectionReset:
220 case SocketError.Disconnecting: 213 case SocketError.Disconnecting: