// 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); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: public bool pollRecv(pspsharp.HLE.TPointer srcMacAddr, pspsharp.HLE.TPointer16 portAddr, pspsharp.HLE.TPointer data, pspsharp.HLE.TPointer32 dataLengthAddr, pspsharp.HLE.kernel.types.SceKernelThreadInfo thread) throws java.io.IOException public virtual bool pollRecv(TPointer srcMacAddr, TPointer16 portAddr, TPointer data, TPointer32 dataLengthAddr, SceKernelThreadInfo thread) { int Length = dataLengthAddr.getValue(); bool completed = false; if (rcvdMessages.Count == 0) { update(); } if (rcvdMessages.Count > 0) { AdhocBufferMessage bufferMessage = rcvdMessages.First.Value; if (Length < bufferMessage.Length) { // Buffer is too small to contain all the available data. // Return the buffer size that would be required. dataLengthAddr.setValue(bufferMessage.Length); setReturnValue(thread, SceKernelErrors.ERROR_NET_BUFFER_TOO_SMALL); } else { // Copy the data already received dataLengthAddr.setValue(bufferMessage.Length); Memory.Instance.memcpy(data.Address, buffer.addr + bufferMessage.offset, bufferMessage.Length); if (srcMacAddr != null && !srcMacAddr.Null) { bufferMessage.macAddress.write(srcMacAddr); } if (portAddr != null && portAddr.NotNull) { portAddr.Value = bufferMessage.port; } removeFirstReceivedMessage(); //if (log.DebugEnabled) { Console.WriteLine(string.Format("Returned received data: {0:D} bytes from {1} on port {2:D}", dataLengthAddr.getValue(), bufferMessage.macAddress, portAddr.Value)); if (log.TraceEnabled) { log.trace(string.Format("Returned data: {0}", Utilities.getMemoryDump(data.Address, dataLengthAddr.getValue()))); } } setReturnValue(thread, 0); } completed = true; } return(completed); }
private void removeFirstReceivedMessage() { AdhocBufferMessage bufferMessage = rcvdMessages.RemoveFirst(); if (bufferMessage == null) { return; } if (rcvdData > bufferMessage.Length) { // Move the remaining buffer data to the beginning of the buffer Memory.Instance.memcpy(buffer.addr, buffer.addr + bufferMessage.Length, rcvdData - bufferMessage.Length); foreach (AdhocBufferMessage rcvdMessage in rcvdMessages) { rcvdMessage.offset -= bufferMessage.Length; } } rcvdData -= bufferMessage.Length; }