示例#1
0
        public virtual int send(pspNetMacAddress destMacAddress, int destPort, TPointer data, int Length, int timeout, int nonblock)
        {
            int result = 0;

            try
            {
                openSocket();
                setTimeout(timeout, nonblock);
                AdhocMessage adhocMessage = networkAdapter.createAdhocPdpMessage(data.Address, Length, destMacAddress.macAddress);
                send(adhocMessage, destPort);
            }
            catch (SocketException e)
            {
                Console.WriteLine("send", e);
            }
            catch (UnknownHostException e)
            {
                result = SceKernelErrors.ERROR_NET_ADHOC_INVALID_ADDR;
                Console.WriteLine("send", e);
            }
            catch (SocketTimeoutException e)
            {
                Console.WriteLine("send", e);
            }
            catch (IOException e)
            {
                Console.WriteLine("send", e);
            }

            return(result);
        }
示例#2
0
        // For Pdp sockets, data is stored in the internal buffer as a sequence of packets.
        // The organization in packets must be kept for reading.
        private void addReceivedMessage(AdhocMessage adhocMessage, int port)
        {
            AdhocBufferMessage bufferMessage = new AdhocBufferMessage();

            bufferMessage.Length = adhocMessage.DataLength;
            bufferMessage.macAddress.MacAddress = adhocMessage.FromMacAddress;
            bufferMessage.port   = Modules.sceNetAdhocModule.getClientPortFromRealPort(adhocMessage.FromMacAddress, port);
            bufferMessage.offset = rcvdData;
            adhocMessage.writeDataToMemory(buffer.addr + bufferMessage.offset);

            // Update the timestamp of the peer
            Modules.sceNetAdhocctlModule.hleNetAdhocctlPeerUpdateTimestamp(adhocMessage.FromMacAddress);

            //if (log.DebugEnabled)
            {
                Console.WriteLine(string.Format("Successfully received {0:D} bytes from {1} on port {2:D}({3:D})", bufferMessage.Length, bufferMessage.macAddress, bufferMessage.port, port));
                if (log.TraceEnabled)
                {
                    log.trace(string.Format("Message data: {0}", Utilities.getMemoryDump(buffer.addr + bufferMessage.offset, bufferMessage.Length)));
                }
            }

            rcvdData += bufferMessage.Length;
            rcvdMessages.AddLast(bufferMessage);
        }
示例#3
0
        // For Ptp sockets, data is stored in the internal buffer as a continuous byte stream.
        // The organization in packets doesn't matter.
        private int addReceivedMessage(AdhocMessage adhocMessage, int offset)
        {
            int Length = System.Math.Min(adhocMessage.DataLength - offset, BufSize - RcvdData);
            int addr   = buffer.addr + RcvdData;

            adhocMessage.writeDataToMemory(addr, offset, Length);
            rcvdData += Length;
            //if (log.DebugEnabled)
            {
                if (offset == 0)
                {
                    Console.WriteLine(string.Format("Successfully received message (Length={0:D}, rcvdData={1:D}) {2}", Length, RcvdData, adhocMessage));
                }
                else
                {
                    Console.WriteLine(string.Format("Appending received message (offset={0:D}, Length={1:D}, rcvdData={2:D}) {3}", offset, Length, RcvdData, adhocMessage));
                }
                if (log.TraceEnabled)
                {
                    log.trace(string.Format("Message data: {0}", Utilities.getMemoryDump(addr, Length)));
                }
            }

            return(Length);
        }
示例#4
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: @Override public void update() throws java.io.IOException
        public override void update()
        {
            // Receive all messages available
            while (RcvdData < BufSize)
            {
                if (receivedMessage != null)
                {
                    receivedMessageOffset += addReceivedMessage(receivedMessage, receivedMessageOffset);
                    if (receivedMessageOffset >= receivedMessage.DataLength)
                    {
                        receivedMessage       = null;
                        receivedMessageOffset = 0;
                    }
                }
                else
                {
                    try
                    {
                        openSocket();
                        socket.Timeout = 1;
                        sbyte[] bytes  = new sbyte[0x10000];                        // 64K buffer
                        int     Length = socket.receive(bytes, bytes.Length);
                        if (Length <= 0)
                        {
                            break;
                        }
                        int          receivedPort    = socket.ReceivedPort;
                        InetAddress  receivedAddress = socket.ReceivedAddress;
                        AdhocMessage adhocMessage    = createAdhocMessage(bytes, Length);
                        if (isForMe(adhocMessage, receivedPort, receivedAddress))
                        {
                            receivedMessage       = adhocMessage;
                            receivedMessageOffset = 0;
                        }
                        else
                        {
                            //if (log.DebugEnabled)
                            {
                                Console.WriteLine(string.Format("Received message not for me: {0}", adhocMessage));
                            }
                        }
                        //				} catch (SocketException e) {
                        //					Console.WriteLine("update", e);
                        //					break;
                    }
                    catch (SocketTimeoutException)
                    {
                        // Timeout
                        break;
                    }
                }
            }
        }
