internal DefaultKayakSocket(Socket socket, IScheduler scheduler) { this.id = nextId++; this.socket = new SocketWrapper(socket); this.scheduler = scheduler; state = new KayakSocketState(false); }
public void Connect(IPEndPoint ep) { Debug.WriteLine("KayakSocket: connect called with " + ep); state.SetConnecting(); Debug.WriteLine("KayakSocket: connecting to " + ep); this.socket = new SocketWrapper(ep.Address.AddressFamily); socket.BeginConnect(ep, iasr => { Exception error = null; try { socket.EndConnect(iasr); } catch (Exception e) { error = e; } scheduler.Post(() => { if (error is ObjectDisposedException) return; if (error != null) { state.SetError(); Debug.WriteLine("KayakSocket: error while connecting to " + ep); RaiseError(error); } else { state.SetConnected(); Debug.WriteLine("KayakSocket: connected to " + ep); del.OnConnected(this); DoRead(); } }); }); }