123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153 |
- using System;
- using System.Collections.Generic;
- using System.Net;
- using System.Net.Sockets;
- using OpenMetaverse.Packets;
- namespace OpenSim.Region.ClientStack.LindenUDP.Tests
- {
-
-
-
-
- public class TestLLUDPServer : LLUDPServer
- {
-
-
-
- protected Queue<ChunkSenderTuple> m_chunksToLoad = new Queue<ChunkSenderTuple>();
-
- protected override void BeginReceive()
- {
- if (m_chunksToLoad.Count > 0 && m_chunksToLoad.Peek().BeginReceiveException)
- {
- ChunkSenderTuple tuple = m_chunksToLoad.Dequeue();
- reusedEpSender = tuple.Sender;
- throw new SocketException();
- }
- }
-
- protected override bool EndReceive(out int numBytes, IAsyncResult result, ref EndPoint epSender)
- {
- numBytes = 0;
-
-
- if (m_chunksToLoad.Count <= 0)
- return false;
-
- ChunkSenderTuple tuple = m_chunksToLoad.Dequeue();
- RecvBuffer = tuple.Data;
- numBytes = tuple.Data.Length;
- epSender = tuple.Sender;
-
- return true;
- }
-
- public override void SendPacketTo(byte[] buffer, int size, SocketFlags flags, uint circuitcode)
- {
-
- }
-
-
-
-
-
- public void LoadReceiveWithBeginException(EndPoint epSender)
- {
- ChunkSenderTuple tuple = new ChunkSenderTuple(epSender);
- tuple.BeginReceiveException = true;
- m_chunksToLoad.Enqueue(tuple);
- }
-
-
-
-
-
-
- public void LoadReceive(byte[] data, EndPoint epSender)
- {
- m_chunksToLoad.Enqueue(new ChunkSenderTuple(data, epSender));
- }
-
-
-
-
-
- public void LoadReceive(Packet packet, EndPoint epSender)
- {
- LoadReceive(packet.ToBytes(), epSender);
- }
-
-
-
-
-
- public void ReceiveData(IAsyncResult result)
- {
- while (m_chunksToLoad.Count > 0)
- OnReceivedData(result);
- }
-
-
-
-
-
-
- public bool HasCircuit(uint circuitCode)
- {
- lock (clientCircuits_reverse)
- {
- return clientCircuits_reverse.ContainsKey(circuitCode);
- }
- }
- }
-
-
-
-
- public class ChunkSenderTuple
- {
- public byte[] Data;
- public EndPoint Sender;
- public bool BeginReceiveException;
-
- public ChunkSenderTuple(byte[] data, EndPoint sender)
- {
- Data = data;
- Sender = sender;
- }
-
- public ChunkSenderTuple(EndPoint sender)
- {
- Sender = sender;
- }
- }
- }
|