comparison Net/TCPServer.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 3ab940a0c7a0
children 819fb56a56ea
comparison
equal deleted inserted replaced
104:327be9216006 105:4ba4fd48e1da
86 public void Listen(AddressFamily af, int Port) { 86 public void Listen(AddressFamily af, int Port) {
87 Stop(); 87 Stop();
88 88
89 _Listener = new Socket(af, SocketType.Stream, ProtocolType.Tcp); 89 _Listener = new Socket(af, SocketType.Stream, ProtocolType.Tcp);
90 90
91 _Listener.Blocking = false;
92 _Listener.Bind(new IPEndPoint(af == AddressFamily.InterNetworkV6 ? IPAddress.IPv6Any : IPAddress.Any, Port)); 91 _Listener.Bind(new IPEndPoint(af == AddressFamily.InterNetworkV6 ? IPAddress.IPv6Any : IPAddress.Any, Port));
93 _Listener.Listen(25); 92 _Listener.Listen(25);
94 _ThrottleCounter = _ThrottleBurst; 93 _ThrottleCounter = _ThrottleBurst;
95 _Listener.BeginAccept(AcceptCallback, null); 94 _Listener.BeginAccept(AcceptCallback, null);
96 95
182 base.Closed -= _Stream_Closed; 181 base.Closed -= _Stream_Closed;
183 } 182 }
184 183
185 internal Client(Socket Socket, TCPServer Server) : base(Socket) { 184 internal Client(Socket Socket, TCPServer Server) : base(Socket) {
186 _Server = Server; 185 _Server = Server;
187 Socket.Blocking = true;
188 base.Closed += _Stream_Closed; 186 base.Closed += _Stream_Closed;
189 this.Tag = Server; 187 this.Tag = Server;
190 } 188 }
191 189
192 internal void Start(UCIS.ThreadPool Pool) { 190 internal void Start(UCIS.ThreadPool Pool) {
195 193
196 private void WorkerProc(object state) { 194 private void WorkerProc(object state) {
197 bool CloseSocket = true; 195 bool CloseSocket = true;
198 try { 196 try {
199 try { 197 try {
200 base.Blocking = true;
201 //base.NoDelay = true; 198 //base.NoDelay = true;
202 base.ReadTimeout = 5000; 199 base.ReadTimeout = 5000;
203 base.WriteBufferSize = 1024 * 10;
204 base.ReadBufferSize = 1024 * 10;
205 //Console.WriteLine("TCPServer: Accepted connection from " + base.Socket.RemoteEndPoint.ToString()); 200 //Console.WriteLine("TCPServer: Accepted connection from " + base.Socket.RemoteEndPoint.ToString());
206 _MagicNumber = (byte)base.PeekByte(); 201 _MagicNumber = (byte)base.PeekByte();
207 } catch (TimeoutException ex) { 202 } catch (TimeoutException ex) {
208 Console.WriteLine("TCPServer: Caught TimeoutException while reading magic number: " + ex.Message); 203 Console.WriteLine("TCPServer: Caught TimeoutException while reading magic number: " + ex.Message);
209 return; 204 return;