|
188 | 188 | $MaxIdlePause=.001; |
189 | 189 | $MinIdlePause=0.0001; |
190 | 190 | $PauseIncrement=0.0001; |
191 | | -$TaskSupportMinVersion = Infinity; |
| 191 | +$ListenerSupportMinVersion = 12.3; |
192 | 192 |
|
193 | 193 | Which[ |
194 | | - $VersionNumber < $TaskSupportMinVersion, |
| 194 | + $VersionNumber < $ListenerSupportMinVersion, |
195 | 195 | (* Low CPU wait but need synchronous loop. *) |
196 | 196 | evaluationLoop[socketIn_SocketObject]:= With[ |
197 | 197 | {maxPause=$MaxIdlePause, minPause=$MinIdlePause, incr=$PauseIncrement, poller={socketIn}}, |
|
208 | 208 | ] |
209 | 209 | ], |
210 | 210 | True, |
211 | | - (* Version with fixed asynchronous tasks *) |
| 211 | + evaluationLoop[socketIn_SocketObject]:= ( |
| 212 | + $SocketListener = SocketListen[ |
| 213 | + socketIn, |
| 214 | + socketEventHandler[#DataByteArray]& |
| 215 | + ]; |
| 216 | + SendAck[]; |
| 217 | + Pause[2^60]; |
| 218 | + ); |
| 219 | + (* |
| 220 | + Version with fixed asynchronous tasks |
212 | 221 | evaluationLoop[socketIn_SocketObject]:= With[ |
213 | 222 | {maxPause=$MaxIdlePause, minPause=$MinIdlePause, incr=$PauseIncrement, poller={socketIn}}, |
214 | 223 | $Task = SessionSubmit[ |
|
221 | 230 | SocketWaitNext[poller]; |
222 | 231 | ] |
223 | 232 | ), |
224 | | - 0.0001 (*negligeable compared to IO operations ~1ms. We basically need 0 but can't use this value. *) |
| 233 | + 0.0001 negligeable compared to IO operations ~1ms. We basically need 0 but can't use this value. |
225 | 234 | ], |
226 | 235 | Method->"Idle", |
227 | 236 | HandlerFunctions-><|"TaskStarted"->SendAck[]|> |
228 | 237 | ]; |
229 | 238 | ]; |
| 239 | + *) |
230 | 240 | ]; |
231 | 241 | (* can be useful for loopback connections which are available only if a task can be used. |
232 | 242 | Does not kill the kernel *) |
233 | 243 | ClientLibrary`disconnect[] := Quit[]; |
234 | | -ClientLibrary`disconnect[] /; ($Task =!= None) := ( |
235 | | - TaskRemove[$Task]; |
| 244 | +ClientLibrary`disconnect[] /; ($SocketListener =!= None) := ( |
| 245 | + DeleteObject[$SocketListener]; |
236 | 246 | Scan[ |
237 | 247 | If[# =!= None, Close[#]] &, |
238 | 248 | {$LoggerSocket, $OutputSocket, $InputSocket} |
239 | 249 | ] |
240 | 250 | ); |
241 | | -$Task = None; |
| 251 | +$SocketListener = None; |
242 | 252 | $LoggerSocket=None; |
243 | 253 | $OutputSocket=None; |
244 | 254 | $InputSocket=None; |
|
0 commit comments