@@ -87,6 +87,7 @@ func (s *ArduinoCoreServerImpl) BoardSearch(ctx context.Context, req *rpc.BoardS
87
87
88
88
// BoardListWatch FIXMEDOC
89
89
func (s * ArduinoCoreServerImpl ) BoardListWatch (stream rpc.ArduinoCoreService_BoardListWatchServer ) error {
90
+ syncSend := NewSynchronizedSend (stream .Send )
90
91
msg , err := stream .Recv ()
91
92
if err == io .EOF {
92
93
return nil
@@ -97,7 +98,7 @@ func (s *ArduinoCoreServerImpl) BoardListWatch(stream rpc.ArduinoCoreService_Boa
97
98
98
99
if msg .Instance == nil {
99
100
err = fmt .Errorf (tr ("no instance specified" ))
100
- stream .Send (& rpc.BoardListWatchResponse {
101
+ syncSend .Send (& rpc.BoardListWatchResponse {
101
102
EventType : "error" ,
102
103
Error : err .Error (),
103
104
})
@@ -132,7 +133,7 @@ func (s *ArduinoCoreServerImpl) BoardListWatch(stream rpc.ArduinoCoreService_Boa
132
133
}()
133
134
134
135
for event := range eventsChan {
135
- if err := stream .Send (event ); err != nil {
136
+ if err := syncSend .Send (event ); err != nil {
136
137
logrus .Infof ("sending board watch message: %v" , err )
137
138
}
138
139
}
@@ -148,16 +149,18 @@ func (s *ArduinoCoreServerImpl) Destroy(ctx context.Context, req *rpc.DestroyReq
148
149
149
150
// UpdateIndex FIXMEDOC
150
151
func (s * ArduinoCoreServerImpl ) UpdateIndex (req * rpc.UpdateIndexRequest , stream rpc.ArduinoCoreService_UpdateIndexServer ) error {
152
+ syncSend := NewSynchronizedSend (stream .Send )
151
153
err := commands .UpdateIndex (stream .Context (), req ,
152
- func (p * rpc.DownloadProgress ) { stream .Send (& rpc.UpdateIndexResponse {DownloadProgress : p }) },
154
+ func (p * rpc.DownloadProgress ) { syncSend .Send (& rpc.UpdateIndexResponse {DownloadProgress : p }) },
153
155
)
154
156
return convertErrorToRPCStatus (err )
155
157
}
156
158
157
159
// UpdateLibrariesIndex FIXMEDOC
158
160
func (s * ArduinoCoreServerImpl ) UpdateLibrariesIndex (req * rpc.UpdateLibrariesIndexRequest , stream rpc.ArduinoCoreService_UpdateLibrariesIndexServer ) error {
161
+ syncSend := NewSynchronizedSend (stream .Send )
159
162
err := commands .UpdateLibrariesIndex (stream .Context (), req ,
160
- func (p * rpc.DownloadProgress ) { stream .Send (& rpc.UpdateLibrariesIndexResponse {DownloadProgress : p }) },
163
+ func (p * rpc.DownloadProgress ) { syncSend .Send (& rpc.UpdateLibrariesIndexResponse {DownloadProgress : p }) },
161
164
)
162
165
return convertErrorToRPCStatus (err )
163
166
}
@@ -177,9 +180,8 @@ func (s *ArduinoCoreServerImpl) Create(ctx context.Context, req *rpc.CreateReque
177
180
178
181
// Init FIXMEDOC
179
182
func (s * ArduinoCoreServerImpl ) Init (req * rpc.InitRequest , stream rpc.ArduinoCoreService_InitServer ) error {
180
- err := commands .Init (req , func (message * rpc.InitResponse ) {
181
- stream .Send (message )
182
- })
183
+ syncSend := NewSynchronizedSend (stream .Send )
184
+ err := commands .Init (req , func (message * rpc.InitResponse ) { syncSend .Send (message ) })
183
185
return convertErrorToRPCStatus (err )
184
186
}
185
187
@@ -202,16 +204,17 @@ func (s *ArduinoCoreServerImpl) LoadSketch(ctx context.Context, req *rpc.LoadSke
202
204
203
205
// Compile FIXMEDOC
204
206
func (s * ArduinoCoreServerImpl ) Compile (req * rpc.CompileRequest , stream rpc.ArduinoCoreService_CompileServer ) error {
205
- outStream := feedStreamTo (func (data []byte ) { stream .Send (& rpc.CompileResponse {OutStream : data }) })
206
- errStream := feedStreamTo (func (data []byte ) { stream .Send (& rpc.CompileResponse {ErrStream : data }) })
207
+ syncSend := NewSynchronizedSend (stream .Send )
208
+ outStream := feedStreamTo (func (data []byte ) { syncSend .Send (& rpc.CompileResponse {OutStream : data }) })
209
+ errStream := feedStreamTo (func (data []byte ) { syncSend .Send (& rpc.CompileResponse {ErrStream : data }) })
207
210
compileResp , compileErr := compile .Compile (
208
211
stream .Context (), req , outStream , errStream ,
209
- func (p * rpc.TaskProgress ) { stream .Send (& rpc.CompileResponse {Progress : p }) })
212
+ func (p * rpc.TaskProgress ) { syncSend .Send (& rpc.CompileResponse {Progress : p }) })
210
213
outStream .Close ()
211
214
errStream .Close ()
212
215
var compileRespSendErr error
213
216
if compileResp != nil {
214
- compileRespSendErr = stream .Send (compileResp )
217
+ compileRespSendErr = syncSend .Send (compileResp )
215
218
}
216
219
if compileErr != nil {
217
220
return convertErrorToRPCStatus (compileErr )
@@ -221,52 +224,56 @@ func (s *ArduinoCoreServerImpl) Compile(req *rpc.CompileRequest, stream rpc.Ardu
221
224
222
225
// PlatformInstall FIXMEDOC
223
226
func (s * ArduinoCoreServerImpl ) PlatformInstall (req * rpc.PlatformInstallRequest , stream rpc.ArduinoCoreService_PlatformInstallServer ) error {
227
+ syncSend := NewSynchronizedSend (stream .Send )
224
228
resp , err := core .PlatformInstall (
225
229
stream .Context (), req ,
226
- func (p * rpc.DownloadProgress ) { stream .Send (& rpc.PlatformInstallResponse {Progress : p }) },
227
- func (p * rpc.TaskProgress ) { stream .Send (& rpc.PlatformInstallResponse {TaskProgress : p }) },
230
+ func (p * rpc.DownloadProgress ) { syncSend .Send (& rpc.PlatformInstallResponse {Progress : p }) },
231
+ func (p * rpc.TaskProgress ) { syncSend .Send (& rpc.PlatformInstallResponse {TaskProgress : p }) },
228
232
)
229
233
if err != nil {
230
234
return convertErrorToRPCStatus (err )
231
235
}
232
- return stream .Send (resp )
236
+ return syncSend .Send (resp )
233
237
}
234
238
235
239
// PlatformDownload FIXMEDOC
236
240
func (s * ArduinoCoreServerImpl ) PlatformDownload (req * rpc.PlatformDownloadRequest , stream rpc.ArduinoCoreService_PlatformDownloadServer ) error {
241
+ syncSend := NewSynchronizedSend (stream .Send )
237
242
resp , err := core .PlatformDownload (
238
243
stream .Context (), req ,
239
- func (p * rpc.DownloadProgress ) { stream .Send (& rpc.PlatformDownloadResponse {Progress : p }) },
244
+ func (p * rpc.DownloadProgress ) { syncSend .Send (& rpc.PlatformDownloadResponse {Progress : p }) },
240
245
)
241
246
if err != nil {
242
247
return convertErrorToRPCStatus (err )
243
248
}
244
- return stream .Send (resp )
249
+ return syncSend .Send (resp )
245
250
}
246
251
247
252
// PlatformUninstall FIXMEDOC
248
253
func (s * ArduinoCoreServerImpl ) PlatformUninstall (req * rpc.PlatformUninstallRequest , stream rpc.ArduinoCoreService_PlatformUninstallServer ) error {
254
+ syncSend := NewSynchronizedSend (stream .Send )
249
255
resp , err := core .PlatformUninstall (
250
256
stream .Context (), req ,
251
- func (p * rpc.TaskProgress ) { stream .Send (& rpc.PlatformUninstallResponse {TaskProgress : p }) },
257
+ func (p * rpc.TaskProgress ) { syncSend .Send (& rpc.PlatformUninstallResponse {TaskProgress : p }) },
252
258
)
253
259
if err != nil {
254
260
return convertErrorToRPCStatus (err )
255
261
}
256
- return stream .Send (resp )
262
+ return syncSend .Send (resp )
257
263
}
258
264
259
265
// PlatformUpgrade FIXMEDOC
260
266
func (s * ArduinoCoreServerImpl ) PlatformUpgrade (req * rpc.PlatformUpgradeRequest , stream rpc.ArduinoCoreService_PlatformUpgradeServer ) error {
267
+ syncSend := NewSynchronizedSend (stream .Send )
261
268
resp , err := core .PlatformUpgrade (
262
269
stream .Context (), req ,
263
- func (p * rpc.DownloadProgress ) { stream .Send (& rpc.PlatformUpgradeResponse {Progress : p }) },
264
- func (p * rpc.TaskProgress ) { stream .Send (& rpc.PlatformUpgradeResponse {TaskProgress : p }) },
270
+ func (p * rpc.DownloadProgress ) { syncSend .Send (& rpc.PlatformUpgradeResponse {Progress : p }) },
271
+ func (p * rpc.TaskProgress ) { syncSend .Send (& rpc.PlatformUpgradeResponse {TaskProgress : p }) },
265
272
)
266
273
if err != nil {
267
274
return convertErrorToRPCStatus (err )
268
275
}
269
- return stream .Send (resp )
276
+ return syncSend .Send (resp )
270
277
}
271
278
272
279
// PlatformSearch FIXMEDOC
@@ -286,8 +293,9 @@ func (s *ArduinoCoreServerImpl) PlatformList(ctx context.Context, req *rpc.Platf
286
293
287
294
// Upload FIXMEDOC
288
295
func (s * ArduinoCoreServerImpl ) Upload (req * rpc.UploadRequest , stream rpc.ArduinoCoreService_UploadServer ) error {
289
- outStream := feedStreamTo (func (data []byte ) { stream .Send (& rpc.UploadResponse {OutStream : data }) })
290
- errStream := feedStreamTo (func (data []byte ) { stream .Send (& rpc.UploadResponse {ErrStream : data }) })
296
+ syncSend := NewSynchronizedSend (stream .Send )
297
+ outStream := feedStreamTo (func (data []byte ) { syncSend .Send (& rpc.UploadResponse {OutStream : data }) })
298
+ errStream := feedStreamTo (func (data []byte ) { syncSend .Send (& rpc.UploadResponse {ErrStream : data }) })
291
299
err := upload .Upload (stream .Context (), req , outStream , errStream )
292
300
outStream .Close ()
293
301
errStream .Close ()
@@ -299,8 +307,9 @@ func (s *ArduinoCoreServerImpl) Upload(req *rpc.UploadRequest, stream rpc.Arduin
299
307
300
308
// UploadUsingProgrammer FIXMEDOC
301
309
func (s * ArduinoCoreServerImpl ) UploadUsingProgrammer (req * rpc.UploadUsingProgrammerRequest , stream rpc.ArduinoCoreService_UploadUsingProgrammerServer ) error {
302
- outStream := feedStreamTo (func (data []byte ) { stream .Send (& rpc.UploadUsingProgrammerResponse {OutStream : data }) })
303
- errStream := feedStreamTo (func (data []byte ) { stream .Send (& rpc.UploadUsingProgrammerResponse {ErrStream : data }) })
310
+ syncSend := NewSynchronizedSend (stream .Send )
311
+ outStream := feedStreamTo (func (data []byte ) { syncSend .Send (& rpc.UploadUsingProgrammerResponse {OutStream : data }) })
312
+ errStream := feedStreamTo (func (data []byte ) { syncSend .Send (& rpc.UploadUsingProgrammerResponse {ErrStream : data }) })
304
313
err := upload .UsingProgrammer (stream .Context (), req , outStream , errStream )
305
314
outStream .Close ()
306
315
errStream .Close ()
@@ -318,15 +327,16 @@ func (s *ArduinoCoreServerImpl) SupportedUserFields(ctx context.Context, req *rp
318
327
319
328
// BurnBootloader FIXMEDOC
320
329
func (s * ArduinoCoreServerImpl ) BurnBootloader (req * rpc.BurnBootloaderRequest , stream rpc.ArduinoCoreService_BurnBootloaderServer ) error {
321
- outStream := feedStreamTo (func (data []byte ) { stream .Send (& rpc.BurnBootloaderResponse {OutStream : data }) })
322
- errStream := feedStreamTo (func (data []byte ) { stream .Send (& rpc.BurnBootloaderResponse {ErrStream : data }) })
330
+ syncSend := NewSynchronizedSend (stream .Send )
331
+ outStream := feedStreamTo (func (data []byte ) { syncSend .Send (& rpc.BurnBootloaderResponse {OutStream : data }) })
332
+ errStream := feedStreamTo (func (data []byte ) { syncSend .Send (& rpc.BurnBootloaderResponse {ErrStream : data }) })
323
333
resp , err := upload .BurnBootloader (stream .Context (), req , outStream , errStream )
324
334
outStream .Close ()
325
335
errStream .Close ()
326
336
if err != nil {
327
337
return convertErrorToRPCStatus (err )
328
338
}
329
- return stream .Send (resp )
339
+ return syncSend .Send (resp )
330
340
}
331
341
332
342
// ListProgrammersAvailableForUpload FIXMEDOC
@@ -337,49 +347,54 @@ func (s *ArduinoCoreServerImpl) ListProgrammersAvailableForUpload(ctx context.Co
337
347
338
348
// LibraryDownload FIXMEDOC
339
349
func (s * ArduinoCoreServerImpl ) LibraryDownload (req * rpc.LibraryDownloadRequest , stream rpc.ArduinoCoreService_LibraryDownloadServer ) error {
350
+ syncSend := NewSynchronizedSend (stream .Send )
340
351
resp , err := lib .LibraryDownload (
341
352
stream .Context (), req ,
342
- func (p * rpc.DownloadProgress ) { stream .Send (& rpc.LibraryDownloadResponse {Progress : p }) },
353
+ func (p * rpc.DownloadProgress ) { syncSend .Send (& rpc.LibraryDownloadResponse {Progress : p }) },
343
354
)
344
355
if err != nil {
345
356
return convertErrorToRPCStatus (err )
346
357
}
347
- return stream .Send (resp )
358
+ return syncSend .Send (resp )
348
359
}
349
360
350
361
// LibraryInstall FIXMEDOC
351
362
func (s * ArduinoCoreServerImpl ) LibraryInstall (req * rpc.LibraryInstallRequest , stream rpc.ArduinoCoreService_LibraryInstallServer ) error {
363
+ syncSend := NewSynchronizedSend (stream .Send )
352
364
err := lib .LibraryInstall (
353
365
stream .Context (), req ,
354
- func (p * rpc.DownloadProgress ) { stream .Send (& rpc.LibraryInstallResponse {Progress : p }) },
355
- func (p * rpc.TaskProgress ) { stream .Send (& rpc.LibraryInstallResponse {TaskProgress : p }) },
366
+ func (p * rpc.DownloadProgress ) { syncSend .Send (& rpc.LibraryInstallResponse {Progress : p }) },
367
+ func (p * rpc.TaskProgress ) { syncSend .Send (& rpc.LibraryInstallResponse {TaskProgress : p }) },
356
368
)
357
369
return convertErrorToRPCStatus (err )
358
370
}
359
371
360
372
// LibraryUpgrade FIXMEDOC
361
373
func (s * ArduinoCoreServerImpl ) LibraryUpgrade (req * rpc.LibraryUpgradeRequest , stream rpc.ArduinoCoreService_LibraryUpgradeServer ) error {
374
+ syncSend := NewSynchronizedSend (stream .Send )
362
375
err := lib .LibraryUpgrade (
363
376
stream .Context (), req ,
364
- func (p * rpc.DownloadProgress ) { stream .Send (& rpc.LibraryUpgradeResponse {Progress : p }) },
365
- func (p * rpc.TaskProgress ) { stream .Send (& rpc.LibraryUpgradeResponse {TaskProgress : p }) },
377
+ func (p * rpc.DownloadProgress ) { syncSend .Send (& rpc.LibraryUpgradeResponse {Progress : p }) },
378
+ func (p * rpc.TaskProgress ) { syncSend .Send (& rpc.LibraryUpgradeResponse {TaskProgress : p }) },
366
379
)
367
380
return convertErrorToRPCStatus (err )
368
381
}
369
382
370
383
// LibraryUninstall FIXMEDOC
371
384
func (s * ArduinoCoreServerImpl ) LibraryUninstall (req * rpc.LibraryUninstallRequest , stream rpc.ArduinoCoreService_LibraryUninstallServer ) error {
385
+ syncSend := NewSynchronizedSend (stream .Send )
372
386
err := lib .LibraryUninstall (stream .Context (), req ,
373
- func (p * rpc.TaskProgress ) { stream .Send (& rpc.LibraryUninstallResponse {TaskProgress : p }) },
387
+ func (p * rpc.TaskProgress ) { syncSend .Send (& rpc.LibraryUninstallResponse {TaskProgress : p }) },
374
388
)
375
389
return convertErrorToRPCStatus (err )
376
390
}
377
391
378
392
// LibraryUpgradeAll FIXMEDOC
379
393
func (s * ArduinoCoreServerImpl ) LibraryUpgradeAll (req * rpc.LibraryUpgradeAllRequest , stream rpc.ArduinoCoreService_LibraryUpgradeAllServer ) error {
394
+ syncSend := NewSynchronizedSend (stream .Send )
380
395
err := lib .LibraryUpgradeAll (req ,
381
- func (p * rpc.DownloadProgress ) { stream .Send (& rpc.LibraryUpgradeAllResponse {Progress : p }) },
382
- func (p * rpc.TaskProgress ) { stream .Send (& rpc.LibraryUpgradeAllResponse {TaskProgress : p }) },
396
+ func (p * rpc.DownloadProgress ) { syncSend .Send (& rpc.LibraryUpgradeAllResponse {Progress : p }) },
397
+ func (p * rpc.TaskProgress ) { syncSend .Send (& rpc.LibraryUpgradeAllResponse {TaskProgress : p }) },
383
398
)
384
399
return convertErrorToRPCStatus (err )
385
400
}
@@ -410,18 +425,20 @@ func (s *ArduinoCoreServerImpl) ArchiveSketch(ctx context.Context, req *rpc.Arch
410
425
411
426
// ZipLibraryInstall FIXMEDOC
412
427
func (s * ArduinoCoreServerImpl ) ZipLibraryInstall (req * rpc.ZipLibraryInstallRequest , stream rpc.ArduinoCoreService_ZipLibraryInstallServer ) error {
428
+ syncSend := NewSynchronizedSend (stream .Send )
413
429
err := lib .ZipLibraryInstall (
414
430
stream .Context (), req ,
415
- func (p * rpc.TaskProgress ) { stream .Send (& rpc.ZipLibraryInstallResponse {TaskProgress : p }) },
431
+ func (p * rpc.TaskProgress ) { syncSend .Send (& rpc.ZipLibraryInstallResponse {TaskProgress : p }) },
416
432
)
417
433
return convertErrorToRPCStatus (err )
418
434
}
419
435
420
436
// GitLibraryInstall FIXMEDOC
421
437
func (s * ArduinoCoreServerImpl ) GitLibraryInstall (req * rpc.GitLibraryInstallRequest , stream rpc.ArduinoCoreService_GitLibraryInstallServer ) error {
438
+ syncSend := NewSynchronizedSend (stream .Send )
422
439
err := lib .GitLibraryInstall (
423
440
stream .Context (), req ,
424
- func (p * rpc.TaskProgress ) { stream .Send (& rpc.GitLibraryInstallResponse {TaskProgress : p }) },
441
+ func (p * rpc.TaskProgress ) { syncSend .Send (& rpc.GitLibraryInstallResponse {TaskProgress : p }) },
425
442
)
426
443
return convertErrorToRPCStatus (err )
427
444
}
@@ -434,6 +451,8 @@ func (s *ArduinoCoreServerImpl) EnumerateMonitorPortSettings(ctx context.Context
434
451
435
452
// Monitor FIXMEDOC
436
453
func (s * ArduinoCoreServerImpl ) Monitor (stream rpc.ArduinoCoreService_MonitorServer ) error {
454
+ syncSend := NewSynchronizedSend (stream .Send )
455
+
437
456
// The configuration must be sent on the first message
438
457
req , err := stream .Recv ()
439
458
if err != nil {
@@ -446,7 +465,7 @@ func (s *ArduinoCoreServerImpl) Monitor(stream rpc.ArduinoCoreService_MonitorSer
446
465
}
447
466
448
467
// Send a message with Success set to true to notify the caller of the port being now active
449
- _ = stream .Send (& rpc.MonitorResponse {Success : true })
468
+ _ = syncSend .Send (& rpc.MonitorResponse {Success : true })
450
469
451
470
cancelCtx , cancel := context .WithCancel (stream .Context ())
452
471
go func () {
@@ -457,13 +476,13 @@ func (s *ArduinoCoreServerImpl) Monitor(stream rpc.ArduinoCoreService_MonitorSer
457
476
return
458
477
}
459
478
if err != nil {
460
- stream .Send (& rpc.MonitorResponse {Error : err .Error ()})
479
+ syncSend .Send (& rpc.MonitorResponse {Error : err .Error ()})
461
480
return
462
481
}
463
482
if conf := msg .GetPortConfiguration (); conf != nil {
464
483
for _ , c := range conf .GetSettings () {
465
484
if err := portProxy .Config (c .SettingId , c .Value ); err != nil {
466
- stream .Send (& rpc.MonitorResponse {Error : err .Error ()})
485
+ syncSend .Send (& rpc.MonitorResponse {Error : err .Error ()})
467
486
}
468
487
}
469
488
}
@@ -474,7 +493,7 @@ func (s *ArduinoCoreServerImpl) Monitor(stream rpc.ArduinoCoreService_MonitorSer
474
493
return
475
494
}
476
495
if err != nil {
477
- stream .Send (& rpc.MonitorResponse {Error : err .Error ()})
496
+ syncSend .Send (& rpc.MonitorResponse {Error : err .Error ()})
478
497
return
479
498
}
480
499
tx = tx [n :]
@@ -491,10 +510,10 @@ func (s *ArduinoCoreServerImpl) Monitor(stream rpc.ArduinoCoreService_MonitorSer
491
510
break
492
511
}
493
512
if err != nil {
494
- stream .Send (& rpc.MonitorResponse {Error : err .Error ()})
513
+ syncSend .Send (& rpc.MonitorResponse {Error : err .Error ()})
495
514
break
496
515
}
497
- if err := stream .Send (& rpc.MonitorResponse {RxData : buff [:n ]}); err != nil {
516
+ if err := syncSend .Send (& rpc.MonitorResponse {RxData : buff [:n ]}); err != nil {
498
517
break
499
518
}
500
519
}
0 commit comments