Example #1
0
        public StreamSocket(ProtocolInstance instance, NetworkProxy proxy, EndPoint addr, EndPoint sourceAddr)
        {
            _instance   = instance;
            _proxy      = proxy;
            _addr       = addr;
            _sourceAddr = sourceAddr;
            _fd         = Network.createSocket(false, (_proxy != null ? _proxy.getAddress() : _addr).AddressFamily);
            _state      = StateNeedConnect;

            Network.setBlock(_fd, false);
            Network.setTcpBufSize(_fd, _instance);

            _readEventArgs            = new SocketAsyncEventArgs();
            _readEventArgs.Completed += new EventHandler <SocketAsyncEventArgs>(ioCompleted);

            _writeEventArgs            = new SocketAsyncEventArgs();
            _writeEventArgs.Completed += new EventHandler <SocketAsyncEventArgs>(ioCompleted);

            //
            // For timeouts to work properly, we need to receive/send
            // the data in several chunks. Otherwise, we would only be
            // notified when all the data is received/written. The
            // connection timeout could easily be triggered when
            // receiging/sending large messages.
            //
            _maxSendPacketSize = Math.Max(512, Network.getSendBufferSize(_fd));
            _maxRecvPacketSize = Math.Max(512, Network.getRecvBufferSize(_fd));
        }
Example #2
0
        public StreamSocket(ProtocolInstance instance, NetworkProxy proxy, EndPoint addr, EndPoint sourceAddr)
        {
            _instance   = instance;
            _proxy      = proxy;
            _addr       = addr;
            _sourceAddr = sourceAddr;
            _fd         = Network.createSocket(false, (_proxy != null ? _proxy.getAddress() : _addr).AddressFamily);
            _state      = StateNeedConnect;

            init();
        }
Example #3
0
        //
        // Only for use by UdpConnector.
        //
        internal UdpTransceiver(ProtocolInstance instance, EndPoint addr, EndPoint sourceAddr, string mcastInterface,
                                int mcastTtl)
        {
            _instance   = instance;
            _addr       = addr;
            _sourceAddr = sourceAddr;

            _readEventArgs = new SocketAsyncEventArgs();
            _readEventArgs.RemoteEndPoint = _addr;
            _readEventArgs.Completed     += new EventHandler <SocketAsyncEventArgs>(ioCompleted);

            _writeEventArgs = new SocketAsyncEventArgs();
            _writeEventArgs.RemoteEndPoint = _addr;
            _writeEventArgs.Completed     += new EventHandler <SocketAsyncEventArgs>(ioCompleted);

            _mcastInterface = mcastInterface;
            _mcastTtl       = mcastTtl;
            _state          = StateNeedConnect;
            _incoming       = false;

            try
            {
                _fd = Network.createSocket(true, _addr.AddressFamily);
                setBufSize(-1, -1);
                Network.setBlock(_fd, false);
                if (Network.isMulticast((IPEndPoint)_addr))
                {
                    if (_mcastInterface.Length > 0)
                    {
                        Network.setMcastInterface(_fd, _mcastInterface, _addr.AddressFamily);
                    }
                    if (AssemblyUtil.osx_)
                    {
                        //
                        // On Windows, we delay the join for the mcast group after the connection
                        // establishment succeeds. This is necessary for older Windows versions
                        // where joining the group fails if the socket isn't bound. See ICE-5113.
                        //
                        Network.setMcastGroup(_fd, ((IPEndPoint)_addr).Address, _mcastInterface);
                        if (_mcastTtl != -1)
                        {
                            Network.setMcastTtl(_fd, _mcastTtl, _addr.AddressFamily);
                        }
                    }
                }
            }
            catch (Ice.LocalException)
            {
                _fd = null;
                throw;
            }
        }
