Skip to content

Commit 478234f

Browse files
committed
added a new delegate class SessionHandler
1 parent 41aaa3f commit 478234f

File tree

10 files changed

+38
-10
lines changed

10 files changed

+38
-10
lines changed

QuickStart/Basic/TelnetServer/Program.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ static void Main(string[] args)
2929
return;
3030
}
3131

32-
appServer.NewSessionConnected += new Action<AppSession>(appServer_NewSessionConnected);
32+
appServer.NewSessionConnected += new SessionHandler<AppSession>(appServer_NewSessionConnected);
3333

3434
Console.WriteLine();
3535

QuickStart/Basic/TelnetServer_Command/Program.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ static void Main(string[] args)
3535
return;
3636
}
3737

38-
appServer.NewSessionConnected += new Action<AppSession>(appServer_NewSessionConnected);
38+
appServer.NewSessionConnected += new SessionHandler<AppSession>(appServer_NewSessionConnected);
3939

4040
Console.WriteLine();
4141

QuickStart/Basic/TelnetServer_ProcessRequest/Program.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ static void Main(string[] args)
2929
return;
3030
}
3131

32-
appServer.NewSessionConnected += new Action<AppSession>(appServer_NewSessionConnected);
32+
appServer.NewSessionConnected += new SessionHandler<AppSession>(appServer_NewSessionConnected);
3333
appServer.NewRequestReceived += new RequestHandler<AppSession, StringRequestInfo>(appServer_NewRequestReceived);
3434

3535
Console.WriteLine();

SocketBase/AppServerBase.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1191,12 +1191,12 @@ protected virtual bool RegisterSession(string sessionID, TAppSession appSession)
11911191
}
11921192

11931193

1194-
private Action<TAppSession> m_NewSessionConnected;
1194+
private SessionHandler<TAppSession> m_NewSessionConnected;
11951195

11961196
/// <summary>
11971197
/// The action which will be executed after a new session connect
11981198
/// </summary>
1199-
public event Action<TAppSession> NewSessionConnected
1199+
public event SessionHandler<TAppSession> NewSessionConnected
12001200
{
12011201
add { m_NewSessionConnected += value; }
12021202
remove { m_NewSessionConnected -= value; }
@@ -1254,11 +1254,11 @@ private void OnSocketSessionClosed(ISocketSession session, CloseReason reason)
12541254
OnSessionClosed(appSession, reason);
12551255
}
12561256

1257-
private Action<TAppSession, CloseReason> m_SessionClosed;
1257+
private SessionHandler<TAppSession, CloseReason> m_SessionClosed;
12581258
/// <summary>
12591259
/// Gets/sets the session closed event handler.
12601260
/// </summary>
1261-
public event Action<TAppSession, CloseReason> SessionClosed
1261+
public event SessionHandler<TAppSession, CloseReason> SessionClosed
12621262
{
12631263
add { m_SessionClosed += value; }
12641264
remove { m_SessionClosed -= value; }

SocketBase/IAppServer.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -193,12 +193,12 @@ public interface IAppServer<TAppSession> : IAppServer
193193
/// <summary>
194194
/// Gets/sets the new session connected event handler.
195195
/// </summary>
196-
event Action<TAppSession> NewSessionConnected;
196+
event SessionHandler<TAppSession> NewSessionConnected;
197197

198198
/// <summary>
199199
/// Gets/sets the session closed event handler.
200200
/// </summary>
201-
event Action<TAppSession, CloseReason> SessionClosed;
201+
event SessionHandler<TAppSession, CloseReason> SessionClosed;
202202
}
203203

204204
/// <summary>

SocketBase/SessionHandler.cs

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
6+
namespace SuperSocket.SocketBase
7+
{
8+
/// <summary>
9+
/// Used for session level event handler
10+
/// </summary>
11+
/// <typeparam name="TAppSession">the type of the target session</typeparam>
12+
/// <param name="session">the target session</param>
13+
public delegate void SessionHandler<TAppSession>(TAppSession session)
14+
where TAppSession : IAppSession;
15+
16+
/// <summary>
17+
/// Used for session level event handler
18+
/// </summary>
19+
/// <typeparam name="TAppSession">the type of the target session</typeparam>
20+
/// <typeparam name="TParam">the target session</typeparam>
21+
/// <param name="session">the target session</param>
22+
/// <param name="value">the event parameter</param>
23+
public delegate void SessionHandler<TAppSession, TParam>(TAppSession session, TParam value)
24+
where TAppSession : IAppSession;
25+
}

SocketBase/SuperSocket.SocketBase.Net35.csproj

+1
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@
132132
<Compile Include="RequestHandler.cs" />
133133
<Compile Include="Security\CertificateManager.cs" />
134134
<Compile Include="ServerState.cs" />
135+
<Compile Include="SessionHandler.cs" />
135136
<Compile Include="SocketMode.cs" />
136137
</ItemGroup>
137138
<ItemGroup>

SocketBase/SuperSocket.SocketBase.Net40.csproj

+1
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@
140140
<Compile Include="Protocol\IRequestInfoParser.cs" />
141141
<Compile Include="Security\CertificateManager.cs" />
142142
<Compile Include="ServerState.cs" />
143+
<Compile Include="SessionHandler.cs" />
143144
<Compile Include="SocketMode.cs" />
144145
<Compile Include="AppServer.cs" />
145146
<Compile Include="AppServerBase.cs" />

SocketBase/SuperSocket.SocketBase.Net45.csproj

+1
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@
144144
<Compile Include="Protocol\IRequestInfoParser.cs" />
145145
<Compile Include="Security\CertificateManager.cs" />
146146
<Compile Include="ServerState.cs" />
147+
<Compile Include="SessionHandler.cs" />
147148
<Compile Include="SocketMode.cs" />
148149
<Compile Include="AppServer.cs" />
149150
<Compile Include="AppServerBase.cs" />

Test/ConnectionFilterTest.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public void Setup()
3737
};
3838

3939
m_Server = new TestServer();
40-
m_Server.NewSessionConnected += new Action<TestSession>(m_Server_NewSessionConnected);
40+
m_Server.NewSessionConnected += new SessionHandler<TestSession>(m_Server_NewSessionConnected);
4141
m_Server.Setup(new RootConfig(), m_ServerConfig, null, null, new ConsoleLogFactory(), new IConnectionFilter[] { new TestConnectionFilter() }, null);
4242
}
4343

0 commit comments

Comments
 (0)