Update svn properties. Minor formatting cleanup.
parent
279e0061c5
commit
75f6f6e3ff
|
@ -1,30 +1,29 @@
|
|||
/*
|
||||
* Copyright (c) Contributors, http://opensimulator.org/
|
||||
* See CONTRIBUTORS.TXT for a full list of copyright holders.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * Neither the name of the OpenSim Project nor the
|
||||
* names of its contributors may be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
* Copyright (c) Contributors, http://opensimulator.org/
|
||||
* See CONTRIBUTORS.TXT for a full list of copyright holders.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * Neither the name of the OpenSim Project nor the
|
||||
* names of its contributors may be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
|
@ -72,7 +71,7 @@ namespace OpenSim.ApplicationPlugins.LoadBalancer
|
|||
private int proxyOffset;
|
||||
private string proxyURL;
|
||||
private SceneManager sceneManager;
|
||||
private string serializeDir;
|
||||
private string serializeDir;
|
||||
|
||||
private TcpServer mTcpServer;
|
||||
private TcpClient mTcpClient;
|
||||
|
@ -81,7 +80,7 @@ namespace OpenSim.ApplicationPlugins.LoadBalancer
|
|||
{
|
||||
m_log.Info("[BALANCER] "+"Entering Initialize()");
|
||||
|
||||
StartTcpServer();
|
||||
StartTcpServer();
|
||||
ClientView.SynchronizeClient = new ClientView.SynchronizeClientHandler(SynchronizePackets);
|
||||
AsynchronousSocketListener.PacketHandler = new AsynchronousSocketListener.PacketRecieveHandler(SynchronizePacketRecieve);
|
||||
|
||||
|
@ -113,10 +112,10 @@ namespace OpenSim.ApplicationPlugins.LoadBalancer
|
|||
private void StartTcpServer()
|
||||
{
|
||||
Thread server_thread = new Thread(new ThreadStart(
|
||||
delegate {
|
||||
mTcpServer = new TcpServer(10001);
|
||||
mTcpServer.start();
|
||||
}));
|
||||
delegate {
|
||||
mTcpServer = new TcpServer(10001);
|
||||
mTcpServer.start();
|
||||
}));
|
||||
server_thread.Start();
|
||||
}
|
||||
|
||||
|
@ -126,67 +125,67 @@ namespace OpenSim.ApplicationPlugins.LoadBalancer
|
|||
|
||||
private XmlRpcResponse GetStatus(XmlRpcRequest request)
|
||||
{
|
||||
XmlRpcResponse response = new XmlRpcResponse();
|
||||
try
|
||||
XmlRpcResponse response = new XmlRpcResponse();
|
||||
try
|
||||
{
|
||||
m_log.Info("[BALANCER] "+"Entering RegionStatus()");
|
||||
|
||||
int src_port = (int)request.Params[0];
|
||||
Scene scene = null;
|
||||
// try to get the scene object
|
||||
RegionInfo src_region = SearchRegionFromPortNum(src_port);
|
||||
if (sceneManager.TryGetScene(src_region.RegionID, out scene) == false)
|
||||
{
|
||||
m_log.Error("[BALANCER] "+"The Scene is not found");
|
||||
return response;
|
||||
}
|
||||
// serialization of client's informations
|
||||
Scene scene = null;
|
||||
// try to get the scene object
|
||||
RegionInfo src_region = SearchRegionFromPortNum(src_port);
|
||||
if (sceneManager.TryGetScene(src_region.RegionID, out scene) == false)
|
||||
{
|
||||
m_log.Error("[BALANCER] "+"The Scene is not found");
|
||||
return response;
|
||||
}
|
||||
// serialization of client's informations
|
||||
List<ScenePresence> presences = scene.GetScenePresences();
|
||||
int get_scene_presence = presences.Count;
|
||||
int get_scene_presence_filter = 0;
|
||||
foreach (ScenePresence pre in presences)
|
||||
int get_scene_presence = presences.Count;
|
||||
int get_scene_presence_filter = 0;
|
||||
foreach (ScenePresence pre in presences)
|
||||
{
|
||||
ClientView client = (ClientView) pre.ControllingClient;
|
||||
//if(pre.MovementFlag!=0 && client.PacketProcessingEnabled==true) {
|
||||
if(client.PacketProcessingEnabled==true) {
|
||||
get_scene_presence_filter++;
|
||||
}
|
||||
if(client.PacketProcessingEnabled==true) {
|
||||
get_scene_presence_filter++;
|
||||
}
|
||||
}
|
||||
List<ScenePresence> avatars = scene.GetAvatars();
|
||||
int get_avatar = avatars.Count;
|
||||
int get_avatar_filter = 0;
|
||||
string avatar_names = "";
|
||||
foreach (ScenePresence pre in avatars)
|
||||
List<ScenePresence> avatars = scene.GetAvatars();
|
||||
int get_avatar = avatars.Count;
|
||||
int get_avatar_filter = 0;
|
||||
string avatar_names = "";
|
||||
foreach (ScenePresence pre in avatars)
|
||||
{
|
||||
ClientView client = (ClientView) pre.ControllingClient;
|
||||
//if(pre.MovementFlag!=0 && client.PacketProcessingEnabled==true) {
|
||||
if(client.PacketProcessingEnabled==true) {
|
||||
get_avatar_filter++;
|
||||
avatar_names += pre.Firstname + " " + pre.Lastname + "; ";
|
||||
}
|
||||
if(client.PacketProcessingEnabled==true) {
|
||||
get_avatar_filter++;
|
||||
avatar_names += pre.Firstname + " " + pre.Lastname + "; ";
|
||||
}
|
||||
}
|
||||
|
||||
Hashtable responseData = new Hashtable();
|
||||
responseData["get_scene_presence_filter"] = get_scene_presence_filter;
|
||||
responseData["get_scene_presence"] = get_scene_presence;
|
||||
responseData["get_avatar_filter"] = get_avatar_filter;
|
||||
responseData["get_avatar"] = get_avatar;
|
||||
responseData["avatar_names"] = avatar_names;
|
||||
response.Value = responseData;
|
||||
Hashtable responseData = new Hashtable();
|
||||
responseData["get_scene_presence_filter"] = get_scene_presence_filter;
|
||||
responseData["get_scene_presence"] = get_scene_presence;
|
||||
responseData["get_avatar_filter"] = get_avatar_filter;
|
||||
responseData["get_avatar"] = get_avatar;
|
||||
responseData["avatar_names"] = avatar_names;
|
||||
response.Value = responseData;
|
||||
|
||||
m_log.Info("[BALANCER] "+"Exiting RegionStatus()");
|
||||
m_log.Info("[BALANCER] "+"Exiting RegionStatus()");
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
m_log.Error("[BALANCER] "+e.ToString());
|
||||
m_log.Error("[BALANCER] "+e.StackTrace);
|
||||
}
|
||||
return response;
|
||||
return response;
|
||||
}
|
||||
|
||||
private XmlRpcResponse SerializeRegion(XmlRpcRequest request)
|
||||
{
|
||||
try
|
||||
try
|
||||
{
|
||||
m_log.Info("[BALANCER] "+"Entering SerializeRegion()");
|
||||
|
||||
|
@ -431,7 +430,7 @@ namespace OpenSim.ApplicationPlugins.LoadBalancer
|
|||
//scene.Backup();
|
||||
|
||||
m_log.InfoFormat("[BALANCER] "+"region serialization completed [{0}]",
|
||||
src_region.RegionID.ToString());
|
||||
src_region.RegionID.ToString());
|
||||
}
|
||||
|
||||
private void SerializeClient(int idx, Scene scene, ScenePresence pre, string export_dir)
|
||||
|
@ -499,7 +498,7 @@ namespace OpenSim.ApplicationPlugins.LoadBalancer
|
|||
DeserializeClient(dst_region, import_dir);
|
||||
|
||||
m_log.InfoFormat("[BALANCER] "+"region deserialization completed [{0}]",
|
||||
dst_region.ToString());
|
||||
dst_region.ToString());
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
|
@ -527,19 +526,19 @@ namespace OpenSim.ApplicationPlugins.LoadBalancer
|
|||
|
||||
// restore the scene presence
|
||||
/*
|
||||
files = Directory.GetFiles(import_dir, "Presence_*.bin");
|
||||
Array.Sort(files);
|
||||
files = Directory.GetFiles(import_dir, "Presence_*.bin");
|
||||
Array.Sort(files);
|
||||
|
||||
foreach (string filename in files)
|
||||
{
|
||||
sp = (ScenePresence)Util.DeserializeFromFile(filename);
|
||||
Console.WriteLine("agent id = {0}", sp.m_uuid);
|
||||
foreach (string filename in files)
|
||||
{
|
||||
sp = (ScenePresence)Util.DeserializeFromFile(filename);
|
||||
Console.WriteLine("agent id = {0}", sp.m_uuid);
|
||||
|
||||
scene.m_restorePresences.Add(sp.m_uuid, sp);
|
||||
File.Delete(filename);
|
||||
scene.m_restorePresences.Add(sp.m_uuid, sp);
|
||||
File.Delete(filename);
|
||||
|
||||
m_log.InfoFormat("[BALANCER] "+"scene presence deserialized [{0}]", sp.m_uuid);
|
||||
}
|
||||
m_log.InfoFormat("[BALANCER] "+"scene presence deserialized [{0}]", sp.m_uuid);
|
||||
}
|
||||
*/
|
||||
for (int i = 0; ; i++)
|
||||
{
|
||||
|
@ -576,17 +575,17 @@ namespace OpenSim.ApplicationPlugins.LoadBalancer
|
|||
|
||||
udpserv.RestoreClient(agentdata, data.userEP, data.proxyEP);
|
||||
|
||||
// waiting for the scene-presense restored
|
||||
lock (scene.m_restorePresences)
|
||||
{
|
||||
Monitor.Wait(scene.m_restorePresences, 3000);
|
||||
}
|
||||
// waiting for the scene-presense restored
|
||||
lock (scene.m_restorePresences)
|
||||
{
|
||||
Monitor.Wait(scene.m_restorePresences, 3000);
|
||||
}
|
||||
|
||||
if (scene.ClientManager.TryGetClient(circuit_code, out controller))
|
||||
{
|
||||
m_log.InfoFormat("[BALANCER] " + "get client [{0}]", circuit_code);
|
||||
controller.SetClientInfo(data);
|
||||
}
|
||||
if (scene.ClientManager.TryGetClient(circuit_code, out controller))
|
||||
{
|
||||
m_log.InfoFormat("[BALANCER] " + "get client [{0}]", circuit_code);
|
||||
controller.SetClientInfo(data);
|
||||
}
|
||||
|
||||
File.Delete(fname);
|
||||
|
||||
|
@ -622,7 +621,7 @@ namespace OpenSim.ApplicationPlugins.LoadBalancer
|
|||
Console.WriteLine("scene found.");
|
||||
|
||||
if ((sceneManager.CurrentScene != null)
|
||||
&& (sceneManager.CurrentScene.RegionInfo.RegionID == killScene.RegionInfo.RegionID))
|
||||
&& (sceneManager.CurrentScene.RegionInfo.RegionID == killScene.RegionInfo.RegionID))
|
||||
{
|
||||
sceneManager.TrySetCurrentScene("..");
|
||||
}
|
||||
|
@ -671,10 +670,10 @@ namespace OpenSim.ApplicationPlugins.LoadBalancer
|
|||
{
|
||||
// stopping clientview thread
|
||||
if (((ClientView)controller).PacketProcessingEnabled)
|
||||
{
|
||||
{
|
||||
controller.Stop();
|
||||
((ClientView)controller).PacketProcessingEnabled = false;
|
||||
}
|
||||
}
|
||||
// teminateing clientview thread
|
||||
controller.Terminate();
|
||||
m_log.Info("[BALANCER] "+"client thread stopped");
|
||||
|
@ -698,90 +697,90 @@ namespace OpenSim.ApplicationPlugins.LoadBalancer
|
|||
|
||||
private XmlRpcResponse SplitRegion(XmlRpcRequest request)
|
||||
{
|
||||
try
|
||||
{
|
||||
int myID = (int) request.Params[0];
|
||||
int numRegions = (int) request.Params[1];
|
||||
regionPortList = new int[numRegions];
|
||||
sceneURL = new string[numRegions];
|
||||
tcpClientList = new TcpClient[numRegions];
|
||||
try
|
||||
{
|
||||
int myID = (int) request.Params[0];
|
||||
int numRegions = (int) request.Params[1];
|
||||
regionPortList = new int[numRegions];
|
||||
sceneURL = new string[numRegions];
|
||||
tcpClientList = new TcpClient[numRegions];
|
||||
|
||||
for(int i=0; i<numRegions; i++)
|
||||
{
|
||||
regionPortList[i]=(int) request.Params[i+2];
|
||||
sceneURL[i]=(string) request.Params[i+2+numRegions];
|
||||
}
|
||||
for(int i=0; i<numRegions; i++)
|
||||
{
|
||||
regionPortList[i]=(int) request.Params[i+2];
|
||||
sceneURL[i]=(string) request.Params[i+2+numRegions];
|
||||
}
|
||||
|
||||
string hostname;
|
||||
string hostname;
|
||||
|
||||
for(int i=0; i<numRegions; i++)
|
||||
{
|
||||
hostname = sceneURL[i].Split(new char[] { '/', ':' })[3];
|
||||
m_log.InfoFormat("[SPLITSCENE] "+"creating tcp client host:{0}", hostname);
|
||||
tcpClientList[i] = new TcpClient(hostname, 10001);
|
||||
}
|
||||
for(int i=0; i<numRegions; i++)
|
||||
{
|
||||
hostname = sceneURL[i].Split(new char[] { '/', ':' })[3];
|
||||
m_log.InfoFormat("[SPLITSCENE] "+"creating tcp client host:{0}", hostname);
|
||||
tcpClientList[i] = new TcpClient(hostname, 10001);
|
||||
}
|
||||
|
||||
bool isMaster = (myID == 0);
|
||||
bool isMaster = (myID == 0);
|
||||
|
||||
isLocalNeighbour = new bool[numRegions];
|
||||
for(int i=0; i<numRegions; i++) isLocalNeighbour[i] = (sceneURL[i] == sceneURL[myID]);
|
||||
isLocalNeighbour = new bool[numRegions];
|
||||
for(int i=0; i<numRegions; i++) isLocalNeighbour[i] = (sceneURL[i] == sceneURL[myID]);
|
||||
|
||||
RegionInfo region = SearchRegionFromPortNum(regionPortList[myID]);
|
||||
RegionInfo region = SearchRegionFromPortNum(regionPortList[myID]);
|
||||
|
||||
//Console.WriteLine("\n === SplitRegion {0}\n", region.RegionID);
|
||||
//Console.WriteLine("\n === SplitRegion {0}\n", region.RegionID);
|
||||
|
||||
Scene scene;
|
||||
if (sceneManager.TryGetScene(region.RegionID, out scene))
|
||||
{
|
||||
// Disable event updates, backups etc in the slave(s)
|
||||
if (isMaster) {
|
||||
scene.Region_Status = RegionStatus.Up;
|
||||
}
|
||||
else
|
||||
{
|
||||
scene.Region_Status = RegionStatus.SlaveScene;
|
||||
}
|
||||
|
||||
//Console.WriteLine("=== SplitRegion {0}: Scene found, status {1}", region.RegionID, scene.Region_Status);
|
||||
|
||||
// Disabling half of the avatars in master, and the other half in slave
|
||||
|
||||
int i = 0;
|
||||
List<ScenePresence> presences = scene.GetScenePresences();
|
||||
presences.Sort();
|
||||
foreach (ScenePresence pre in presences)
|
||||
{
|
||||
// Divide the presences evenly over the set of subscenes
|
||||
ClientView client = (ClientView) pre.ControllingClient;
|
||||
client.PacketProcessingEnabled = (( (i + myID) % sceneURL.Length) == 0);
|
||||
|
||||
m_log.InfoFormat("[SPLITSCENE] === SplitRegion {0}: SP.PacketEnabled {1}", region.RegionID, client.PacketProcessingEnabled);
|
||||
|
||||
if (!client.PacketProcessingEnabled)
|
||||
{
|
||||
// stopping clientview thread
|
||||
client.Stop();
|
||||
}
|
||||
|
||||
++i;
|
||||
}
|
||||
|
||||
scene.splitID = myID;
|
||||
scene.SynchronizeScene = new Scene.SynchronizeSceneHandler(SynchronizeScenes);
|
||||
isSplit = true;
|
||||
Scene scene;
|
||||
if (sceneManager.TryGetScene(region.RegionID, out scene))
|
||||
{
|
||||
// Disable event updates, backups etc in the slave(s)
|
||||
if (isMaster) {
|
||||
scene.Region_Status = RegionStatus.Up;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_log.Error("[SPLITSCENE] "+String.Format("Scene not found {0}", region.RegionID));
|
||||
scene.Region_Status = RegionStatus.SlaveScene;
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
m_log.Error("[SPLITSCENE] "+e.ToString());
|
||||
m_log.Error("[SPLITSCENE] "+e.StackTrace);
|
||||
}
|
||||
|
||||
return new XmlRpcResponse();
|
||||
//Console.WriteLine("=== SplitRegion {0}: Scene found, status {1}", region.RegionID, scene.Region_Status);
|
||||
|
||||
// Disabling half of the avatars in master, and the other half in slave
|
||||
|
||||
int i = 0;
|
||||
List<ScenePresence> presences = scene.GetScenePresences();
|
||||
presences.Sort();
|
||||
foreach (ScenePresence pre in presences)
|
||||
{
|
||||
// Divide the presences evenly over the set of subscenes
|
||||
ClientView client = (ClientView) pre.ControllingClient;
|
||||
client.PacketProcessingEnabled = (( (i + myID) % sceneURL.Length) == 0);
|
||||
|
||||
m_log.InfoFormat("[SPLITSCENE] === SplitRegion {0}: SP.PacketEnabled {1}", region.RegionID, client.PacketProcessingEnabled);
|
||||
|
||||
if (!client.PacketProcessingEnabled)
|
||||
{
|
||||
// stopping clientview thread
|
||||
client.Stop();
|
||||
}
|
||||
|
||||
++i;
|
||||
}
|
||||
|
||||
scene.splitID = myID;
|
||||
scene.SynchronizeScene = new Scene.SynchronizeSceneHandler(SynchronizeScenes);
|
||||
isSplit = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_log.Error("[SPLITSCENE] "+String.Format("Scene not found {0}", region.RegionID));
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
m_log.Error("[SPLITSCENE] "+e.ToString());
|
||||
m_log.Error("[SPLITSCENE] "+e.StackTrace);
|
||||
}
|
||||
|
||||
return new XmlRpcResponse();
|
||||
}
|
||||
|
||||
private XmlRpcResponse MergeRegions(XmlRpcRequest request)
|
||||
|
@ -794,40 +793,40 @@ presences.Sort();
|
|||
string src_url = (string) request.Params[0];
|
||||
int src_port = (int) request.Params[1];
|
||||
|
||||
RegionInfo region = SearchRegionFromPortNum(src_port);
|
||||
RegionInfo region = SearchRegionFromPortNum(src_port);
|
||||
|
||||
simMain.ProxyCommand(region.proxyUrl, "BlockClientMessages", src_url, src_port + proxyOffset);
|
||||
simMain.ProxyCommand(region.proxyUrl, "BlockClientMessages", src_url, src_port + proxyOffset);
|
||||
|
||||
Scene scene;
|
||||
if (sceneManager.TryGetScene(region.RegionID, out scene))
|
||||
{
|
||||
isSplit = false;
|
||||
Scene scene;
|
||||
if (sceneManager.TryGetScene(region.RegionID, out scene))
|
||||
{
|
||||
isSplit = false;
|
||||
|
||||
scene.SynchronizeScene = null;
|
||||
scene.Region_Status = RegionStatus.Up;
|
||||
scene.SynchronizeScene = null;
|
||||
scene.Region_Status = RegionStatus.Up;
|
||||
|
||||
List<ScenePresence> presences = scene.GetScenePresences();
|
||||
foreach (ScenePresence pre in presences)
|
||||
{
|
||||
ClientView client = (ClientView) pre.ControllingClient;
|
||||
if (!client.PacketProcessingEnabled)
|
||||
{
|
||||
client.Restart();
|
||||
client.PacketProcessingEnabled = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
List<ScenePresence> presences = scene.GetScenePresences();
|
||||
foreach (ScenePresence pre in presences)
|
||||
{
|
||||
ClientView client = (ClientView) pre.ControllingClient;
|
||||
if (!client.PacketProcessingEnabled)
|
||||
{
|
||||
client.Restart();
|
||||
client.PacketProcessingEnabled = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Delete the slave scenes
|
||||
for(int i=1; i<sceneURL.Length; i++)
|
||||
{
|
||||
string url = (sceneURL[i].Split('/')[2]).Split(':')[0]; // get URL part from EP
|
||||
simMain.ProxyCommand(region.proxyUrl, "DeleteRegion", regionPortList[i] + proxyOffset, url);
|
||||
Thread.Sleep(1000);
|
||||
simMain.XmlRpcCommand(sceneURL[i], "TerminateRegion", regionPortList[i]); // TODO: need + proxyOffset?
|
||||
}
|
||||
// Delete the slave scenes
|
||||
for(int i=1; i<sceneURL.Length; i++)
|
||||
{
|
||||
string url = (sceneURL[i].Split('/')[2]).Split(':')[0]; // get URL part from EP
|
||||
simMain.ProxyCommand(region.proxyUrl, "DeleteRegion", regionPortList[i] + proxyOffset, url);
|
||||
Thread.Sleep(1000);
|
||||
simMain.XmlRpcCommand(sceneURL[i], "TerminateRegion", regionPortList[i]); // TODO: need + proxyOffset?
|
||||
}
|
||||
|
||||
simMain.ProxyCommand(region.proxyUrl, "UnblockClientMessages", src_url, src_port + proxyOffset);
|
||||
simMain.ProxyCommand(region.proxyUrl, "UnblockClientMessages", src_url, src_port + proxyOffset);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
|
@ -870,11 +869,11 @@ presences.Sort();
|
|||
{
|
||||
ScenePresence pre = scene.GetScenePresences().Find(delegate(ScenePresence x) { return x.UUID == scenePresenceID; });
|
||||
|
||||
if (pre == null)
|
||||
{
|
||||
if (pre == null)
|
||||
{
|
||||
m_log.ErrorFormat("[SPLITSCENE] [LocalUpdatePhysics] ScenePresence is missing... ({0})", scenePresenceID.ToString());
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// m_log.Info("[SPLITSCENE] "+"LocalUpdatePhysics [region:{0}, client:{1}]",
|
||||
// regionID.ToString(), pre.UUID.ToString());
|
||||
|
@ -905,56 +904,56 @@ presences.Sort();
|
|||
// Because data changes by the physics simulation when the client doesn't move,
|
||||
// if MovementFlag is false, It is necessary to synchronize.
|
||||
//if(pre.MovementFlag!=0 && client.PacketProcessingEnabled==true)
|
||||
if(client.PacketProcessingEnabled==true)
|
||||
if(client.PacketProcessingEnabled==true)
|
||||
{
|
||||
//m_log.Info("[SPLITSCENE] "+String.Format("Client moving in {0} {1}", scene.RegionInfo.RegionID, pre.AbsolutePosition));
|
||||
|
||||
for (int i = 0; i < sceneURL.Length; i++)
|
||||
{
|
||||
if (i == scene.splitID)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
for (int i = 0; i < sceneURL.Length; i++)
|
||||
{
|
||||
if (i == scene.splitID)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if(isLocalNeighbour[i])
|
||||
{
|
||||
//m_log.Info("[SPLITSCENE] "+"Synchronize ScenePresence (Local) [region:{0}=>{1}, client:{2}]",
|
||||
// scene.RegionInfo.RegionID, regionPortList[i], pre.UUID.ToString());
|
||||
LocalUpdatePhysics(regionPortList[i], pre.UUID, pre.AbsolutePosition, pre.Velocity, pre.PhysicsActor.Flying);
|
||||
}
|
||||
else
|
||||
{
|
||||
//m_log.Info("[SPLITSCENE] "+"Synchronize ScenePresence (Remote) [region port:{0}, client:{1}, position:{2}, velocity:{3}, flying:{4}]",
|
||||
// regionPortList[i], pre.UUID.ToString(), pre.AbsolutePosition.ToString(),
|
||||
// pre.Velocity.ToString(), pre.PhysicsActor.Flying);
|
||||
if(isLocalNeighbour[i])
|
||||
{
|
||||
//m_log.Info("[SPLITSCENE] "+"Synchronize ScenePresence (Local) [region:{0}=>{1}, client:{2}]",
|
||||
// scene.RegionInfo.RegionID, regionPortList[i], pre.UUID.ToString());
|
||||
LocalUpdatePhysics(regionPortList[i], pre.UUID, pre.AbsolutePosition, pre.Velocity, pre.PhysicsActor.Flying);
|
||||
}
|
||||
else
|
||||
{
|
||||
//m_log.Info("[SPLITSCENE] "+"Synchronize ScenePresence (Remote) [region port:{0}, client:{1}, position:{2}, velocity:{3}, flying:{4}]",
|
||||
// regionPortList[i], pre.UUID.ToString(), pre.AbsolutePosition.ToString(),
|
||||
// pre.Velocity.ToString(), pre.PhysicsActor.Flying);
|
||||
|
||||
|
||||
simMain.XmlRpcCommand(sceneURL[i], "UpdatePhysics",
|
||||
regionPortList[i], pre.UUID.GetBytes(),
|
||||
pre.AbsolutePosition.GetBytes(), pre.Velocity.GetBytes(),
|
||||
pre.PhysicsActor.Flying);
|
||||
simMain.XmlRpcCommand(sceneURL[i], "UpdatePhysics",
|
||||
regionPortList[i], pre.UUID.GetBytes(),
|
||||
pre.AbsolutePosition.GetBytes(), pre.Velocity.GetBytes(),
|
||||
pre.PhysicsActor.Flying);
|
||||
|
||||
/*
|
||||
byte[] buff = new byte[12+12+1];
|
||||
byte[] buff = new byte[12+12+1];
|
||||
|
||||
Buffer.BlockCopy(pre.AbsolutePosition.GetBytes(), 0, buff, 0, 12);
|
||||
Buffer.BlockCopy(pre.Velocity.GetBytes(), 0, buff, 12, 12);
|
||||
buff[24] = (byte)((pre.PhysicsActor.Flying)?1:0);
|
||||
Buffer.BlockCopy(pre.AbsolutePosition.GetBytes(), 0, buff, 0, 12);
|
||||
Buffer.BlockCopy(pre.Velocity.GetBytes(), 0, buff, 12, 12);
|
||||
buff[24] = (byte)((pre.PhysicsActor.Flying)?1:0);
|
||||
|
||||
// create header
|
||||
InternalPacketHeader header = new InternalPacketHeader();
|
||||
// create header
|
||||
InternalPacketHeader header = new InternalPacketHeader();
|
||||
|
||||
header.type = 1;
|
||||
header.throttlePacketType = 0;
|
||||
header.numbytes = buff.Length;
|
||||
header.agent_id = pre.UUID.UUID;
|
||||
header.region_port = regionPortList[i];
|
||||
header.type = 1;
|
||||
header.throttlePacketType = 0;
|
||||
header.numbytes = buff.Length;
|
||||
header.agent_id = pre.UUID.UUID;
|
||||
header.region_port = regionPortList[i];
|
||||
|
||||
//Send
|
||||
tcpClientList[i].send(header, buff);
|
||||
//Send
|
||||
tcpClientList[i].send(header, buff);
|
||||
*/
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// ++i;
|
||||
}
|
||||
|
@ -968,41 +967,41 @@ presences.Sort();
|
|||
return false;
|
||||
}
|
||||
|
||||
Scene localScene = (Scene)scene;
|
||||
Scene localScene = (Scene)scene;
|
||||
|
||||
for (int i = 0; i < sceneURL.Length; i++)
|
||||
{
|
||||
if (i == localScene.splitID)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if(isLocalNeighbour[i])
|
||||
for (int i = 0; i < sceneURL.Length; i++)
|
||||
{
|
||||
if (i == localScene.splitID)
|
||||
{
|
||||
//m_log.Info("[SPLITSCENE] "+"Synchronize Packet (Local) [type:{0}, client:{1}]",
|
||||
// packet.Type.ToString(), agentID.ToString());
|
||||
LocalUpdatePacket(regionPortList[i], agentID, packet, throttlePacketType);
|
||||
continue;
|
||||
}
|
||||
else
|
||||
|
||||
if(isLocalNeighbour[i])
|
||||
{
|
||||
//m_log.Info("[SPLITSCENE] "+"Synchronize Packet (Remote) [type:{0}, client:{1}]",
|
||||
// packet.Type.ToString(), agentID.ToString());
|
||||
// to bytes
|
||||
byte[] buff = packet.ToBytes();
|
||||
//m_log.Info("[SPLITSCENE] "+"Synchronize Packet (Local) [type:{0}, client:{1}]",
|
||||
// packet.Type.ToString(), agentID.ToString());
|
||||
LocalUpdatePacket(regionPortList[i], agentID, packet, throttlePacketType);
|
||||
}
|
||||
else
|
||||
{
|
||||
//m_log.Info("[SPLITSCENE] "+"Synchronize Packet (Remote) [type:{0}, client:{1}]",
|
||||
// packet.Type.ToString(), agentID.ToString());
|
||||
// to bytes
|
||||
byte[] buff = packet.ToBytes();
|
||||
|
||||
// create header
|
||||
InternalPacketHeader header = new InternalPacketHeader();
|
||||
// create header
|
||||
InternalPacketHeader header = new InternalPacketHeader();
|
||||
|
||||
header.type = 0;
|
||||
header.throttlePacketType = (int)throttlePacketType;
|
||||
header.numbytes = buff.Length;
|
||||
header.agent_id = agentID.UUID;
|
||||
header.region_port = regionPortList[i];
|
||||
header.type = 0;
|
||||
header.throttlePacketType = (int)throttlePacketType;
|
||||
header.numbytes = buff.Length;
|
||||
header.agent_id = agentID.UUID;
|
||||
header.region_port = regionPortList[i];
|
||||
|
||||
//Send
|
||||
tcpClientList[i].send(header, buff);
|
||||
//Send
|
||||
tcpClientList[i].send(header, buff);
|
||||
|
||||
PacketPool.Instance.ReturnPacket(packet);
|
||||
PacketPool.Instance.ReturnPacket(packet);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1022,20 +1021,20 @@ presences.Sort();
|
|||
{
|
||||
ScenePresence pre = scene.GetScenePresences().Find(delegate(ScenePresence x) { return x.UUID == agentID; });
|
||||
|
||||
if (pre == null)
|
||||
{
|
||||
if (pre == null)
|
||||
{
|
||||
m_log.ErrorFormat("[SPLITSCENE] [LocalUpdatePacket] ScenePresence is missing... ({0})", agentID.ToString());
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (((ClientView)pre.ControllingClient).PacketProcessingEnabled==true)
|
||||
{
|
||||
pre.ControllingClient.OutPacket(packet, throttlePacketType);
|
||||
}
|
||||
else
|
||||
{
|
||||
PacketPool.Instance.ReturnPacket(packet);
|
||||
}
|
||||
if (((ClientView)pre.ControllingClient).PacketProcessingEnabled==true)
|
||||
{
|
||||
pre.ControllingClient.OutPacket(packet, throttlePacketType);
|
||||
}
|
||||
else
|
||||
{
|
||||
PacketPool.Instance.ReturnPacket(packet);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1061,22 +1060,22 @@ presences.Sort();
|
|||
// packetEnd = buff.Length;
|
||||
|
||||
try
|
||||
{
|
||||
{
|
||||
//m_log.Info("[SPLITSCENE] "+"PacketPool.Instance : {0}", (PacketPool.Instance == null)?"null":"not null");
|
||||
//m_log.Info("[SPLITSCENE] "+"buff length={0}", buff.Length);
|
||||
|
||||
packet = PacketPool.Instance.GetPacket(buff, ref packetEnd, zero);
|
||||
|
||||
LocalUpdatePacket(header.region_port, new LLUUID(header.agent_id),
|
||||
packet, (ThrottleOutPacketType)header.throttlePacketType);
|
||||
}
|
||||
packet, (ThrottleOutPacketType)header.throttlePacketType);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
{
|
||||
m_log.Error("[SPLITSCENE] "+e.ToString());
|
||||
m_log.Error("[SPLITSCENE] "+e.StackTrace);
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
break;
|
||||
|
||||
case 1:
|
||||
|
||||
|
|
|
@ -1,30 +1,29 @@
|
|||
/*
|
||||
* Copyright (c) Contributors, http://opensimulator.org/
|
||||
* See CONTRIBUTORS.TXT for a full list of copyright holders.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * Neither the name of the OpenSim Project nor the
|
||||
* names of its contributors may be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
* Copyright (c) Contributors, http://opensimulator.org/
|
||||
* See CONTRIBUTORS.TXT for a full list of copyright holders.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * Neither the name of the OpenSim Project nor the
|
||||
* names of its contributors may be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
|
@ -35,196 +34,197 @@ using System.Text;
|
|||
using System.Runtime.Serialization.Formatters.Binary;
|
||||
|
||||
namespace OpenSim.ApplicationPlugins.LoadBalancer {
|
||||
public class AsynchronousClient {
|
||||
private static ManualResetEvent connectDone = new ManualResetEvent(false);
|
||||
private static ManualResetEvent sendDone = new ManualResetEvent(false);
|
||||
private static ManualResetEvent receiveDone = new ManualResetEvent(false);
|
||||
private static String response = String.Empty;
|
||||
public class AsynchronousClient {
|
||||
private static ManualResetEvent connectDone = new ManualResetEvent(false);
|
||||
private static ManualResetEvent sendDone = new ManualResetEvent(false);
|
||||
private static ManualResetEvent receiveDone = new ManualResetEvent(false);
|
||||
private static String response = String.Empty;
|
||||
|
||||
public static Socket StartClient(string hostname, int port) {
|
||||
try {
|
||||
IPHostEntry ipHostInfo = Dns.GetHostEntry(hostname);
|
||||
IPAddress ipAddress = ipHostInfo.AddressList[0];
|
||||
IPEndPoint remoteEP = new IPEndPoint(ipAddress, port);
|
||||
public static Socket StartClient(string hostname, int port) {
|
||||
try {
|
||||
IPHostEntry ipHostInfo = Dns.GetHostEntry(hostname);
|
||||
IPAddress ipAddress = ipHostInfo.AddressList[0];
|
||||
IPEndPoint remoteEP = new IPEndPoint(ipAddress, port);
|
||||
|
||||
Socket client = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
|
||||
client.BeginConnect( remoteEP, new AsyncCallback(ConnectCallback), client);
|
||||
connectDone.WaitOne();
|
||||
/*
|
||||
Send(client,"This is a test<EOF>");
|
||||
sendDone.WaitOne();
|
||||
Receive(client);
|
||||
receiveDone.WaitOne();
|
||||
client.Shutdown(SocketShutdown.Both);
|
||||
client.Close();
|
||||
*/
|
||||
return client;
|
||||
} catch (Exception e) {
|
||||
Console.WriteLine(e.ToString());
|
||||
throw new Exception("socket error !!");
|
||||
}
|
||||
}
|
||||
Socket client = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
|
||||
client.BeginConnect( remoteEP, new AsyncCallback(ConnectCallback), client);
|
||||
connectDone.WaitOne();
|
||||
/*
|
||||
Send(client,"This is a test<EOF>");
|
||||
sendDone.WaitOne();
|
||||
Receive(client);
|
||||
receiveDone.WaitOne();
|
||||
client.Shutdown(SocketShutdown.Both);
|
||||
client.Close();
|
||||
*/
|
||||
return client;
|
||||
} catch (Exception e) {
|
||||
Console.WriteLine(e.ToString());
|
||||
throw new Exception("socket error !!");
|
||||
}
|
||||
}
|
||||
|
||||
private static void ConnectCallback(IAsyncResult ar) {
|
||||
try {
|
||||
Socket client = (Socket) ar.AsyncState;
|
||||
client.EndConnect(ar);
|
||||
Console.WriteLine("Socket connected to {0}", client.RemoteEndPoint.ToString());
|
||||
connectDone.Set();
|
||||
} catch (Exception e) {
|
||||
Console.WriteLine(e.ToString());
|
||||
}
|
||||
}
|
||||
private static void ConnectCallback(IAsyncResult ar) {
|
||||
try {
|
||||
Socket client = (Socket) ar.AsyncState;
|
||||
client.EndConnect(ar);
|
||||
Console.WriteLine("Socket connected to {0}", client.RemoteEndPoint.ToString());
|
||||
connectDone.Set();
|
||||
} catch (Exception e) {
|
||||
Console.WriteLine(e.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
public static void Receive(Socket client) {
|
||||
try {
|
||||
StateObject state = new StateObject();
|
||||
state.workSocket = client;
|
||||
client.BeginReceive( state.buffer, 0, StateObject.BufferSize, 0, new AsyncCallback(ReceiveCallback), state);
|
||||
} catch (Exception e) {
|
||||
Console.WriteLine(e.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
private static void ReceiveCallback( IAsyncResult ar ) {
|
||||
try {
|
||||
StateObject state = (StateObject) ar.AsyncState;
|
||||
Socket client = state.workSocket;
|
||||
|
||||
int bytesRead = client.EndReceive(ar);
|
||||
if (bytesRead > 0) {
|
||||
state.sb.Append(Encoding.ASCII.GetString(state.buffer,0,bytesRead));
|
||||
client.BeginReceive(state.buffer,0,StateObject.BufferSize,0, new AsyncCallback(ReceiveCallback), state);
|
||||
} else {
|
||||
if (state.sb.Length > 1) {
|
||||
response = state.sb.ToString();
|
||||
}
|
||||
receiveDone.Set();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Console.WriteLine(e.ToString());
|
||||
}
|
||||
}
|
||||
*/
|
||||
public static void Send(Socket client, byte[] byteData) {
|
||||
client.BeginSend(byteData, 0, byteData.Length, 0, new AsyncCallback(SendCallback), client);
|
||||
}
|
||||
|
||||
private static void SendCallback(IAsyncResult ar) {
|
||||
try {
|
||||
Socket client = (Socket) ar.AsyncState;
|
||||
int bytesSent = client.EndSend(ar);
|
||||
//Console.WriteLine("Sent {0} bytes to server.", bytesSent);
|
||||
sendDone.Set();
|
||||
} catch (Exception e) {
|
||||
Console.WriteLine(e.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class InternalPacketHeader
|
||||
{
|
||||
private byte[] buffer = new byte[32];
|
||||
public int type;
|
||||
public int throttlePacketType;
|
||||
public int numbytes;
|
||||
public Guid agent_id;
|
||||
public int region_port;
|
||||
|
||||
public void FromBytes(byte[] bytes)
|
||||
{
|
||||
int i = 0; // offset
|
||||
try
|
||||
{
|
||||
this.type = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24));
|
||||
this.throttlePacketType = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24));
|
||||
this.numbytes = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24));
|
||||
this.agent_id = new Guid(
|
||||
bytes[i++] | (bytes[i++] << 8) | (bytes[i++] << 16) | bytes[i++] << 24,
|
||||
(short)(bytes[i++] | (bytes[i++] << 8)),
|
||||
(short)(bytes[i++] | (bytes[i++] << 8)),
|
||||
bytes[i++], bytes[i++], bytes[i++], bytes[i++],
|
||||
bytes[i++], bytes[i++], bytes[i++], bytes[i++]);
|
||||
this.region_port = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24));
|
||||
public static void Receive(Socket client) {
|
||||
try {
|
||||
StateObject state = new StateObject();
|
||||
state.workSocket = client;
|
||||
client.BeginReceive( state.buffer, 0, StateObject.BufferSize, 0, new AsyncCallback(ReceiveCallback), state);
|
||||
} catch (Exception e) {
|
||||
Console.WriteLine(e.ToString());
|
||||
}
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
throw new Exception("bad format!!!");
|
||||
|
||||
private static void ReceiveCallback( IAsyncResult ar ) {
|
||||
try {
|
||||
StateObject state = (StateObject) ar.AsyncState;
|
||||
Socket client = state.workSocket;
|
||||
|
||||
int bytesRead = client.EndReceive(ar);
|
||||
if (bytesRead > 0) {
|
||||
state.sb.Append(Encoding.ASCII.GetString(state.buffer,0,bytesRead));
|
||||
client.BeginReceive(state.buffer,0,StateObject.BufferSize,0, new AsyncCallback(ReceiveCallback), state);
|
||||
} else {
|
||||
if (state.sb.Length > 1) {
|
||||
response = state.sb.ToString();
|
||||
}
|
||||
receiveDone.Set();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Console.WriteLine(e.ToString());
|
||||
}
|
||||
}
|
||||
*/
|
||||
public static void Send(Socket client, byte[] byteData) {
|
||||
client.BeginSend(byteData, 0, byteData.Length, 0, new AsyncCallback(SendCallback), client);
|
||||
}
|
||||
|
||||
private static void SendCallback(IAsyncResult ar) {
|
||||
try {
|
||||
Socket client = (Socket) ar.AsyncState;
|
||||
int bytesSent = client.EndSend(ar);
|
||||
//Console.WriteLine("Sent {0} bytes to server.", bytesSent);
|
||||
sendDone.Set();
|
||||
} catch (Exception e) {
|
||||
Console.WriteLine(e.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public byte[] ToBytes()
|
||||
public class InternalPacketHeader
|
||||
{
|
||||
int i = 0;
|
||||
this.buffer[i++] = (byte)(this.type % 256);
|
||||
this.buffer[i++] = (byte)((this.type >> 8) % 256);
|
||||
this.buffer[i++] = (byte)((this.type >> 16) % 256);
|
||||
this.buffer[i++] = (byte)((this.type >> 24) % 256);
|
||||
private byte[] buffer = new byte[32];
|
||||
public int type;
|
||||
public int throttlePacketType;
|
||||
public int numbytes;
|
||||
public Guid agent_id;
|
||||
public int region_port;
|
||||
|
||||
this.buffer[i++] = (byte)(this.throttlePacketType % 256);
|
||||
this.buffer[i++] = (byte)((this.throttlePacketType >> 8) % 256);
|
||||
this.buffer[i++] = (byte)((this.throttlePacketType >> 16) % 256);
|
||||
this.buffer[i++] = (byte)((this.throttlePacketType >> 24) % 256);
|
||||
public void FromBytes(byte[] bytes)
|
||||
{
|
||||
int i = 0; // offset
|
||||
try
|
||||
{
|
||||
this.type = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24));
|
||||
this.throttlePacketType = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24));
|
||||
this.numbytes = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24));
|
||||
this.agent_id = new Guid(
|
||||
bytes[i++] | (bytes[i++] << 8) | (bytes[i++] << 16) | bytes[i++] << 24,
|
||||
(short)(bytes[i++] | (bytes[i++] << 8)),
|
||||
(short)(bytes[i++] | (bytes[i++] << 8)),
|
||||
bytes[i++], bytes[i++], bytes[i++], bytes[i++],
|
||||
bytes[i++], bytes[i++], bytes[i++], bytes[i++]);
|
||||
this.region_port = (int)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24));
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
throw new Exception("bad format!!!");
|
||||
}
|
||||
}
|
||||
|
||||
this.buffer[i++] = (byte)(this.numbytes % 256);
|
||||
this.buffer[i++] = (byte)((this.numbytes >> 8) % 256);
|
||||
this.buffer[i++] = (byte)((this.numbytes >> 16) % 256);
|
||||
this.buffer[i++] = (byte)((this.numbytes >> 24) % 256);
|
||||
public byte[] ToBytes()
|
||||
{
|
||||
int i = 0;
|
||||
this.buffer[i++] = (byte)(this.type % 256);
|
||||
this.buffer[i++] = (byte)((this.type >> 8) % 256);
|
||||
this.buffer[i++] = (byte)((this.type >> 16) % 256);
|
||||
this.buffer[i++] = (byte)((this.type >> 24) % 256);
|
||||
|
||||
// no endian care
|
||||
Buffer.BlockCopy(agent_id.ToByteArray(), 0, this.buffer, i, 16); i += 16;
|
||||
this.buffer[i++] = (byte)(this.throttlePacketType % 256);
|
||||
this.buffer[i++] = (byte)((this.throttlePacketType >> 8) % 256);
|
||||
this.buffer[i++] = (byte)((this.throttlePacketType >> 16) % 256);
|
||||
this.buffer[i++] = (byte)((this.throttlePacketType >> 24) % 256);
|
||||
|
||||
this.buffer[i++] = (byte)(this.region_port % 256);
|
||||
this.buffer[i++] = (byte)((this.region_port >> 8) % 256);
|
||||
this.buffer[i++] = (byte)((this.region_port >> 16) % 256);
|
||||
this.buffer[i++] = (byte)((this.region_port >> 24) % 256);
|
||||
this.buffer[i++] = (byte)(this.numbytes % 256);
|
||||
this.buffer[i++] = (byte)((this.numbytes >> 8) % 256);
|
||||
this.buffer[i++] = (byte)((this.numbytes >> 16) % 256);
|
||||
this.buffer[i++] = (byte)((this.numbytes >> 24) % 256);
|
||||
|
||||
return this.buffer;
|
||||
}
|
||||
}
|
||||
public class TcpClient {
|
||||
// no endian care
|
||||
Buffer.BlockCopy(agent_id.ToByteArray(), 0, this.buffer, i, 16); i += 16;
|
||||
|
||||
public static int internalPacketHeaderSize = 4*4 + 16*1;
|
||||
this.buffer[i++] = (byte)(this.region_port % 256);
|
||||
this.buffer[i++] = (byte)((this.region_port >> 8) % 256);
|
||||
this.buffer[i++] = (byte)((this.region_port >> 16) % 256);
|
||||
this.buffer[i++] = (byte)((this.region_port >> 24) % 256);
|
||||
|
||||
private string mHostname;
|
||||
private int mPort;
|
||||
private Socket mConnection;
|
||||
public TcpClient(string hostname, int port) {
|
||||
this.mHostname = hostname;
|
||||
this.mPort = port;
|
||||
this.mConnection = null;
|
||||
}
|
||||
public void connect() {
|
||||
this.mConnection = AsynchronousClient.StartClient(mHostname, mPort);
|
||||
}
|
||||
return this.buffer;
|
||||
}
|
||||
}
|
||||
|
||||
public class TcpClient {
|
||||
|
||||
public static int internalPacketHeaderSize = 4*4 + 16*1;
|
||||
|
||||
private string mHostname;
|
||||
private int mPort;
|
||||
private Socket mConnection;
|
||||
public TcpClient(string hostname, int port) {
|
||||
this.mHostname = hostname;
|
||||
this.mPort = port;
|
||||
this.mConnection = null;
|
||||
}
|
||||
public void connect() {
|
||||
this.mConnection = AsynchronousClient.StartClient(mHostname, mPort);
|
||||
}
|
||||
/*
|
||||
public void recevie() {
|
||||
if (mConnection == null) {
|
||||
throw new Exception("client not initialized");
|
||||
}
|
||||
try
|
||||
{
|
||||
AsynchronousClient.Receive(this.mConnection);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Console.WriteLine(e.ToString());
|
||||
mConnection = null;
|
||||
}
|
||||
}
|
||||
public void recevie() {
|
||||
if (mConnection == null) {
|
||||
throw new Exception("client not initialized");
|
||||
}
|
||||
try
|
||||
{
|
||||
AsynchronousClient.Receive(this.mConnection);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Console.WriteLine(e.ToString());
|
||||
mConnection = null;
|
||||
}
|
||||
}
|
||||
*/
|
||||
public void send(InternalPacketHeader header, byte[] packet) {
|
||||
public void send(InternalPacketHeader header, byte[] packet) {
|
||||
|
||||
lock (this)
|
||||
lock (this)
|
||||
{
|
||||
|
||||
if (mConnection == null) {
|
||||
// throw new Exception("client not initialized");
|
||||
connect();
|
||||
}
|
||||
if (mConnection == null) {
|
||||
// throw new Exception("client not initialized");
|
||||
connect();
|
||||
}
|
||||
|
||||
AsynchronousClient.Send(this.mConnection, header.ToBytes());
|
||||
AsynchronousClient.Send(this.mConnection, header.ToBytes());
|
||||
|
||||
/*
|
||||
for (int i = 0; i < 10; i++)
|
||||
|
@ -233,8 +233,8 @@ for (int i = 0; i < 10; i++)
|
|||
}
|
||||
Console.WriteLine("");
|
||||
*/
|
||||
AsynchronousClient.Send(this.mConnection, packet);
|
||||
AsynchronousClient.Send(this.mConnection, packet);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,30 +1,29 @@
|
|||
/*
|
||||
* Copyright (c) Contributors, http://opensimulator.org/
|
||||
* See CONTRIBUTORS.TXT for a full list of copyright holders.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * Neither the name of the OpenSim Project nor the
|
||||
* names of its contributors may be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
* Copyright (c) Contributors, http://opensimulator.org/
|
||||
* See CONTRIBUTORS.TXT for a full list of copyright holders.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * Neither the name of the OpenSim Project nor the
|
||||
* names of its contributors may be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
|
@ -38,182 +37,180 @@ using OpenSim.Framework.Console;
|
|||
|
||||
namespace OpenSim.ApplicationPlugins.LoadBalancer {
|
||||
|
||||
public class StateObject {
|
||||
public Socket workSocket = null;
|
||||
public const int BufferSize = 2048;
|
||||
public byte[] buffer = new byte[BufferSize];
|
||||
public MemoryStream ms_ptr = new MemoryStream();
|
||||
public InternalPacketHeader header = null;
|
||||
}
|
||||
public class StateObject {
|
||||
public Socket workSocket = null;
|
||||
public const int BufferSize = 2048;
|
||||
public byte[] buffer = new byte[BufferSize];
|
||||
public MemoryStream ms_ptr = new MemoryStream();
|
||||
public InternalPacketHeader header = null;
|
||||
}
|
||||
|
||||
public class AsynchronousSocketListener {
|
||||
public static string data = null;
|
||||
public static ManualResetEvent allDone = new ManualResetEvent(false);
|
||||
public class AsynchronousSocketListener {
|
||||
public static string data = null;
|
||||
public static ManualResetEvent allDone = new ManualResetEvent(false);
|
||||
|
||||
#region KIRYU
|
||||
public delegate void PacketRecieveHandler(InternalPacketHeader header, byte[] buff);
|
||||
public static PacketRecieveHandler PacketHandler = null;
|
||||
#endregion
|
||||
|
||||
public AsynchronousSocketListener() { }
|
||||
public AsynchronousSocketListener() { }
|
||||
|
||||
public static void StartListening(int port) {
|
||||
IPHostEntry ipHostInfo = Dns.GetHostEntry(Dns.GetHostName());
|
||||
IPAddress ipAddress = ipHostInfo.AddressList[0];
|
||||
IPEndPoint localEndPoint = new IPEndPoint(ipAddress, port);
|
||||
public static void StartListening(int port) {
|
||||
IPHostEntry ipHostInfo = Dns.GetHostEntry(Dns.GetHostName());
|
||||
IPAddress ipAddress = ipHostInfo.AddressList[0];
|
||||
IPEndPoint localEndPoint = new IPEndPoint(ipAddress, port);
|
||||
|
||||
Socket listener = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp );
|
||||
try {
|
||||
listener.Bind(localEndPoint);
|
||||
listener.Listen(100);
|
||||
while (true) {
|
||||
allDone.Reset();
|
||||
listener.BeginAccept( new AsyncCallback(AcceptCallback), listener );
|
||||
allDone.WaitOne();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Console.WriteLine(e.ToString());
|
||||
}
|
||||
/*
|
||||
Console.WriteLine("\nPress ENTER to continue...");
|
||||
Console.Read();
|
||||
*/
|
||||
}
|
||||
Socket listener = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp );
|
||||
try {
|
||||
listener.Bind(localEndPoint);
|
||||
listener.Listen(100);
|
||||
while (true) {
|
||||
allDone.Reset();
|
||||
listener.BeginAccept( new AsyncCallback(AcceptCallback), listener );
|
||||
allDone.WaitOne();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Console.WriteLine(e.ToString());
|
||||
}
|
||||
/*
|
||||
Console.WriteLine("\nPress ENTER to continue...");
|
||||
Console.Read();
|
||||
*/
|
||||
}
|
||||
|
||||
public static void AcceptCallback(IAsyncResult ar) {
|
||||
allDone.Set();
|
||||
Socket listener = (Socket) ar.AsyncState;
|
||||
Socket handler = listener.EndAccept(ar);
|
||||
StateObject state = new StateObject();
|
||||
state.workSocket = handler;
|
||||
handler.BeginReceive( state.buffer, 0, StateObject.BufferSize, 0, new AsyncCallback(ReadCallback), state);
|
||||
}
|
||||
public static void AcceptCallback(IAsyncResult ar) {
|
||||
allDone.Set();
|
||||
Socket listener = (Socket) ar.AsyncState;
|
||||
Socket handler = listener.EndAccept(ar);
|
||||
StateObject state = new StateObject();
|
||||
state.workSocket = handler;
|
||||
handler.BeginReceive( state.buffer, 0, StateObject.BufferSize, 0, new AsyncCallback(ReadCallback), state);
|
||||
}
|
||||
|
||||
public static void ReadCallback(IAsyncResult ar) {
|
||||
String content = String.Empty;
|
||||
StateObject state = (StateObject) ar.AsyncState;
|
||||
Socket handler = state.workSocket;
|
||||
public static void ReadCallback(IAsyncResult ar) {
|
||||
String content = String.Empty;
|
||||
StateObject state = (StateObject) ar.AsyncState;
|
||||
Socket handler = state.workSocket;
|
||||
|
||||
try
|
||||
{
|
||||
int bytesRead = handler.EndReceive(ar);
|
||||
|
||||
int bytesRead = handler.EndReceive(ar);
|
||||
//MainLog.Instance.Verbose("TCPSERVER", "Received packet [{0}]", bytesRead);
|
||||
|
||||
//MainLog.Instance.Verbose("TCPSERVER", "Received packet [{0}]", bytesRead);
|
||||
if (bytesRead > 0) {
|
||||
state.ms_ptr.Write(state.buffer, 0, bytesRead);
|
||||
}
|
||||
else
|
||||
{
|
||||
//MainLog.Instance.Verbose("TCPSERVER", "Connection terminated");
|
||||
return;
|
||||
}
|
||||
|
||||
if (bytesRead > 0) {
|
||||
state.ms_ptr.Write(state.buffer, 0, bytesRead);
|
||||
}
|
||||
else
|
||||
{
|
||||
//MainLog.Instance.Verbose("TCPSERVER", "Connection terminated");
|
||||
return;
|
||||
}
|
||||
long rest_size = state.ms_ptr.Length;
|
||||
long current_pos = 0;
|
||||
while (rest_size > TcpClient.internalPacketHeaderSize) {
|
||||
|
||||
long rest_size = state.ms_ptr.Length;
|
||||
long current_pos = 0;
|
||||
while (rest_size > TcpClient.internalPacketHeaderSize) {
|
||||
if ((state.header == null) && (rest_size >= TcpClient.internalPacketHeaderSize))
|
||||
{
|
||||
//MainLog.Instance.Verbose("TCPSERVER", "Processing header");
|
||||
|
||||
if ((state.header == null) && (rest_size >= TcpClient.internalPacketHeaderSize))
|
||||
{
|
||||
//MainLog.Instance.Verbose("TCPSERVER", "Processing header");
|
||||
// reading header
|
||||
state.header = new InternalPacketHeader();
|
||||
|
||||
// reading header
|
||||
state.header = new InternalPacketHeader();
|
||||
byte[] headerbytes = new byte[TcpClient.internalPacketHeaderSize];
|
||||
state.ms_ptr.Position = current_pos;
|
||||
state.ms_ptr.Read(headerbytes, 0, TcpClient.internalPacketHeaderSize);
|
||||
state.ms_ptr.Seek(0, SeekOrigin.End);
|
||||
state.header.FromBytes(headerbytes);
|
||||
}
|
||||
|
||||
byte[] headerbytes = new byte[TcpClient.internalPacketHeaderSize];
|
||||
state.ms_ptr.Position = current_pos;
|
||||
state.ms_ptr.Read(headerbytes, 0, TcpClient.internalPacketHeaderSize);
|
||||
state.ms_ptr.Seek(0, SeekOrigin.End);
|
||||
state.header.FromBytes(headerbytes);
|
||||
}
|
||||
if ((state.header != null) && (rest_size >= state.header.numbytes + TcpClient.internalPacketHeaderSize))
|
||||
{
|
||||
//MainLog.Instance.Verbose("TCPSERVER", "Processing body");
|
||||
|
||||
if ((state.header != null) && (rest_size >= state.header.numbytes + TcpClient.internalPacketHeaderSize))
|
||||
{
|
||||
//MainLog.Instance.Verbose("TCPSERVER", "Processing body");
|
||||
|
||||
// reading body
|
||||
byte[] packet = new byte[state.header.numbytes];
|
||||
state.ms_ptr.Position = current_pos + TcpClient.internalPacketHeaderSize;
|
||||
state.ms_ptr.Read(packet, 0, state.header.numbytes);
|
||||
// reading body
|
||||
byte[] packet = new byte[state.header.numbytes];
|
||||
state.ms_ptr.Position = current_pos + TcpClient.internalPacketHeaderSize;
|
||||
state.ms_ptr.Read(packet, 0, state.header.numbytes);
|
||||
|
||||
/*
|
||||
for(int i=0; i<state.header.numbytes; i++) {
|
||||
System.Console.Write(packet[i] + " ");
|
||||
}
|
||||
System.Console.WriteLine();
|
||||
for(int i=0; i<state.header.numbytes; i++) {
|
||||
System.Console.Write(packet[i] + " ");
|
||||
}
|
||||
System.Console.WriteLine();
|
||||
*/
|
||||
|
||||
state.ms_ptr.Seek(0, SeekOrigin.End);
|
||||
// call loadbarancer function
|
||||
if (PacketHandler != null)
|
||||
{
|
||||
//MainLog.Instance.Verbose("TCPSERVER", "calling PacketHandler");
|
||||
PacketHandler(state.header, packet);
|
||||
}
|
||||
else
|
||||
{
|
||||
//MainLog.Instance.Verbose("TCPSERVER", "PacketHandler not found");
|
||||
}
|
||||
state.ms_ptr.Seek(0, SeekOrigin.End);
|
||||
// call loadbarancer function
|
||||
if (PacketHandler != null)
|
||||
{
|
||||
//MainLog.Instance.Verbose("TCPSERVER", "calling PacketHandler");
|
||||
PacketHandler(state.header, packet);
|
||||
}
|
||||
else
|
||||
{
|
||||
//MainLog.Instance.Verbose("TCPSERVER", "PacketHandler not found");
|
||||
}
|
||||
|
||||
int read_size = state.header.numbytes + TcpClient.internalPacketHeaderSize;
|
||||
state.header = null;
|
||||
int read_size = state.header.numbytes + TcpClient.internalPacketHeaderSize;
|
||||
state.header = null;
|
||||
|
||||
rest_size -= read_size;
|
||||
current_pos += read_size;
|
||||
rest_size -= read_size;
|
||||
current_pos += read_size;
|
||||
|
||||
if (rest_size < TcpClient.internalPacketHeaderSize) {
|
||||
if (rest_size < TcpClient.internalPacketHeaderSize) {
|
||||
|
||||
byte[] rest_bytes = new byte[rest_size];
|
||||
state.ms_ptr.Position = read_size;
|
||||
state.ms_ptr.Read(rest_bytes, 0, (int)rest_size);
|
||||
state.ms_ptr.Close();
|
||||
state.ms_ptr = new MemoryStream();
|
||||
state.ms_ptr.Write(rest_bytes, 0, (int)rest_size);
|
||||
break;
|
||||
}
|
||||
}
|
||||
byte[] rest_bytes = new byte[rest_size];
|
||||
state.ms_ptr.Position = read_size;
|
||||
state.ms_ptr.Read(rest_bytes, 0, (int)rest_size);
|
||||
state.ms_ptr.Close();
|
||||
state.ms_ptr = new MemoryStream();
|
||||
state.ms_ptr.Write(rest_bytes, 0, (int)rest_size);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
} // while (true)
|
||||
} // while (true)
|
||||
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
//MainLog.Instance.Verbose("TCPSERVER", e.ToString());
|
||||
//MainLog.Instance.Verbose("TCPSERVER", e.StackTrace);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
//MainLog.Instance.Verbose("TCPSERVER", e.ToString());
|
||||
//MainLog.Instance.Verbose("TCPSERVER", e.StackTrace);
|
||||
}
|
||||
|
||||
handler.BeginReceive( state.buffer, 0, StateObject.BufferSize, 0, new AsyncCallback(ReadCallback), state);
|
||||
}
|
||||
handler.BeginReceive( state.buffer, 0, StateObject.BufferSize, 0, new AsyncCallback(ReadCallback), state);
|
||||
}
|
||||
|
||||
private static void Send(Socket handler, String data) {
|
||||
byte[] byteData = Encoding.ASCII.GetBytes(data);
|
||||
handler.BeginSend(byteData, 0, byteData.Length, 0, new AsyncCallback(SendCallback), handler);
|
||||
}
|
||||
private static void Send(Socket handler, String data) {
|
||||
byte[] byteData = Encoding.ASCII.GetBytes(data);
|
||||
handler.BeginSend(byteData, 0, byteData.Length, 0, new AsyncCallback(SendCallback), handler);
|
||||
}
|
||||
|
||||
private static void SendCallback(IAsyncResult ar) {
|
||||
try {
|
||||
Socket handler = (Socket) ar.AsyncState;
|
||||
int bytesSent = handler.EndSend(ar);
|
||||
//Console.WriteLine("Sent {0} bytes to client.", bytesSent);
|
||||
handler.Shutdown(SocketShutdown.Both);
|
||||
handler.Close();
|
||||
} catch (Exception e) {
|
||||
Console.WriteLine(e.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
private static void SendCallback(IAsyncResult ar) {
|
||||
try {
|
||||
Socket handler = (Socket) ar.AsyncState;
|
||||
int bytesSent = handler.EndSend(ar);
|
||||
//Console.WriteLine("Sent {0} bytes to client.", bytesSent);
|
||||
handler.Shutdown(SocketShutdown.Both);
|
||||
handler.Close();
|
||||
} catch (Exception e) {
|
||||
Console.WriteLine(e.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class TcpServer {
|
||||
private int mPort = 11000;
|
||||
public TcpServer() {
|
||||
}
|
||||
public TcpServer(int port) {
|
||||
mPort = port;
|
||||
}
|
||||
public void start() {
|
||||
AsynchronousSocketListener.StartListening(mPort);
|
||||
}
|
||||
}
|
||||
public class TcpServer {
|
||||
private int mPort = 11000;
|
||||
public TcpServer() {
|
||||
}
|
||||
public TcpServer(int port) {
|
||||
mPort = port;
|
||||
}
|
||||
public void start() {
|
||||
AsynchronousSocketListener.StartListening(mPort);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,30 +1,29 @@
|
|||
/*
|
||||
* Copyright (c) Contributors, http://opensimulator.org/
|
||||
* See CONTRIBUTORS.TXT for a full list of copyright holders.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * Neither the name of the OpenSim Project nor the
|
||||
* names of its contributors may be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
/*
|
||||
* Copyright (c) Contributors, http://opensimulator.org/
|
||||
* See CONTRIBUTORS.TXT for a full list of copyright holders.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * Neither the name of the OpenSim Project nor the
|
||||
* names of its contributors may be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
|
@ -255,7 +254,7 @@ namespace OpenSim.ApplicationPlugins.RegionProxy
|
|||
public EndPoint clientEP;
|
||||
public EndPoint senderEP;
|
||||
public IPEndPoint serverIP;
|
||||
public byte[] recvBuffer = new byte[4096];
|
||||
public byte[] recvBuffer = new byte[4096];
|
||||
|
||||
public ServerData()
|
||||
{
|
||||
|
|
|
@ -84,12 +84,12 @@
|
|||
<Project name="OpenSim.Tests.Common" path="OpenSim/Tests/Common" type="Library">
|
||||
<Configuration name="Debug">
|
||||
<Options>
|
||||
<OutputPath>../../../bin/</OutputPath>
|
||||
<OutputPath>../../../bin/</OutputPath>
|
||||
</Options>
|
||||
</Configuration>
|
||||
<Configuration name="Release">
|
||||
<Options>
|
||||
<OutputPath>../../../bin/</OutputPath>
|
||||
<OutputPath>../../../bin/</OutputPath>
|
||||
</Options>
|
||||
</Configuration>
|
||||
|
||||
|
@ -107,12 +107,12 @@
|
|||
<Project name="OpenSim.Framework.Tests" path="OpenSim/Tests/OpenSim/Framework" type="Library">
|
||||
<Configuration name="Debug">
|
||||
<Options>
|
||||
<OutputPath>../../../../bin/</OutputPath>
|
||||
<OutputPath>../../../../bin/</OutputPath>
|
||||
</Options>
|
||||
</Configuration>
|
||||
<Configuration name="Release">
|
||||
<Options>
|
||||
<OutputPath>../../../../bin/</OutputPath>
|
||||
<OutputPath>../../../../bin/</OutputPath>
|
||||
</Options>
|
||||
</Configuration>
|
||||
|
||||
|
|
|
@ -42,6 +42,7 @@ def binary_or_text(file):
|
|||
|
||||
property_map = {
|
||||
".bat" : script,
|
||||
".cgi" : textfile,
|
||||
".config" : textfile,
|
||||
".cs" : textfile,
|
||||
".csproj" : textfile,
|
||||
|
@ -64,6 +65,7 @@ property_map = {
|
|||
".php" : script,
|
||||
".pidb" : binary,
|
||||
".pl" : script,
|
||||
".pm" : textfile,
|
||||
".png" : binary,
|
||||
".py" : script,
|
||||
".rb" : script,
|
||||
|
|
Loading…
Reference in New Issue