Example #4
0
        //
        // Only for use by UdpConnector.
        //
        internal UdpTransceiver(ProtocolInstance instance, EndPoint addr, EndPoint sourceAddr, string mcastInterface,
                                int mcastTtl)
        {
            _instance   = instance;
            _addr       = addr;
            _sourceAddr = sourceAddr;

            _readEventArgs = new SocketAsyncEventArgs();
            _readEventArgs.RemoteEndPoint = _addr;
            _readEventArgs.Completed     += new EventHandler <SocketAsyncEventArgs>(ioCompleted);

            _writeEventArgs = new SocketAsyncEventArgs();
            _writeEventArgs.RemoteEndPoint = _addr;
            _writeEventArgs.Completed     += new EventHandler <SocketAsyncEventArgs>(ioCompleted);

            _mcastInterface = mcastInterface;
            _state          = StateNeedConnect;
            _incoming       = false;

            try
            {
                _fd = Network.createSocket(true, _addr.AddressFamily);
                setBufSize(-1, -1);
                Network.setBlock(_fd, false);
                if (Network.isMulticast((IPEndPoint)_addr))
                {
                    if (_mcastInterface.Length > 0)
                    {
                        Network.setMcastInterface(_fd, _mcastInterface, _addr.AddressFamily);
                    }
                    if (mcastTtl != -1)
                    {
                        Network.setMcastTtl(_fd, mcastTtl, _addr.AddressFamily);
                    }
                }
            }
            catch (Ice.LocalException)
            {
                _fd = null;
                throw;
            }
        }
Example #5
0
        public Transceiver connect()
        {
            if (_traceLevels.network >= 2)
            {
                string s = "trying to establish tcp connection to " + ToString();
                _logger.trace(_traceLevels.networkCat, s);
            }

            try
            {
#if SILVERLIGHT
                Socket fd = Network.createSocket(false, _addr.AddressFamily == AddressFamily.InterNetworkV6 ?
                                                 AddressFamily.InterNetworkV6 : AddressFamily.InterNetwork);
#else
                Socket fd = Network.createSocket(false, _addr.AddressFamily);
                Network.setBlock(fd, false);
#endif
#if !COMPACT
                Network.setTcpBufSize(fd, _instance.initializationData().properties, _logger);
#endif

                //
                // Nonblocking connect is handled by the transceiver.
                //
                return(new TcpTransceiver(_instance, fd, _addr, _proxy, false));
            }
            catch (Ice.LocalException ex)
            {
                if (_traceLevels.network >= 2)
                {
                    string s = "failed to establish tcp connection to " + ToString() + "\n" + ex;
                    _logger.trace(_traceLevels.networkCat, s);
                }
                throw;
            }
        }
Example #6
0
        //
        // Only for use by UdpConnector.
        //
        internal UdpTransceiver(Instance instance, EndPoint addr, string mcastInterface, int mcastTtl)
        {
            _traceLevels = instance.traceLevels();
            _logger      = instance.initializationData().logger;
            _stats       = instance.initializationData().stats;
            _addr        = addr;

#if ICE_SOCKET_ASYNC_API
            _readEventArgs = new SocketAsyncEventArgs();
            _readEventArgs.RemoteEndPoint = _addr;
            _readEventArgs.Completed     += new EventHandler <SocketAsyncEventArgs>(ioCompleted);

            _writeEventArgs = new SocketAsyncEventArgs();
            _writeEventArgs.RemoteEndPoint = _addr;
            _writeEventArgs.Completed     += new EventHandler <SocketAsyncEventArgs>(ioCompleted);
#if SILVERLIGHT
            String policy = instance.initializationData().properties.getProperty("Ice.ClientAccessPolicyProtocol");
            if (policy.Equals("Http"))
            {
                _readEventArgs.SocketClientAccessPolicyProtocol  = SocketClientAccessPolicyProtocol.Http;
                _writeEventArgs.SocketClientAccessPolicyProtocol = SocketClientAccessPolicyProtocol.Http;
            }
            else if (!String.IsNullOrEmpty(policy))
            {
                _logger.warning("Ignoring invalid Ice.ClientAccessPolicyProtocol value `" + policy + "'");
            }
#endif
#endif

            _mcastInterface = mcastInterface;
            _mcastTtl       = mcastTtl;
            _state          = StateNeedConnect;
            _incoming       = false;

            try
            {
                _fd = Network.createSocket(true, _addr.AddressFamily);
                setBufSize(instance);
#if !SILVERLIGHT
                Network.setBlock(_fd, false);
                if (AssemblyUtil.osx_)
                {
                    //
                    // On Windows, we delay the join for the mcast group after the connection
                    // establishment succeeds. This is necessary for older Windows versions
                    // where joining the group fails if the socket isn't bound. See ICE-5113.
                    //
                    if (Network.isMulticast((IPEndPoint)_addr))
                    {
                        Network.setMcastGroup(_fd, ((IPEndPoint)_addr).Address, _mcastInterface);
                        if (_mcastTtl != -1)
                        {
                            Network.setMcastTtl(_fd, _mcastTtl, _addr.AddressFamily);
                        }
                    }
                }
#endif
            }
            catch (Ice.LocalException)
            {
                _fd = null;
                throw;
            }
        }