示例#5
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public void update() throws java.io.IOException
        public virtual void update()
        {
            // Receive all messages available
            while (rcvdData < BufSize)
            {
                try
                {
                    openSocket();
                    socket.Timeout = 1;
                    sbyte[] bytes  = new sbyte[BufSize - rcvdData + MAX_HEADER_SIZE];
                    int     Length = socket.receive(bytes, bytes.Length);
                    if (Length <= 0)
                    {
                        break;
                    }
                    int          receivedPort    = socket.ReceivedPort;
                    InetAddress  receivedAddress = socket.ReceivedAddress;
                    AdhocMessage adhocMessage    = createAdhocMessage(bytes, Length);
                    if (isForMe(adhocMessage, receivedPort, receivedAddress))
                    {
                        if (RcvdData + adhocMessage.DataLength <= BufSize)
                        {
                            addReceivedMessage(adhocMessage, receivedPort);
                        }
                        else
                        {
                            //if (log.DebugEnabled)
                            {
                                Console.WriteLine(string.Format("Discarded message, receive buffer full ({0:D} of {1:D}): {2}", RcvdData, BufSize, adhocMessage));
                            }
                        }
                    }
                    else
                    {
                        //if (log.DebugEnabled)
                        {
                            Console.WriteLine(string.Format("Received message not for me: {0}", adhocMessage));
                        }
                    }
                }
                catch (SocketException e)
                {
                    Console.WriteLine("update", e);
                    break;
                }
                catch (SocketTimeoutException)
                {
                    // Timeout
                    break;
                }
            }
        }
示例#6
0
        public virtual int send(int data, TPointer32 dataSizeAddr, int timeout, int nonblock)
        {
            int result = 0;

            try
            {
                AdhocMessage adhocMessage = networkAdapter.createAdhocPtpMessage(data, dataSizeAddr.getValue());
                send(adhocMessage);
            }
            catch (IOException e)
            {
                result = SceKernelErrors.ERROR_NET_ADHOC_DISCONNECTED;
                Console.WriteLine("send returning ERROR_NET_ADHOC_DISCONNECTED", e);
            }

            return(result);
        }
示例#7
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: protected void send(AdhocMessage adhocMessage, int destPort) throws java.io.IOException
        protected internal virtual void send(AdhocMessage adhocMessage, int destPort)
        {
            if (adhocMessage == null)
            {
                // Nothing to send
                return;
            }

            openSocket();

            int realPort = Modules.sceNetAdhocModule.getRealPortFromClientPort(adhocMessage.ToMacAddress, destPort);

            SocketAddress[] socketAddress = Modules.sceNetAdhocModule.getMultiSocketAddress(adhocMessage.ToMacAddress, realPort);
            for (int i = 0; i < socketAddress.Length; i++)
            {
                socket.send(socketAddress[i], adhocMessage);

                //if (log.DebugEnabled)
                {
                    Console.WriteLine(string.Format("Successfully sent {0:D} bytes to {1}, port {2:D}({3:D}): {4}", adhocMessage.DataLength, socketAddress[i], destPort, realPort, adhocMessage));
                }
            }
        }
示例#8
0
 protected internal virtual bool isForMe(AdhocMessage adhocMessage, int port, InetAddress address)
 {
     return(adhocMessage.ForMe);
 }
示例#9
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: protected void send(AdhocMessage adhocMessage) throws java.io.IOException
        protected internal virtual void send(AdhocMessage adhocMessage)
        {
            send(adhocMessage, Port);
        }
示例#10
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: @Override public void send(AdhocMessage adhocMessage) throws java.io.IOException
        public override void send(AdhocMessage adhocMessage)
        {
            adhocMessage.FromMacAddress = MacAddress.macAddress;
            adhocMessage.ToMacAddress   = DestMacAddress.macAddress;
            send(adhocMessage, DestPort);
        }
示例#11
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public abstract void send(java.net.SocketAddress socketAddress, AdhocMessage adhocMessage) throws java.io.IOException;
        public abstract void send(SocketAddress socketAddress, AdhocMessage adhocMessage);