aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/ScriptEngine/Common/TRPC/TCPSocket.cs
diff options
context:
space:
mode:
authorJeff Ames2008-01-12 01:35:25 +0000
committerJeff Ames2008-01-12 01:35:25 +0000
commit5d7e120d56873d91141695ddf7aebd88e4619dce (patch)
tree79e5ae7fcb518dfc726e447a029744b05204001c /OpenSim/Region/ScriptEngine/Common/TRPC/TCPSocket.cs
parentAnd one last time - removed duplicate exception dump :) (diff)
downloadopensim-SC-5d7e120d56873d91141695ddf7aebd88e4619dce.zip
opensim-SC-5d7e120d56873d91141695ddf7aebd88e4619dce.tar.gz
opensim-SC-5d7e120d56873d91141695ddf7aebd88e4619dce.tar.bz2
opensim-SC-5d7e120d56873d91141695ddf7aebd88e4619dce.tar.xz
Set svn:eol-style.
Diffstat (limited to 'OpenSim/Region/ScriptEngine/Common/TRPC/TCPSocket.cs')
-rw-r--r--OpenSim/Region/ScriptEngine/Common/TRPC/TCPSocket.cs170
1 files changed, 85 insertions, 85 deletions
diff --git a/OpenSim/Region/ScriptEngine/Common/TRPC/TCPSocket.cs b/OpenSim/Region/ScriptEngine/Common/TRPC/TCPSocket.cs
index 1079846..ce50a27 100644
--- a/OpenSim/Region/ScriptEngine/Common/TRPC/TCPSocket.cs
+++ b/OpenSim/Region/ScriptEngine/Common/TRPC/TCPSocket.cs
@@ -1,86 +1,86 @@
1using System; 1using System;
2using System.Net.Sockets; 2using System.Net.Sockets;
3 3
4namespace OpenSim.Region.ScriptEngine.Common.TRPC 4namespace OpenSim.Region.ScriptEngine.Common.TRPC
5{ 5{
6 public class TCPSocket 6 public class TCPSocket
7 { 7 {
8 8
9 public readonly Socket Client; 9 public readonly Socket Client;
10 public readonly int ID; 10 public readonly int ID;
11 11
12 public delegate void DataReceivedDelegate(int ID, byte[] data, int offset, int length); 12 public delegate void DataReceivedDelegate(int ID, byte[] data, int offset, int length);
13 public delegate void DataSentDelegate(int ID, int length); 13 public delegate void DataSentDelegate(int ID, int length);
14 public delegate void CloseDelegate(int ID); 14 public delegate void CloseDelegate(int ID);
15 public event DataReceivedDelegate DataReceived; 15 public event DataReceivedDelegate DataReceived;
16 public event DataSentDelegate DataSent; 16 public event DataSentDelegate DataSent;
17 public event CloseDelegate Close; 17 public event CloseDelegate Close;
18 18
19 private byte[] RecvQueue = new byte[4096]; 19 private byte[] RecvQueue = new byte[4096];
20 private int RecvQueueSize = 4096; 20 private int RecvQueueSize = 4096;
21 21
22 public TCPSocket(int id, Socket client) 22 public TCPSocket(int id, Socket client)
23 { 23 {
24 ID = id; 24 ID = id;
25 Client = client; 25 Client = client;
26 } 26 }
27 public void Start() 27 public void Start()
28 { 28 {
29 // Start listening 29 // Start listening
30 BeginReceive(); 30 BeginReceive();
31 } 31 }
32 32
33 private void BeginReceive() 33 private void BeginReceive()
34 { 34 {
35 Client.BeginReceive(RecvQueue, 0, RecvQueueSize, SocketFlags.None, new AsyncCallback(asyncDataReceived), Client); 35 Client.BeginReceive(RecvQueue, 0, RecvQueueSize, SocketFlags.None, new AsyncCallback(asyncDataReceived), Client);
36 } 36 }
37 37
38 /// <summary> 38 /// <summary>
39 /// Callback for successful receive (or connection close) 39 /// Callback for successful receive (or connection close)
40 /// </summary> 40 /// </summary>
41 /// <param name="ar"></param> 41 /// <param name="ar"></param>
42 private void asyncDataReceived(IAsyncResult ar) 42 private void asyncDataReceived(IAsyncResult ar)
43 { 43 {
44 Socket client = (Socket)ar.AsyncState; 44 Socket client = (Socket)ar.AsyncState;
45 int recv = client.EndReceive(ar); 45 int recv = client.EndReceive(ar);
46 46
47 // Is connection closed? 47 // Is connection closed?
48 if (recv == 0) 48 if (recv == 0)
49 { 49 {
50 client.Close(); 50 client.Close();
51 Close(ID); 51 Close(ID);
52 return; 52 return;
53 } 53 }
54 54
55 // Call receive event 55 // Call receive event
56 DataReceived(ID, RecvQueue, 0, recv); 56 DataReceived(ID, RecvQueue, 0, recv);
57 57
58 // Start new receive 58 // Start new receive
59 BeginReceive(); 59 BeginReceive();
60 60
61 } 61 }
62 62
63 63
64 public void Send(int clientID, byte[] data, int offset, int len) 64 public void Send(int clientID, byte[] data, int offset, int len)
65 { 65 {
66 Client.BeginSend(data, offset, len, SocketFlags.None, new AsyncCallback(asyncDataSent), Client); 66 Client.BeginSend(data, offset, len, SocketFlags.None, new AsyncCallback(asyncDataSent), Client);
67 } 67 }
68 68
69 /// <summary> 69 /// <summary>
70 /// Callback for successful send 70 /// Callback for successful send
71 /// </summary> 71 /// </summary>
72 /// <param name="ar"></param> 72 /// <param name="ar"></param>
73 void asyncDataSent(IAsyncResult ar) 73 void asyncDataSent(IAsyncResult ar)
74 { 74 {
75 Socket client = (Socket)ar.AsyncState; 75 Socket client = (Socket)ar.AsyncState;
76 int sent = client.EndSend(ar); 76 int sent = client.EndSend(ar);
77 DataSent(ID, sent); 77 DataSent(ID, sent);
78 } 78 }
79 79
80 public void Disconnect() 80 public void Disconnect()
81 { 81 {
82 Client.Close(); 82 Client.Close();
83 Close(ID); 83 Close(ID);
84 } 84 }
85 } 85 }
86} \ No newline at end of file 86} \ No newline at end of file