@@ -16,7 +16,7 @@ public class ZmqIpcServer : IDisposable
16
16
private NetMQPoller ? poller ;
17
17
private ResponseSocket ? responseSocket ;
18
18
19
- private Dictionary < int , Tuple < string , RequestSocket > > clients = new Dictionary < int , Tuple < string , RequestSocket > > ( ) ;
19
+ private Dictionary < int , ProfilerClient > pidToClient = new Dictionary < int , ProfilerClient > ( ) ;
20
20
21
21
private static readonly Logger logger = LogManager . GetCurrentClassLogger ( ) ;
22
22
@@ -58,24 +58,24 @@ protected void StartRequestHandler()
58
58
poller . RunAsync ( "Profiler IPC" , true ) ;
59
59
}
60
60
61
- private void RegisterClient ( string message )
61
+ private void RegisterClient ( string message )
62
62
{
63
63
int pid = Int32 . Parse ( message . Split ( ':' ) [ 1 ] ) ;
64
- lock ( clients )
64
+ lock ( pidToClient )
65
65
{
66
66
string clientAddress ;
67
- if ( clients . ContainsKey ( pid ) )
67
+ if ( pidToClient . ContainsKey ( pid ) )
68
68
{
69
- clientAddress = clients [ pid ] . Item1 ;
69
+ clientAddress = pidToClient [ pid ] . ClientAddress ;
70
70
responseSocket . SendFrame ( clientAddress ) ;
71
71
return ;
72
72
}
73
- portOffset ++ ;
74
73
RequestSocket clientRequestSocket = new RequestSocket ( ) ;
75
74
clientAddress = config . RequestSocket + ":" + ( ( config . StartPortNumber + portOffset ) % 65535 ) ;
75
+ portOffset ++ ;
76
76
clientRequestSocket . Connect ( clientAddress ) ;
77
77
78
- clients . Add ( pid , Tuple . Create ( clientAddress , clientRequestSocket ) ) ;
78
+ pidToClient . Add ( pid , new ProfilerClient ( clientAddress , clientRequestSocket ) ) ;
79
79
responseSocket . SendFrame ( clientAddress ) ;
80
80
logger . Info ( $ "Registered profiler on address { clientAddress } ") ;
81
81
}
@@ -84,34 +84,33 @@ private void RegisterClient(string message)
84
84
/// <summary>
85
85
/// Sends the given test event to all connected profiler instances.
86
86
/// </summary>
87
- /// <param name="testEvent"></param>
88
87
public void SendTestEvent ( string testEvent )
89
88
{
90
89
HashSet < int > clientsToRemove = new HashSet < int > ( ) ;
91
- System . Threading . Tasks . Parallel . ForEach ( clients , entry =>
90
+ System . Threading . Tasks . Parallel . ForEach ( pidToClient , entry =>
92
91
{
93
- entry . Value . Item2 . SendFrame ( Encoding . UTF8 . GetBytes ( testEvent ) ) ;
94
- if ( entry . Value . Item2 . TryReceiveFrameString ( TimeSpan . FromSeconds ( 3.0 ) , out string ? response ) )
92
+ entry . Value . Socket . SendFrame ( Encoding . UTF8 . GetBytes ( testEvent ) ) ;
93
+ if ( entry . Value . Socket . TryReceiveFrameString ( TimeSpan . FromSeconds ( 3.0 ) , out string ? response ) )
95
94
{
96
- logger . Info ( $ "Got Response from { entry . Value . Item1 } : { response } ") ;
95
+ logger . Info ( $ "Got Response from { entry . Value . ClientAddress } : { response } ") ;
97
96
} else
98
97
{
99
98
lock ( clientsToRemove )
100
99
{
101
100
clientsToRemove . Add ( entry . Key ) ;
102
101
}
103
- logger . Error ( $ "Got no response from Profiler with Socket { entry . Key } ") ;
102
+ logger . Error ( $ "Got no response from Profiler with PID { entry . Key } with address { entry . Value . ClientAddress } , removing from clients ") ;
104
103
}
105
104
} ) ;
106
- lock ( clients )
105
+ lock ( pidToClient )
107
106
{
108
107
foreach ( var client in clientsToRemove )
109
108
{
110
- if ( ! clients . ContainsKey ( client ) ) {
109
+ if ( ! pidToClient . ContainsKey ( client ) ) {
111
110
continue ;
112
111
}
113
- clients [ client ] . Item2 . Close ( ) ;
114
- clients . Remove ( client ) ;
112
+ pidToClient [ client ] . Socket . Close ( ) ;
113
+ pidToClient . Remove ( client ) ;
115
114
}
116
115
}
117
116
}
@@ -120,9 +119,9 @@ public void Dispose()
120
119
{
121
120
this . poller ? . Dispose ( ) ;
122
121
this . responseSocket ? . Dispose ( ) ;
123
- foreach ( var client in clients )
122
+ foreach ( var client in pidToClient )
124
123
{
125
- client . Value . Item2 . Dispose ( ) ;
124
+ client . Value . Socket . Dispose ( ) ;
126
125
}
127
126
NetMQConfig . Cleanup ( false ) ;
128
127
}
0 commit comments