@@ -323,152 +323,168 @@ func TestServe(t *testing.T) {
323
323
t .Run ("poll" , func (t * testing.T ) {
324
324
t .Run ("tcp" , func (t * testing.T ) {
325
325
t .Run ("1-loop" , func (t * testing.T ) {
326
- testServe (t , "tcp" , ":9991" , false , false , false , false , 10 , RoundRobin )
326
+ testServe (t , "tcp" , ":9991" , false , false , false , false , false , 10 , RoundRobin )
327
327
})
328
328
t .Run ("N-loop" , func (t * testing.T ) {
329
- testServe (t , "tcp" , ":9992" , false , false , true , false , 10 , LeastConnections )
329
+ testServe (t , "tcp" , ":9992" , false , false , true , false , false , 10 , LeastConnections )
330
330
})
331
331
})
332
332
t .Run ("tcp-async" , func (t * testing.T ) {
333
333
t .Run ("1-loop" , func (t * testing.T ) {
334
- testServe (t , "tcp" , ":9991" , false , false , false , true , 10 , RoundRobin )
334
+ testServe (t , "tcp" , ":9991" , false , false , false , true , false , 10 , RoundRobin )
335
335
})
336
336
t .Run ("N-loop" , func (t * testing.T ) {
337
- testServe (t , "tcp" , ":9992" , false , false , true , true , 10 , LeastConnections )
337
+ testServe (t , "tcp" , ":9992" , false , false , true , true , false , 10 , LeastConnections )
338
+ })
339
+ })
340
+ t .Run ("tcp-async-writev" , func (t * testing.T ) {
341
+ t .Run ("1-loop" , func (t * testing.T ) {
342
+ testServe (t , "tcp" , ":9991" , false , false , false , true , true , 10 , RoundRobin )
343
+ })
344
+ t .Run ("N-loop" , func (t * testing.T ) {
345
+ testServe (t , "tcp" , ":9992" , false , false , true , true , true , 10 , LeastConnections )
338
346
})
339
347
})
340
348
t .Run ("udp" , func (t * testing.T ) {
341
349
t .Run ("1-loop" , func (t * testing.T ) {
342
- testServe (t , "udp" , ":9991" , false , false , false , false , 10 , RoundRobin )
350
+ testServe (t , "udp" , ":9991" , false , false , false , false , false , 10 , RoundRobin )
343
351
})
344
352
t .Run ("N-loop" , func (t * testing.T ) {
345
- testServe (t , "udp" , ":9992" , false , false , true , false , 10 , LeastConnections )
353
+ testServe (t , "udp" , ":9992" , false , false , true , false , false , 10 , LeastConnections )
346
354
})
347
355
})
348
356
t .Run ("udp-async" , func (t * testing.T ) {
349
357
t .Run ("1-loop" , func (t * testing.T ) {
350
- testServe (t , "udp" , ":9991" , false , false , false , true , 10 , RoundRobin )
358
+ testServe (t , "udp" , ":9991" , false , false , false , true , false , 10 , RoundRobin )
351
359
})
352
360
t .Run ("N-loop" , func (t * testing.T ) {
353
- testServe (t , "udp" , ":9992" , false , false , true , true , 10 , LeastConnections )
361
+ testServe (t , "udp" , ":9992" , false , false , true , true , false , 10 , LeastConnections )
354
362
})
355
363
})
356
364
t .Run ("unix" , func (t * testing.T ) {
357
365
t .Run ("1-loop" , func (t * testing.T ) {
358
- testServe (t , "unix" , "gnet1.sock" , false , false , false , false , 10 , RoundRobin )
366
+ testServe (t , "unix" , "gnet1.sock" , false , false , false , false , false , 10 , RoundRobin )
359
367
})
360
368
t .Run ("N-loop" , func (t * testing.T ) {
361
- testServe (t , "unix" , "gnet2.sock" , false , false , true , false , 10 , SourceAddrHash )
369
+ testServe (t , "unix" , "gnet2.sock" , false , false , true , false , false , 10 , SourceAddrHash )
362
370
})
363
371
})
364
372
t .Run ("unix-async" , func (t * testing.T ) {
365
373
t .Run ("1-loop" , func (t * testing.T ) {
366
- testServe (t , "unix" , "gnet1.sock" , false , false , false , true , 10 , RoundRobin )
374
+ testServe (t , "unix" , "gnet1.sock" , false , false , false , true , false , 10 , RoundRobin )
375
+ })
376
+ t .Run ("N-loop" , func (t * testing.T ) {
377
+ testServe (t , "unix" , "gnet2.sock" , false , false , true , true , false , 10 , SourceAddrHash )
378
+ })
379
+ })
380
+ t .Run ("unix-async-writev" , func (t * testing.T ) {
381
+ t .Run ("1-loop" , func (t * testing.T ) {
382
+ testServe (t , "unix" , "gnet1.sock" , false , false , false , true , true , 10 , RoundRobin )
367
383
})
368
384
t .Run ("N-loop" , func (t * testing.T ) {
369
- testServe (t , "unix" , "gnet2.sock" , false , false , true , true , 10 , SourceAddrHash )
385
+ testServe (t , "unix" , "gnet2.sock" , false , false , true , true , true , 10 , SourceAddrHash )
370
386
})
371
387
})
372
388
})
373
389
374
390
t .Run ("poll-reuseport" , func (t * testing.T ) {
375
391
t .Run ("tcp" , func (t * testing.T ) {
376
392
t .Run ("1-loop" , func (t * testing.T ) {
377
- testServe (t , "tcp" , ":9991" , true , true , false , false , 10 , RoundRobin )
393
+ testServe (t , "tcp" , ":9991" , true , true , false , false , false , 10 , RoundRobin )
378
394
})
379
395
t .Run ("N-loop" , func (t * testing.T ) {
380
- testServe (t , "tcp" , ":9992" , true , true , true , false , 10 , LeastConnections )
396
+ testServe (t , "tcp" , ":9992" , true , true , true , false , false , 10 , LeastConnections )
381
397
})
382
398
})
383
399
t .Run ("tcp-async" , func (t * testing.T ) {
384
400
t .Run ("1-loop" , func (t * testing.T ) {
385
- testServe (t , "tcp" , ":9991" , true , true , false , true , 10 , RoundRobin )
401
+ testServe (t , "tcp" , ":9991" , true , true , false , true , false , 10 , RoundRobin )
386
402
})
387
403
t .Run ("N-loop" , func (t * testing.T ) {
388
- testServe (t , "tcp" , ":9992" , true , true , true , false , 10 , LeastConnections )
404
+ testServe (t , "tcp" , ":9992" , true , true , true , false , false , 10 , LeastConnections )
389
405
})
390
406
})
391
407
t .Run ("udp" , func (t * testing.T ) {
392
408
t .Run ("1-loop" , func (t * testing.T ) {
393
- testServe (t , "udp" , ":9991" , true , true , false , false , 10 , RoundRobin )
409
+ testServe (t , "udp" , ":9991" , true , true , false , false , false , 10 , RoundRobin )
394
410
})
395
411
t .Run ("N-loop" , func (t * testing.T ) {
396
- testServe (t , "udp" , ":9992" , true , true , true , false , 10 , LeastConnections )
412
+ testServe (t , "udp" , ":9992" , true , true , true , false , false , 10 , LeastConnections )
397
413
})
398
414
})
399
415
t .Run ("udp-async" , func (t * testing.T ) {
400
416
t .Run ("1-loop" , func (t * testing.T ) {
401
- testServe (t , "udp" , ":9991" , true , true , false , false , 10 , RoundRobin )
417
+ testServe (t , "udp" , ":9991" , true , true , false , false , false , 10 , RoundRobin )
402
418
})
403
419
t .Run ("N-loop" , func (t * testing.T ) {
404
- testServe (t , "udp" , ":9992" , true , true , true , true , 10 , LeastConnections )
420
+ testServe (t , "udp" , ":9992" , true , true , true , true , false , 10 , LeastConnections )
405
421
})
406
422
})
407
423
t .Run ("unix" , func (t * testing.T ) {
408
424
t .Run ("1-loop" , func (t * testing.T ) {
409
- testServe (t , "unix" , "gnet1.sock" , true , true , false , false , 10 , RoundRobin )
425
+ testServe (t , "unix" , "gnet1.sock" , true , true , false , false , false , 10 , RoundRobin )
410
426
})
411
427
t .Run ("N-loop" , func (t * testing.T ) {
412
- testServe (t , "unix" , "gnet2.sock" , true , true , true , false , 10 , LeastConnections )
428
+ testServe (t , "unix" , "gnet2.sock" , true , true , true , false , false , 10 , LeastConnections )
413
429
})
414
430
})
415
431
t .Run ("unix-async" , func (t * testing.T ) {
416
432
t .Run ("1-loop" , func (t * testing.T ) {
417
- testServe (t , "unix" , "gnet1.sock" , true , true , false , true , 10 , RoundRobin )
433
+ testServe (t , "unix" , "gnet1.sock" , true , true , false , true , false , 10 , RoundRobin )
418
434
})
419
435
t .Run ("N-loop" , func (t * testing.T ) {
420
- testServe (t , "unix" , "gnet2.sock" , true , true , true , true , 10 , LeastConnections )
436
+ testServe (t , "unix" , "gnet2.sock" , true , true , true , true , false , 10 , LeastConnections )
421
437
})
422
438
})
423
439
})
424
440
425
441
t .Run ("poll-reuseaddr" , func (t * testing.T ) {
426
442
t .Run ("tcp" , func (t * testing.T ) {
427
443
t .Run ("1-loop" , func (t * testing.T ) {
428
- testServe (t , "tcp" , ":9991" , false , true , false , false , 10 , RoundRobin )
444
+ testServe (t , "tcp" , ":9991" , false , true , false , false , false , 10 , RoundRobin )
429
445
})
430
446
t .Run ("N-loop" , func (t * testing.T ) {
431
- testServe (t , "tcp" , ":9992" , false , true , true , false , 10 , LeastConnections )
447
+ testServe (t , "tcp" , ":9992" , false , true , true , false , false , 10 , LeastConnections )
432
448
})
433
449
})
434
450
t .Run ("tcp-async" , func (t * testing.T ) {
435
451
t .Run ("1-loop" , func (t * testing.T ) {
436
- testServe (t , "tcp" , ":9991" , false , true , false , true , 10 , RoundRobin )
452
+ testServe (t , "tcp" , ":9991" , false , true , false , true , false , 10 , RoundRobin )
437
453
})
438
454
t .Run ("N-loop" , func (t * testing.T ) {
439
- testServe (t , "tcp" , ":9992" , false , true , true , false , 10 , LeastConnections )
455
+ testServe (t , "tcp" , ":9992" , false , true , true , false , false , 10 , LeastConnections )
440
456
})
441
457
})
442
458
t .Run ("udp" , func (t * testing.T ) {
443
459
t .Run ("1-loop" , func (t * testing.T ) {
444
- testServe (t , "udp" , ":9991" , false , true , false , false , 10 , RoundRobin )
460
+ testServe (t , "udp" , ":9991" , false , true , false , false , false , 10 , RoundRobin )
445
461
})
446
462
t .Run ("N-loop" , func (t * testing.T ) {
447
- testServe (t , "udp" , ":9992" , false , true , true , false , 10 , LeastConnections )
463
+ testServe (t , "udp" , ":9992" , false , true , true , false , false , 10 , LeastConnections )
448
464
})
449
465
})
450
466
t .Run ("udp-async" , func (t * testing.T ) {
451
467
t .Run ("1-loop" , func (t * testing.T ) {
452
- testServe (t , "udp" , ":9991" , false , true , false , false , 10 , RoundRobin )
468
+ testServe (t , "udp" , ":9991" , false , true , false , false , false , 10 , RoundRobin )
453
469
})
454
470
t .Run ("N-loop" , func (t * testing.T ) {
455
- testServe (t , "udp" , ":9992" , false , true , true , true , 10 , LeastConnections )
471
+ testServe (t , "udp" , ":9992" , false , true , true , true , false , 10 , LeastConnections )
456
472
})
457
473
})
458
474
t .Run ("unix" , func (t * testing.T ) {
459
475
t .Run ("1-loop" , func (t * testing.T ) {
460
- testServe (t , "unix" , "gnet1.sock" , false , true , false , false , 10 , RoundRobin )
476
+ testServe (t , "unix" , "gnet1.sock" , false , true , false , false , false , 10 , RoundRobin )
461
477
})
462
478
t .Run ("N-loop" , func (t * testing.T ) {
463
- testServe (t , "unix" , "gnet2.sock" , false , true , true , false , 10 , LeastConnections )
479
+ testServe (t , "unix" , "gnet2.sock" , false , true , true , false , false , 10 , LeastConnections )
464
480
})
465
481
})
466
482
t .Run ("unix-async" , func (t * testing.T ) {
467
483
t .Run ("1-loop" , func (t * testing.T ) {
468
- testServe (t , "unix" , "gnet1.sock" , false , true , false , true , 10 , RoundRobin )
484
+ testServe (t , "unix" , "gnet1.sock" , false , true , false , true , false , 10 , RoundRobin )
469
485
})
470
486
t .Run ("N-loop" , func (t * testing.T ) {
471
- testServe (t , "unix" , "gnet2.sock" , false , true , true , true , 10 , LeastConnections )
487
+ testServe (t , "unix" , "gnet2.sock" , false , true , true , true , false , 10 , LeastConnections )
472
488
})
473
489
})
474
490
})
@@ -482,6 +498,7 @@ type testServer struct {
482
498
addr string
483
499
multicore bool
484
500
async bool
501
+ writev bool
485
502
nclients int
486
503
started int32
487
504
connected int32
@@ -534,7 +551,15 @@ func (s *testServer) React(packet []byte, c Conn) (out []byte, action Action) {
534
551
535
552
_ = s .workerPool .Submit (
536
553
func () {
537
- _ = c .AsyncWrite (buf .Bytes ())
554
+ if s .writev {
555
+ mid := buf .Len () / 2
556
+ bs := make ([][]byte , 2 )
557
+ bs [0 ] = buf .B [:mid ]
558
+ bs [1 ] = buf .B [mid :]
559
+ _ = c .AsyncWritev (bs )
560
+ } else {
561
+ _ = c .AsyncWrite (buf .Bytes ())
562
+ }
538
563
})
539
564
return
540
565
} else if s .network == "udp" {
@@ -568,13 +593,14 @@ func (s *testServer) Tick() (delay time.Duration, action Action) {
568
593
return
569
594
}
570
595
571
- func testServe (t * testing.T , network , addr string , reuseport , reuseaddr , multicore , async bool , nclients int , lb LoadBalancing ) {
596
+ func testServe (t * testing.T , network , addr string , reuseport , reuseaddr , multicore , async , writev bool , nclients int , lb LoadBalancing ) {
572
597
ts := & testServer {
573
598
tester : t ,
574
599
network : network ,
575
600
addr : addr ,
576
601
multicore : multicore ,
577
602
async : async ,
603
+ writev : writev ,
578
604
nclients : nclients ,
579
605
workerPool : goroutine .Default (),
580
606
}
0 commit comments