@@ -93,112 +93,6 @@ private static uint toNetworkByteOrder(uint port)
93
93
return ( ( port >> 8 ) & 0x00FF00FFu ) | ( ( port << 8 ) & 0xFF00FF00u ) ;
94
94
}
95
95
96
- /// <summary>
97
- /// relays the input clientStream to the server at the specified host name and port with the given httpCmd and headers
98
- /// as prefix
99
- /// Usefull for websocket requests
100
- /// Asynchronous Programming Model, which does not throw exceptions when the socket is closed
101
- /// </summary>
102
- /// <param name="clientStream"></param>
103
- /// <param name="serverStream"></param>
104
- /// <param name="bufferSize"></param>
105
- /// <param name="onDataSend"></param>
106
- /// <param name="onDataReceive"></param>
107
- /// <param name="cancellationTokenSource"></param>
108
- /// <param name="exceptionFunc"></param>
109
- /// <returns></returns>
110
- internal static async Task SendRawApm ( Stream clientStream , Stream serverStream ,
111
- IBufferPool bufferPool , int bufferSize ,
112
- Action < byte [ ] , int , int > onDataSend , Action < byte [ ] , int , int > onDataReceive ,
113
- CancellationTokenSource cancellationTokenSource ,
114
- ExceptionHandler exceptionFunc )
115
- {
116
- var taskCompletionSource = new TaskCompletionSource < bool > ( ) ;
117
- cancellationTokenSource . Token . Register ( ( ) => taskCompletionSource . TrySetResult ( true ) ) ;
118
-
119
- // Now async relay all server=>client & client=>server data
120
- var clientBuffer = bufferPool . GetBuffer ( bufferSize ) ;
121
- var serverBuffer = bufferPool . GetBuffer ( bufferSize ) ;
122
- try
123
- {
124
- beginRead ( clientStream , serverStream , clientBuffer , onDataSend , cancellationTokenSource , exceptionFunc ) ;
125
- beginRead ( serverStream , clientStream , serverBuffer , onDataReceive , cancellationTokenSource ,
126
- exceptionFunc ) ;
127
- await taskCompletionSource . Task ;
128
- }
129
- finally
130
- {
131
- bufferPool . ReturnBuffer ( clientBuffer ) ;
132
- bufferPool . ReturnBuffer ( serverBuffer ) ;
133
- }
134
- }
135
-
136
- private static void beginRead ( Stream inputStream , Stream outputStream , byte [ ] buffer ,
137
- Action < byte [ ] , int , int > onCopy , CancellationTokenSource cancellationTokenSource ,
138
- ExceptionHandler exceptionFunc )
139
- {
140
- if ( cancellationTokenSource . IsCancellationRequested )
141
- {
142
- return ;
143
- }
144
-
145
- bool readFlag = false ;
146
- var readCallback = ( AsyncCallback ) ( ar =>
147
- {
148
- if ( cancellationTokenSource . IsCancellationRequested || readFlag )
149
- {
150
- return ;
151
- }
152
-
153
- readFlag = true ;
154
-
155
- try
156
- {
157
- int read = inputStream . EndRead ( ar ) ;
158
- if ( read <= 0 )
159
- {
160
- cancellationTokenSource . Cancel ( ) ;
161
- return ;
162
- }
163
-
164
- onCopy ? . Invoke ( buffer , 0 , read ) ;
165
-
166
- var writeCallback = ( AsyncCallback ) ( ar2 =>
167
- {
168
- if ( cancellationTokenSource . IsCancellationRequested )
169
- {
170
- return ;
171
- }
172
-
173
- try
174
- {
175
- outputStream . EndWrite ( ar2 ) ;
176
- beginRead ( inputStream , outputStream , buffer , onCopy , cancellationTokenSource ,
177
- exceptionFunc ) ;
178
- }
179
- catch ( IOException ex )
180
- {
181
- cancellationTokenSource . Cancel ( ) ;
182
- exceptionFunc ( ex ) ;
183
- }
184
- } ) ;
185
-
186
- outputStream . BeginWrite ( buffer , 0 , read , writeCallback , null ) ;
187
- }
188
- catch ( IOException ex )
189
- {
190
- cancellationTokenSource . Cancel ( ) ;
191
- exceptionFunc ( ex ) ;
192
- }
193
- } ) ;
194
-
195
- var readResult = inputStream . BeginRead ( buffer , 0 , buffer . Length , readCallback , null ) ;
196
- if ( readResult . CompletedSynchronously )
197
- {
198
- readCallback ( readResult ) ;
199
- }
200
- }
201
-
202
96
/// <summary>
203
97
/// relays the input clientStream to the server at the specified host name and port with the given httpCmd and headers
204
98
/// as prefix
0 commit comments