protected int EndSocketReceive(SocketWrapper socket, IAsyncResult result) { int bytesReceived = 0; if (this.finishScheduled) { this.FinishReceive(); } else { try { bytesReceived = socket.EndReceive(result); if (bytesReceived == 0) { this.FinishReceive(); } } catch (SocketException) { this.FinishReceive(); } catch (IOException) { this.FinishReceive(); } } return(bytesReceived); }
public ServerWorker(ProxySettings settings, string remoteHost, ClientWorker clientWorker, SocketWrapper clientSocket) : base(settings) { this.remoteHost = remoteHost; this.clientWorker = clientWorker; this.clientSocket = clientSocket; this.inspectorFactory = settings.InspectorFactory; }
protected void SocketReceive(SocketWrapper socket, byte[] buffer, AsyncCallback callback) { if (this.finishScheduled) { this.FinishReceive(); return; } try { socket.BeginReceive(buffer, 0, buffer.Length, callback); } catch (SocketException) { this.FinishReceive(); } catch (IOException) { this.FinishReceive(); } }
protected void StartSendDataTask(SocketWrapper targetSocket, BlockingCollection <byte[]> sourceDataQueue) { Task.Factory.StartNew(() => { try { foreach (var dataBlock in sourceDataQueue.GetConsumingEnumerable()) { targetSocket.Send(dataBlock); } } catch (SocketException) { } catch (IOException) { } this.sendFinished = true; this.ScheduleFinish(); }); }
private void OnConnectedToServer(Socket workerSocket) { this.workerSocket = new SocketWrapper(workerSocket, this.Settings); if (this.finishScheduled) { this.ScheduleFinish(); return; } if (this.clientSocket.IsSecure) { try { this.workerSocket.TransferToSecureServer(this.remoteHost); this.clientSocket.FinishTransferToSecureClient(this.remoteHost); } catch (AuthenticationException) { this.ScheduleFinish(); return; } catch (SocketException) { this.ScheduleFinish(); return; } catch (IOException) { this.ScheduleFinish(); return; } } this.StartSendToServerTask(); this.ServerReceive(); }
public ClientWorker(Socket workerSocket, ProxySettings settings) : base(settings) { this.workerSocket = new SocketWrapper(workerSocket, settings); }
protected int EndSocketReceive(SocketWrapper socket, IAsyncResult result) { int bytesReceived = 0; if (this.finishScheduled) { this.FinishReceive(); } else { try { bytesReceived = socket.EndReceive(result); if (bytesReceived == 0) { this.FinishReceive(); } } catch (SocketException) { this.FinishReceive(); } catch (IOException) { this.FinishReceive(); } } return bytesReceived; }
protected void StartSendDataTask(SocketWrapper targetSocket, BlockingCollection<byte[]> sourceDataQueue) { Task.Factory.StartNew(() => { try { foreach (var dataBlock in sourceDataQueue.GetConsumingEnumerable()) { targetSocket.Send(dataBlock); } } catch (SocketException) { } catch (IOException) { } this.sendFinished = true; this.ScheduleFinish(); }); }