protected void RegisterEndpoint(String addr, Ctx.Endpoint endpoint) { m_ctx.RegisterEndpoint(addr, endpoint); }
public void Bind([NotNull] string addr) { CheckContextTerminated(); // Process pending commands, if any. ProcessCommands(0, false); string protocol; string address; DecodeAddress(addr, out address, out protocol); CheckProtocol(protocol); if (protocol.Equals(Address.InProcProtocol)) { var endpoint = new Ctx.Endpoint(this, m_options); bool addressRegistered = RegisterEndpoint(addr, endpoint); if (!addressRegistered) { string xMsg = String.Format("Cannot bind address ( {0} ) - already in use.", addr); throw new AddressAlreadyInUseException(xMsg); } // Save last endpoint URI m_options.LastEndpoint = addr; return; } if ((protocol.Equals(Address.PgmProtocol) || protocol.Equals(Address.EpgmProtocol)) && ( m_options.SocketType == ZmqSocketType.Pub || m_options.SocketType == ZmqSocketType.Xpub)) { // For convenience's sake, bind can be used interchangeable with // connect for PGM and EPGM transports. Connect(addr); return; } // Remaining transports require to be run in an I/O thread, so at this // point we'll choose one. IOThread ioThread = ChooseIOThread(m_options.Affinity); if (ioThread == null) { throw NetMQException.Create(ErrorCode.EmptyThread); } if (protocol.Equals(Address.TcpProtocol)) { var listener = new TcpListener(ioThread, this, m_options); try { listener.SetAddress(address); m_port = listener.Port; // Recreate the address string (localhost:1234) in case the port was system-assigned var host = address.Substring(0, address.IndexOf(':')); addr = "tcp://" + host + ":" + m_port; } catch (NetMQException ex) { listener.Destroy(); EventBindFailed(addr, ex.ErrorCode); throw; } // Save last endpoint URI m_options.LastEndpoint = listener.Address; AddEndpoint(addr, listener); return; } if (protocol.Equals(Address.PgmProtocol) || protocol.Equals(Address.EpgmProtocol)) { var listener = new PgmListener(ioThread, this, m_options); try { listener.Init(address); } catch (NetMQException ex) { listener.Destroy(); EventBindFailed(addr, ex.ErrorCode); throw; } m_options.LastEndpoint = addr; AddEndpoint(addr, listener); return; } if (protocol.Equals(Address.IpcProtocol)) { var listener = new IpcListener(ioThread, this, m_options); try { listener.SetAddress(address); m_port = listener.Port; } catch (NetMQException ex) { listener.Destroy(); EventBindFailed(addr, ex.ErrorCode); throw; } // Save last endpoint URI m_options.LastEndpoint = listener.Address; AddEndpoint(addr, listener); return; } Debug.Assert(false); throw new FaultException(String.Format("SocketBase.Bind({0}) failure.", addr)); }
public void Connect([NotNull] string addr) { CheckContextTerminated(); // Process pending commands, if any. ProcessCommands(0, false); string address; string protocol; DecodeAddress(addr, out address, out protocol); CheckProtocol(protocol); if (protocol.Equals(Address.InProcProtocol)) { // 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); // 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 }; int[] highWaterMarks = { sndhwm, rcvhwm }; bool[] delays = { m_options.DelayOnDisconnect, m_options.DelayOnClose }; Pipe[] pipes = Pipe.PipePair(parents, highWaterMarks, 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) { var id = new Msg(); id.InitPool(peer.Options.IdentitySize); id.Put(peer.Options.Identity, 0, peer.Options.IdentitySize); id.SetFlags(MsgFlags.Identity); bool written = pipes[0].Write(ref id); Debug.Assert(written); pipes[0].Flush(); } // If required, send the identity of the local socket to the peer. if (m_options.RecvIdentity) { var id = new Msg(); id.InitPool(m_options.IdentitySize); id.Put(m_options.Identity, 0, m_options.IdentitySize); id.SetFlags(MsgFlags.Identity); bool written = pipes[1].Write(ref 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; // remember inproc connections for disconnect m_inprocs.Add(addr, pipes[0]); return; } // Choose the I/O thread to run the session in. IOThread ioThread = ChooseIOThread(m_options.Affinity); if (ioThread == null) { throw NetMQException.Create("Empty IO Thread", ErrorCode.EmptyThread); } var paddr = new Address(protocol, address); // Resolve address (if needed by the protocol) if (protocol.Equals(Address.TcpProtocol)) { paddr.Resolved = (new TcpAddress()); paddr.Resolved.Resolve( address, m_options.IPv4Only); } else if (protocol.Equals(Address.IpcProtocol)) { paddr.Resolved = (new IpcAddress()); paddr.Resolved.Resolve(address, true); } else if (protocol.Equals(Address.PgmProtocol) || protocol.Equals(Address.EpgmProtocol)) { if (m_options.SocketType == ZmqSocketType.Sub || m_options.SocketType == ZmqSocketType.Xsub) { Bind(addr); return; } paddr.Resolved = new PgmAddress(); paddr.Resolved.Resolve(address, m_options.IPv4Only); } // 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 = protocol.Equals(Address.PgmProtocol) || protocol.Equals(Address.EpgmProtocol); if (!m_options.DelayAttachOnConnect || icanhasall) { // Create a bi-directional pipe. ZObject[] parents = { this, session }; int[] hwms = { m_options.SendHighWatermark, m_options.ReceiveHighWatermark }; bool[] delays = { m_options.DelayOnDisconnect, m_options.DelayOnClose }; Pipe[] pipes = Pipe.PipePair(parents, 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); }
public bool Bind(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; string protocol; string address; DecodeAddress(addr, out address, out protocol); CheckProtocol(protocol); if (protocol.Equals("inproc")) { Ctx.Endpoint endpoint = new Ctx.Endpoint(this, m_options); bool rc = RegisterEndpoint(addr, endpoint); if (rc) { // Save last endpoint URI m_options.LastEndpoint = addr; } return rc; } if ((protocol.Equals("pgm") || protocol.Equals("epgm")) && ( m_options.SocketType == ZmqSocketType.Pub || m_options.SocketType == ZmqSocketType.Xpub)) { // For convenience's sake, bind can be used interchageable with // connect for PGM and EPGM transports. return Connect(addr); } // Remaining trasnports require to be run in an I/O thread, so at this // point we'll choose one. IOThread ioThread = ChooseIOThread(m_options.Affinity); if (ioThread == null) { ZError.ErrorNumber = (ErrorNumber.EMTHREAD); return false; } if (protocol.Equals("tcp")) { TcpListener listener = new TcpListener( ioThread, this, m_options); bool rc = listener.SetAddress(address); if (!rc) { listener.Destroy(); EventBindFailed(addr, ZError.ErrorNumber); //LOG.error("Failed to Bind", ZError.exc()); return false; } // Save last endpoint URI m_options.LastEndpoint = listener.Address; AddEndpoint(addr, listener); return true; } if (protocol.Equals("pgm") || protocol.Equals("epgm")) { PgmListener listener = new PgmListener(ioThread, this, m_options); bool rc = listener.Init(address); if (!rc) { listener.Destroy(); EventBindFailed(addr, ZError.ErrorNumber); return false; } m_options.LastEndpoint = addr; AddEndpoint(addr, listener); return true; } if (protocol.Equals("ipc")) { IpcListener listener = new IpcListener( ioThread, this, m_options); bool rc = listener.SetAddress(address); if (!rc) { listener.Destroy(); EventBindFailed(addr, ZError.ErrorNumber); return false; } // Save last endpoint URI m_options.LastEndpoint = listener.Address; AddEndpoint(addr, listener); return true; } Debug.Assert(false); return false; }
public void Bind(String addr) { if (m_ctxTerminated) { throw TerminatingException.Create(); } // Process pending commands, if any. ProcessCommands(0, false); string protocol; string address; DecodeAddress(addr, out address, out protocol); CheckProtocol(protocol); if (protocol.Equals(Address.InProcProtocol)) { Ctx.Endpoint endpoint = new Ctx.Endpoint(this, m_options); RegisterEndpoint(addr, endpoint); // Save last endpoint URI m_options.LastEndpoint = addr; return; } if ((protocol.Equals(Address.PgmProtocol) || protocol.Equals(Address.EpgmProtocol)) && ( m_options.SocketType == ZmqSocketType.Pub || m_options.SocketType == ZmqSocketType.Xpub)) { // For convenience's sake, bind can be used interchageable with // connect for PGM and EPGM transports. Connect(addr); return; } // Remaining trasnports require to be run in an I/O thread, so at this // point we'll choose one. IOThread ioThread = ChooseIOThread(m_options.Affinity); if (ioThread == null) { throw NetMQException.Create(ErrorCode.EMTHREAD); } if (protocol.Equals(Address.TcpProtocol)) { TcpListener listener = new TcpListener( ioThread, this, m_options); try { listener.SetAddress(address); m_port = listener.Port; } catch (NetMQException ex) { listener.Destroy(); EventBindFailed(addr, ex.ErrorCode); throw; } // Save last endpoint URI m_options.LastEndpoint = listener.Address; AddEndpoint(addr, listener); return; } if (protocol.Equals(Address.PgmProtocol) || protocol.Equals(Address.EpgmProtocol)) { PgmListener listener = new PgmListener(ioThread, this, m_options); try { listener.Init(address); } catch (NetMQException ex) { listener.Destroy(); EventBindFailed(addr, ex.ErrorCode); throw; } m_options.LastEndpoint = addr; AddEndpoint(addr, listener); return; } if (protocol.Equals(Address.IpcProtocol)) { IpcListener listener = new IpcListener( ioThread, this, m_options); try { listener.SetAddress(address); m_port = listener.Port; } catch (NetMQException ex) { listener.Destroy(); EventBindFailed(addr, ex.ErrorCode); throw; } // Save last endpoint URI m_options.LastEndpoint = listener.Address; AddEndpoint(addr, listener); return; } Debug.Assert(false); throw NetMQException.Create(ErrorCode.EFAULT); }
public void Bind(String addr) { if (m_ctxTerminated) { throw TerminatingException.Create(); } // Process pending commands, if any. ProcessCommands(0, false); string protocol; string address; DecodeAddress(addr, out address, out protocol); CheckProtocol(protocol); if (protocol.Equals("inproc")) { Ctx.Endpoint endpoint = new Ctx.Endpoint(this, m_options); RegisterEndpoint(addr, endpoint); // Save last endpoint URI m_options.LastEndpoint = addr; return; } if ((protocol.Equals("pgm") || protocol.Equals("epgm")) && ( m_options.SocketType == ZmqSocketType.Pub || m_options.SocketType == ZmqSocketType.Xpub)) { // For convenience's sake, bind can be used interchageable with // connect for PGM and EPGM transports. Connect(addr); return; } // Remaining trasnports require to be run in an I/O thread, so at this // point we'll choose one. IOThread ioThread = ChooseIOThread(m_options.Affinity); if (ioThread == null) { throw NetMQException.Create(ErrorCode.EMTHREAD); } if (protocol.Equals("tcp")) { TcpListener listener = new TcpListener( ioThread, this, m_options); try { listener.SetAddress(address); } catch (NetMQException ex) { listener.Destroy(); EventBindFailed(addr, ex.ErrorCode); throw; } // Save last endpoint URI m_options.LastEndpoint = listener.Address; AddEndpoint(addr, listener); return; } if (protocol.Equals("pgm") || protocol.Equals("epgm")) { PgmListener listener = new PgmListener(ioThread, this, m_options); try { listener.Init(address); } catch (NetMQException ex) { listener.Destroy(); EventBindFailed(addr, ex.ErrorCode); throw; } m_options.LastEndpoint = addr; AddEndpoint(addr, listener); return; } if (protocol.Equals("ipc")) { IpcListener listener = new IpcListener( ioThread, this, m_options); try { listener.SetAddress(address); } catch (NetMQException ex) { listener.Destroy(); EventBindFailed(addr, ex.ErrorCode); throw; } // Save last endpoint URI m_options.LastEndpoint = listener.Address; AddEndpoint(addr, listener); return; } Debug.Assert(false); throw NetMQException.Create(ErrorCode.EFAULT); }
public void Bind([NotNull] string addr) { CheckContextTerminated(); // Process pending commands, if any. ProcessCommands(0, false); string protocol; string address; DecodeAddress(addr, out address, out protocol); CheckProtocol(protocol); if (protocol.Equals(Address.InProcProtocol)) { var endpoint = new Ctx.Endpoint(this, m_options); bool addressRegistered = RegisterEndpoint(addr, endpoint); if (!addressRegistered) { string xMsg = string.Format("Cannot bind address ( {0} ) - already in use.", addr); throw new AddressAlreadyInUseException(xMsg); } // Save last endpoint URI m_options.LastEndpoint = addr; return; } if ((protocol.Equals(Address.PgmProtocol) || protocol.Equals(Address.EpgmProtocol)) && ( m_options.SocketType == ZmqSocketType.Pub || m_options.SocketType == ZmqSocketType.Xpub)) { // For convenience's sake, bind can be used interchangeable with // connect for PGM and EPGM transports. Connect(addr); return; } // Remaining transports require to be run in an I/O thread, so at this // point we'll choose one. IOThread ioThread = ChooseIOThread(m_options.Affinity); if (ioThread == null) { throw NetMQException.Create(ErrorCode.EmptyThread); } if (protocol.Equals(Address.TcpProtocol)) { var listener = new TcpListener(ioThread, this, m_options); try { listener.SetAddress(address); m_port = listener.Port; // Recreate the address string (localhost:1234) in case the port was system-assigned var host = address.Substring(0, address.IndexOf(':')); addr = "tcp://" + host + ":" + m_port; } catch (NetMQException ex) { listener.Destroy(); EventBindFailed(addr, ex.ErrorCode); throw; } // Save last endpoint URI m_options.LastEndpoint = listener.Address; AddEndpoint(addr, listener); return; } if (protocol.Equals(Address.PgmProtocol) || protocol.Equals(Address.EpgmProtocol)) { var listener = new PgmListener(ioThread, this, m_options); try { listener.Init(address); } catch (NetMQException ex) { listener.Destroy(); EventBindFailed(addr, ex.ErrorCode); throw; } m_options.LastEndpoint = addr; AddEndpoint(addr, listener); return; } if (protocol.Equals(Address.IpcProtocol)) { var listener = new IpcListener(ioThread, this, m_options); try { listener.SetAddress(address); m_port = listener.Port; } catch (NetMQException ex) { listener.Destroy(); EventBindFailed(addr, ex.ErrorCode); throw; } // Save last endpoint URI m_options.LastEndpoint = listener.Address; AddEndpoint(addr, listener); return; } Debug.Assert(false); throw new FaultException(string.Format("SocketBase.Bind({0}) failure.", addr)); }
protected bool RegisterEndpoint(String addr, Ctx.Endpoint endpoint) { return(m_ctx.RegisterEndpoint(addr, endpoint)); }
protected bool RegisterEndpoint([NotNull] String addr, [NotNull] Ctx.Endpoint endpoint) { return(m_ctx.RegisterEndpoint(addr, endpoint)); }
public void Bind(String addr) { CheckContextTerminated(); // Process pending commands, if any. ProcessCommands(0, false); string protocol; string address; DecodeAddress(addr, out address, out protocol); CheckProtocol(protocol); if (protocol.Equals(Address.InProcProtocol)) { Ctx.Endpoint endpoint = new Ctx.Endpoint(this, m_options); bool addressRegistered = RegisterEndpoint(addr, endpoint); if (!addressRegistered) { throw new AddressAlreadyInUseException("Cannot bind address, address already in use"); } // Save last endpoint URI m_options.LastEndpoint = addr; return; } if ((protocol.Equals(Address.PgmProtocol) || protocol.Equals(Address.EpgmProtocol)) && ( m_options.SocketType == ZmqSocketType.Pub || m_options.SocketType == ZmqSocketType.Xpub)) { // For convenience's sake, bind can be used interchageable with // connect for PGM and EPGM transports. Connect(addr); return; } // Remaining trasnports require to be run in an I/O thread, so at this // point we'll choose one. IOThread ioThread = ChooseIOThread(m_options.Affinity); if (ioThread == null) { throw NetMQException.Create(ErrorCode.EmptyThread); } if (protocol.Equals(Address.TcpProtocol)) { TcpListener listener = new TcpListener( ioThread, this, m_options); try { listener.SetAddress(address); m_port = listener.Port; } catch (NetMQException ex) { listener.Destroy(); EventBindFailed(addr, ex.ErrorCode); throw; } // Save last endpoint URI m_options.LastEndpoint = listener.Address; AddEndpoint(addr, listener); return; } if (protocol.Equals(Address.PgmProtocol) || protocol.Equals(Address.EpgmProtocol)) { PgmListener listener = new PgmListener(ioThread, this, m_options); try { listener.Init(address); } catch (NetMQException ex) { listener.Destroy(); EventBindFailed(addr, ex.ErrorCode); throw; } m_options.LastEndpoint = addr; AddEndpoint(addr, listener); return; } if (protocol.Equals(Address.IpcProtocol)) { IpcListener listener = new IpcListener( ioThread, this, m_options); try { listener.SetAddress(address); m_port = listener.Port; } catch (NetMQException ex) { listener.Destroy(); EventBindFailed(addr, ex.ErrorCode); throw; } // Save last endpoint URI m_options.LastEndpoint = listener.Address; AddEndpoint(addr, listener); return; } Debug.Assert(false); throw new FaultException(); }