Exemplo n.º 1
0
        public unsafe bool TryGetEndPointByHandle(int handle, out NetworkEndPoint endpoint)
        {
            NetworkEndPoint temp;

            temp.family          = NetworkFamily.IPC;
            *(int *)temp.address = handle;
            bool status = m_IPCEndPoints.TryGetValue(handle, out temp.port);

            endpoint = temp;
            return(status);
        }
Exemplo n.º 2
0
        public unsafe void Bind(NetworkEndPoint endpoint)
        {
            Assert.IsTrue(endpoint.family == NetworkFamily.UdpIpv4);
            var addr = new byte[4];

            for (int i = 0; i < 4; ++i)
            {
                addr[i] = endpoint.address[i];
            }
            m_Socket.Bind(new IPEndPoint(new IPAddress(addr), endpoint.port));
        }
Exemplo n.º 3
0
        public int Bind(NetworkEndPoint endpoint)
        {
            try
            {
                m_NetworkInterface.Bind(endpoint);
            }
            catch (SocketException e)
            {
                var SocketError = e.SocketErrorCode;
                return((int)SocketError);
            }

            DebugLog("Binding " + endpoint);
            return(0);
        }
Exemplo n.º 4
0
 public unsafe void ReleaseEndPoint(NetworkEndPoint endpoint)
 {
     if (endpoint.family == NetworkFamily.IPC)
     {
         int *handle = (int *)endpoint.address;
         m_IPCQueue.Reset(*handle);
         // Bunp the version of the endpoint
         ++m_IPCEndPoints[*handle];
         if (m_IPCEndPoints[*handle] == 0)
         {
             ++m_IPCEndPoints[*handle];
         }
         m_FreeList.ReleaseConnectionId(*handle);
     }
 }
Exemplo n.º 5
0
        public unsafe int SendTo(NetworkEndPoint local, void *slice, int length, NetworkEndPoint remote)
        {
            Assert.IsTrue(remote.family == NetworkFamily.IPC);
            Assert.IsTrue(local.family == NetworkFamily.IPC);
            Assert.IsTrue(remote.port != 0);
            Assert.IsTrue(local.port != 0);

            var data = new IPCData();

            data.from   = *(int *)local.address;
            data.length = length;

            UnsafeUtility.MemCpy(data.data, slice, length);

            m_IPCQueue.Enqueue(*(int *)remote.address, data);
            return(length);
        }
Exemplo n.º 6
0
        public unsafe NetworkConnection Connect(NetworkEndPoint endpoint)
        {
            if (Listening)
            {
                throw new SocketException(10048);
            }

            var address = NetworkEndPoint.ToNetworkAddress(endpoint);

            int id;

            if (!m_FreeList.AquireConnectionId(out id))
            {
                return(default(NetworkConnection));
            }

            int ver = m_ConnectionList[id].Version;
            var c   = new Connection
            {
                Id          = id,
                Version     = ver,
                State       = NetworkConnection.State.Connecting,
                Address     = address,
                Attempts    = 1,
                LastAttempt = Timer.ElapsedMilliseconds
                              // PacketProcessor = packetProcessor
            };

            DebugLog("Connecting to EndPoint=" + endpoint + " ID=" + id);
            m_ConnectionList[id] = c;
            var netcon = new NetworkConnection {
                m_NetworkId = id, m_NetworkVersion = ver
            };

            SendPacket(UdpCProtocol.ConnectionRequest, netcon);

            return(netcon);
        }
Exemplo n.º 7
0
        public static unsafe network_address ToNetworkAddress(NetworkEndPoint ep)
        {
            switch (ep.family)
            {
            case NetworkFamily.UdpIpv4:
                return(SocketExtension.MarshalIpV4Address(ep.address, ep.port));

            case NetworkFamily.IPC:
                network_address addr = default(network_address);
                // TODO: Double check this works on ios as well.
#if (UNITY_EDITOR_OSX || UNITY_STANDALONE_OSX)
                addr.family.sa_family = (byte)AddressFamily.Unspecified;
#else
                addr.family.sa_family = (ushort)AddressFamily.Unspecified;
#endif
                addr.ipc_handle = *(int *)ep.address;
                addr.length     = 6;
                return(addr);

            default:
                throw new NotImplementedException();
            }
        }
Exemplo n.º 8
0
        public unsafe int RecvFrom(NetworkEndPoint local, void *slice, out int length, out NetworkEndPoint from)
        {
            IPCData data;

            from   = default(NetworkEndPoint);
            length = 0;

            if (m_IPCQueue.TryDequeue(*(int *)local.address, out data))
            {
                if (!m_IPCEndPoints.ContainsKey(data.from))
                {
                    return(-1);
                }

                UnsafeUtility.MemCpy(slice, data.data, data.length);

                length = data.length;
            }

            NetworkEndPoint endpoint;

            if (!TryGetEndPointByHandle(data.from, out endpoint))
            {
                return(-1);
            }
            from = endpoint;

            return(length);
        }
Exemplo n.º 9
0
 public unsafe int SendTo(void *slice, int length, NetworkEndPoint remote)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 10
0
 public unsafe int ReceiveFrom(void *slice, out int length, out NetworkEndPoint remote)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 11
0
 unsafe int INetworkInterface.SendTo(void *slice, int length, NetworkEndPoint remote)
 {
     return(IPCManager.Instance.SendTo(m_LocalEndPoint[0], slice, length, remote));
 }
Exemplo n.º 12
0
 public unsafe int ReceiveFrom(void *slice, out int length, out NetworkEndPoint remote)
 {
     return(IPCManager.Instance.RecvFrom(m_LocalEndPoint[0], slice, out length, out remote));
 }
Exemplo n.º 13
0
 public void Bind(NetworkEndPoint endpoint)
 {
     Assert.IsTrue(endpoint.family == NetworkFamily.IPC && endpoint.port != 0);
     m_LocalEndPoint[0] = endpoint;
 }