public TcpConnecter(IOThread ioThread, SessionBase session, Options options, Address addr, bool delayedStart) : base(ioThread, options) { m_ioObject = new IOObject(ioThread); m_addr = addr; m_handle = null; m_handleValid = false; m_delayedStart = delayedStart; m_timerStarted = false; m_session = session; m_currentReconnectIvl = m_options.ReconnectIvl; Debug.Assert(m_addr != null); m_endpoint = m_addr.ToString(); m_socket = session.Socket; }
public SessionBase(IOThread ioThread, bool connect, SocketBase socket, Options options, Address addr) : base(ioThread, options) { m_ioObject = new IOObject(ioThread); m_connect = connect; m_pipe = null; m_incompleteIn = false; m_pending = false; m_engine = null; m_socket = socket; m_ioThread = ioThread; m_hasLingerTimer = false; m_identitySent = false; m_identityReceived = false; m_addr = addr; m_terminatingPipes = new HashSet <Pipe> (); }
public RouterSession(IOThread ioThread, bool connect, SocketBase socket, Options options, Address addr) : base(ioThread, connect, socket, options, addr) { }
public bool Connect(String addr) { if (m_ctxTerminated) { ZError.ErrorNumber = (ErrorNumber.ETERM); return false; } // Process pending commands, if any. bool brc = ProcessCommands(0, false); if (!brc) return false; // Parse addr_ string. Uri uri; try { uri = new Uri(addr); } catch (Exception e) { throw new ArgumentException(addr, e); } String protocol = uri.Scheme; String address = uri.Authority; String path = uri.AbsolutePath; if (string.IsNullOrEmpty(address)) address = path; CheckProtocol(protocol); if (protocol.Equals("inproc")) { // TODO: inproc connect is specific with respect to creating pipes // as there's no 'reconnect' functionality implemented. Once that // is in place we should follow generic pipe creation algorithm. // Find the peer endpoint. Ctx.Endpoint peer = FindEndpoint(addr); if (peer.Socket == null) return false; // The total HWM for an inproc connection should be the sum of // the binder's HWM and the connector's HWM. int sndhwm; int rcvhwm; if (m_options.SendHighWatermark == 0 || peer.Options.ReceiveHighWatermark == 0) sndhwm = 0; else sndhwm = m_options.SendHighWatermark + peer.Options.ReceiveHighWatermark; if (m_options.ReceiveHighWatermark == 0 || peer.Options.SendHighWatermark == 0) rcvhwm = 0; else rcvhwm = m_options.ReceiveHighWatermark + peer.Options.SendHighWatermark; // Create a bi-directional pipe to connect the peers. ZObject[] parents = { this, peer.Socket }; Pipe[] pipes = { null, null }; int[] hwms = { sndhwm, rcvhwm }; bool[] delays = { m_options.DelayOnDisconnect, m_options.DelayOnClose }; Pipe.Pipepair(parents, pipes, hwms, delays); // Attach local end of the pipe to this socket object. AttachPipe(pipes[0]); // If required, send the identity of the peer to the local socket. if (peer.Options.RecvIdentity) { Msg id = new Msg(peer.Options.IdentitySize); id.Put(peer.Options.Identity, 0, peer.Options.IdentitySize); id.SetFlags(MsgFlags.Identity); bool written = pipes[0].Write(id); Debug.Assert(written); pipes[0].Flush(); } // If required, send the identity of the local socket to the peer. if (m_options.RecvIdentity) { Msg id = new Msg(m_options.IdentitySize); id.Put(m_options.Identity, 0, m_options.IdentitySize); id.SetFlags(MsgFlags.Identity); bool written = pipes[1].Write(id); Debug.Assert(written); pipes[1].Flush(); } // Attach remote end of the pipe to the peer socket. Note that peer's // seqnum was incremented in find_endpoint function. We don't need it // increased here. SendBind(peer.Socket, pipes[1], false); // Save last endpoint URI m_options.LastEndpoint = addr; return true; } // Choose the I/O thread to run the session in. IOThread ioThread = ChooseIOThread(m_options.Affinity); if (ioThread == null) { throw new ArgumentException("Empty IO Thread"); } Address paddr = new Address(protocol, address); // Resolve address (if needed by the protocol) if (protocol.Equals("tcp")) { paddr.Resolved = (new TcpAddress()); paddr.Resolved.Resolve( address, m_options.IPv4Only); } else if (protocol.Equals("Ipc")) { paddr.Resolved = (new IpcAddress()); paddr.Resolved.Resolve(address, true); } // Create session. SessionBase session = SessionBase.Create(ioThread, true, this, m_options, paddr); Debug.Assert(session != null); // PGM does not support subscription forwarding; ask for all data to be // sent to this pipe. bool icanhasall = false; if (protocol.Equals("pgm") || protocol.Equals("epgm")) icanhasall = true; if (!m_options.DelayAttachOnConnect || icanhasall) { // Create a bi-directional pipe. ZObject[] parents = { this, session }; Pipe[] pipes = { null, null }; int[] hwms = { m_options.SendHighWatermark, m_options.ReceiveHighWatermark }; bool[] delays = { m_options.DelayOnDisconnect, m_options.DelayOnClose }; Pipe.Pipepair(parents, pipes, hwms, delays); // Attach local end of the pipe to the socket object. AttachPipe(pipes[0], icanhasall); // Attach remote end of the pipe to the session object later on. session.AttachPipe(pipes[1]); } // Save last endpoint URI m_options.LastEndpoint = paddr.ToString(); AddEndpoint(addr, session); return true; }
public ReqSession(IOThread ioThread, bool connect, SocketBase socket, Options options, Address addr) : base(ioThread, connect, socket, options, addr) { m_state = State.Identity; }
public static SessionBase Create(IOThread ioThread, bool connect, SocketBase socket, Options options, Address addr) { SessionBase s; switch (options.SocketType) { case ZmqSocketType.Req: s = new Req.ReqSession (ioThread, connect, socket, options, addr); break; case ZmqSocketType.Dealer: s = new Dealer.DealerSession (ioThread, connect, socket, options, addr); break; case ZmqSocketType.Rep: s = new Rep.RepSession (ioThread, connect, socket, options, addr); break; case ZmqSocketType.Router: s = new Router.RouterSession (ioThread, connect, socket, options, addr); break; case ZmqSocketType.Pub: s = new Pub.PubSession (ioThread, connect, socket, options, addr); break; case ZmqSocketType.Xpub: s = new XPub.XPubSession(ioThread, connect, socket, options, addr); break; case ZmqSocketType.Sub: s = new Sub.SubSession (ioThread, connect, socket, options, addr); break; case ZmqSocketType.Xsub: s = new XSub.XSubSession (ioThread, connect, socket, options, addr); break; case ZmqSocketType.Push: s = new Push.PushSession (ioThread, connect, socket, options, addr); break; case ZmqSocketType.Pull: s = new Pull.PullSession (ioThread, connect, socket, options, addr); break; case ZmqSocketType.Pair: s = new Pair.PairSession (ioThread, connect, socket, options, addr); break; default: throw new ArgumentException("type=" + options.SocketType); } return s; }