1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
mod common;
#[cfg(any(
feature = "catnap-libos",
feature = "catnip-libos",
feature = "catpowder-libos",
feature = "catloop-libos"
))]
mod test {
//======================================================================================================================
// Imports
//======================================================================================================================
use crate::common::{
libos::*,
ALICE_CONFIG_PATH,
ALICE_IP,
BOB_CONFIG_PATH,
BOB_IP,
PORT_BASE,
};
use ::anyhow::Result;
use ::demikernel::{
demi_sgarray_t,
runtime::{
memory::{
DemiBuffer,
MemoryRuntime,
},
OperationResult,
QDesc,
QToken,
},
};
use ::socket2::{
Domain,
Protocol,
Type,
};
use crossbeam_channel::{
Receiver,
Sender,
};
#[cfg(target_os = "windows")]
pub const AF_INET: i32 = windows::Win32::Networking::WinSock::AF_INET.0 as i32;
#[cfg(target_os = "windows")]
pub const SOMAXCONN: i32 = WinSock::SOMAXCONN as i32;
#[cfg(target_os = "linux")]
pub const AF_INET: i32 = libc::AF_INET;
#[cfg(target_os = "linux")]
pub const SOMAXCONN: i32 = libc::SOMAXCONN;
/// A default amount of time to wait on an operation to complete. This was chosen arbitrarily to be high enough to
/// ensure most OS operations will complete.
const DEFAULT_TIMEOUT: Duration = Duration::from_millis(100);
const BAD_WAIT_TIMEOUT: Duration = Duration::from_millis(1);
use std::{
net::{
IpAddr,
Ipv4Addr,
Ipv6Addr,
SocketAddr,
SocketAddrV6,
},
sync::{
Arc,
Barrier,
},
thread::{
self,
JoinHandle,
},
time::Duration,
};
#[cfg(target_os = "windows")]
use windows::Win32::Networking::WinSock;
//======================================================================================================================
// Open/Close Passive Socket
//======================================================================================================================
/// Opens and closes a passive socket using a non-ephemeral port.
fn do_passive_connection_setup(mut libos: &mut DummyLibOS) -> Result<()> {
let local: SocketAddr = SocketAddr::new(ALICE_IP, PORT_BASE);
let sockqd: QDesc = safe_socket(&mut libos)?;
safe_bind(&mut libos, sockqd, local)?;
safe_listen(&mut libos, sockqd)?;
safe_close_passive(&mut libos, sockqd)?;
Ok(())
}
/// Opens and closes a passive socket using an ephemeral port.
fn do_passive_connection_setup_ephemeral(mut libos: &mut DummyLibOS) -> Result<()> {
pub const PORT_EPHEMERAL_BASE: u16 = 49152;
let local: SocketAddr = SocketAddr::new(ALICE_IP, PORT_EPHEMERAL_BASE);
let sockqd: QDesc = safe_socket(&mut libos)?;
safe_bind(&mut libos, sockqd, local)?;
safe_listen(&mut libos, sockqd)?;
safe_close_passive(&mut libos, sockqd)?;
Ok(())
}
/// Tests if a passive socket may be successfully opened and closed.
#[test]
fn tcp_connection_setup() -> Result<()> {
let (tx, rx): (Sender<DemiBuffer>, Receiver<DemiBuffer>) = crossbeam_channel::unbounded();
let mut libos: DummyLibOS = DummyLibOS::new_test(ALICE_CONFIG_PATH, tx, rx)?;
do_passive_connection_setup(&mut libos)?;
do_passive_connection_setup_ephemeral(&mut libos)?;
Ok(())
}
//======================================================================================================================
// Establish Connection
//======================================================================================================================
/// Tests if connection may be successfully established by an unbound active socket.
#[test]
fn tcp_establish_connection_unbound() -> Result<()> {
let (alice_tx, alice_rx): (Sender<DemiBuffer>, Receiver<DemiBuffer>) = crossbeam_channel::unbounded();
let (bob_tx, bob_rx): (Sender<DemiBuffer>, Receiver<DemiBuffer>) = crossbeam_channel::unbounded();
let bob_barrier: Arc<Barrier> = Arc::new(Barrier::new(2));
let alice_barrier: Arc<Barrier> = bob_barrier.clone();
let alice: JoinHandle<Result<()>> = thread::spawn(move || {
let mut libos: DummyLibOS = match DummyLibOS::new_test(ALICE_CONFIG_PATH, alice_tx, bob_rx) {
Ok(libos) => libos,
Err(e) => anyhow::bail!("Could not create inetstack: {:?}", e),
};
let local: SocketAddr = SocketAddr::new(ALICE_IP, PORT_BASE);
// Open connection.
let sockqd: QDesc = safe_socket(&mut libos)?;
safe_bind(&mut libos, sockqd, local)?;
safe_listen(&mut libos, sockqd)?;
let qt: QToken = safe_accept(&mut libos, sockqd)?;
let (_, qr): (QDesc, OperationResult) = safe_wait(&mut libos, qt)?;
let qd: QDesc = match qr {
OperationResult::Accept((qd, addr)) if addr.ip() == &BOB_IP => qd,
_ => {
// Close socket on error.
// FIXME: https://github.com/demikernel/demikernel/issues/633
anyhow::bail!("accept() has failed")
},
};
// Close connection.
safe_close_active(&mut libos, qd)?;
safe_close_passive(&mut libos, sockqd)?;
alice_barrier.wait();
Ok(())
});
let bob: JoinHandle<Result<()>> = thread::spawn(move || {
let mut libos: DummyLibOS = match DummyLibOS::new_test(BOB_CONFIG_PATH, bob_tx, alice_rx) {
Ok(libos) => libos,
Err(e) => anyhow::bail!("Could not create inetstack: {:?}", e),
};
let remote: SocketAddr = SocketAddr::new(ALICE_IP, PORT_BASE);
// Open connection.
let sockqd: QDesc = safe_socket(&mut libos)?;
let qt: QToken = safe_connect(&mut libos, sockqd, remote)?;
let (_, qr): (QDesc, OperationResult) = safe_wait(&mut libos, qt)?;
match qr {
OperationResult::Connect => (),
_ => {
// Close socket on error.
// FIXME: https://github.com/demikernel/demikernel/issues/633
anyhow::bail!("connect() has failed")
},
}
// Close connection.
safe_close_active(&mut libos, sockqd)?;
// Sleep for a while to give Alice time to finish.
bob_barrier.wait();
Ok(())
});
// It is safe to use unwrap here because there should not be any reason that we can't join the thread and if there
// is, there is nothing to clean up here on the main thread.
alice.join().unwrap()?;
bob.join().unwrap()?;
Ok(())
}
/// Tests if connection may be successfully established by a bound active socket.
#[test]
fn tcp_establish_connection_bound() -> Result<()> {
let (alice_tx, alice_rx): (Sender<DemiBuffer>, Receiver<DemiBuffer>) = crossbeam_channel::unbounded();
let (bob_tx, bob_rx): (Sender<DemiBuffer>, Receiver<DemiBuffer>) = crossbeam_channel::unbounded();
let bob_barrier: Arc<Barrier> = Arc::new(Barrier::new(2));
let alice_barrier: Arc<Barrier> = bob_barrier.clone();
let alice: JoinHandle<Result<()>> = thread::spawn(move || {
let mut libos: DummyLibOS = match DummyLibOS::new_test(ALICE_CONFIG_PATH, alice_tx, bob_rx) {
Ok(libos) => libos,
Err(e) => anyhow::bail!("Could not create inetstack: {:?}", e),
};
let local: SocketAddr = SocketAddr::new(ALICE_IP, PORT_BASE);
// Open connection.
let sockqd: QDesc = safe_socket(&mut libos)?;
safe_bind(&mut libos, sockqd, local)?;
safe_listen(&mut libos, sockqd)?;
let qt: QToken = safe_accept(&mut libos, sockqd)?;
let (_, qr): (QDesc, OperationResult) = safe_wait(&mut libos, qt)?;
let qd: QDesc = match qr {
OperationResult::Accept((qd, addr)) if addr.ip() == &BOB_IP => qd,
_ => {
// Close socket on error.
// FIXME: https://github.com/demikernel/demikernel/issues/633
anyhow::bail!("accept() has failed")
},
};
// Close connection.
safe_close_active(&mut libos, qd)?;
safe_close_passive(&mut libos, sockqd)?;
// Sleep for a while to give Bob time to finish.
alice_barrier.wait();
Ok(())
});
let bob: JoinHandle<Result<()>> = thread::spawn(move || {
let mut libos: DummyLibOS = match DummyLibOS::new_test(BOB_CONFIG_PATH, bob_tx, alice_rx) {
Ok(libos) => libos,
Err(e) => anyhow::bail!("Could not create inetstack: {:?}", e),
};
let local: SocketAddr = SocketAddr::new(BOB_IP, PORT_BASE);
let remote: SocketAddr = SocketAddr::new(ALICE_IP, PORT_BASE);
// Open connection.
let sockqd: QDesc = safe_socket(&mut libos)?;
safe_bind(&mut libos, sockqd, local)?;
let qt: QToken = safe_connect(&mut libos, sockqd, remote)?;
let (_, qr): (QDesc, OperationResult) = safe_wait(&mut libos, qt)?;
match qr {
OperationResult::Connect => (),
_ => {
// Close socket on error.
// FIXME: https://github.com/demikernel/demikernel/issues/633
anyhow::bail!("connect() has failed")
},
}
// Close connection.
safe_close_active(&mut libos, sockqd)?;
// Sleep for a while to give Alice time to finish.
bob_barrier.wait();
Ok(())
});
// It is safe to use unwrap here because there should not be any reason that we can't join the thread and if there
// is, there is nothing to clean up here on the main thread.
alice.join().unwrap()?;
bob.join().unwrap()?;
Ok(())
}
//======================================================================================================================
// Push
//======================================================================================================================
/// Tests if data can be pushed.
#[test]
fn tcp_push_remote() -> Result<()> {
let (alice_tx, alice_rx): (Sender<DemiBuffer>, Receiver<DemiBuffer>) = crossbeam_channel::unbounded();
let (bob_tx, bob_rx): (Sender<DemiBuffer>, Receiver<DemiBuffer>) = crossbeam_channel::unbounded();
let bob_barrier: Arc<Barrier> = Arc::new(Barrier::new(2));
let alice_barrier: Arc<Barrier> = bob_barrier.clone();
let alice: JoinHandle<Result<()>> = thread::spawn(move || {
let mut libos: DummyLibOS = match DummyLibOS::new_test(ALICE_CONFIG_PATH, alice_tx, bob_rx) {
Ok(libos) => libos,
Err(e) => anyhow::bail!("Could not create inetstack: {:?}", e),
};
let port: u16 = PORT_BASE;
let local: SocketAddr = SocketAddr::new(ALICE_IP, port);
// Open connection.
let sockqd: QDesc = safe_socket(&mut libos)?;
safe_bind(&mut libos, sockqd, local)?;
safe_listen(&mut libos, sockqd)?;
let qt: QToken = safe_accept(&mut libos, sockqd)?;
let (_, qr): (QDesc, OperationResult) = safe_wait(&mut libos, qt)?;
let qd: QDesc = match qr {
OperationResult::Accept((qd, addr)) if addr.ip() == &BOB_IP => qd,
_ => {
// Close socket on error.
// FIXME: https://github.com/demikernel/demikernel/issues/633
anyhow::bail!("accept() has failed")
},
};
// Pop data.
let qt: QToken = safe_pop(&mut libos, qd)?;
let (qd, qr): (QDesc, OperationResult) = safe_wait(&mut libos, qt)?;
match qr {
OperationResult::Pop(_, _) => (),
_ => {
// Close socket on error.
// FIXME: https://github.com/demikernel/demikernel/issues/633
anyhow::bail!("pop() has has failed {:?}", qr)
},
}
// Close connection.
safe_close_active(&mut libos, qd)?;
safe_close_passive(&mut libos, sockqd)?;
alice_barrier.wait();
Ok(())
});
let bob: JoinHandle<Result<()>> = thread::spawn(move || {
let mut libos: DummyLibOS = match DummyLibOS::new_test(BOB_CONFIG_PATH, bob_tx, alice_rx) {
Ok(libos) => libos,
Err(e) => anyhow::bail!("Could not create inetstack: {:?}", e),
};
let port: u16 = PORT_BASE;
let remote: SocketAddr = SocketAddr::new(ALICE_IP, port);
// Open connection.
let sockqd: QDesc = safe_socket(&mut libos)?;
let qt: QToken = safe_connect(&mut libos, sockqd, remote)?;
let (_, qr): (QDesc, OperationResult) = safe_wait(&mut libos, qt)?;
match qr {
OperationResult::Connect => (),
_ => {
// Close socket on error.
// FIXME: https://github.com/demikernel/demikernel/issues/633
anyhow::bail!("connect() has failed")
},
}
// Cook some data and push.
let buf = libos.cook_data(32)?;
let qt: QToken = safe_push(&mut libos, sockqd, buf)?;
let (_, qr): (QDesc, OperationResult) = safe_wait(&mut libos, qt)?;
match qr {
OperationResult::Push => (),
_ => {
// Close socket on error.
// FIXME: https://github.com/demikernel/demikernel/issues/633
anyhow::bail!("push() has failed")
},
}
// Close connection.
safe_close_active(&mut libos, sockqd)?;
bob_barrier.wait();
Ok(())
});
// It is safe to use unwrap here because there should not be any reason that we can't join the thread and if there
// is, there is nothing to clean up here on the main thread.
alice.join().unwrap()?;
bob.join().unwrap()?;
Ok(())
}
//======================================================================================================================
// Bad Socket
//======================================================================================================================
/// Tests for bad socket creation.
#[test]
fn tcp_bad_socket() -> Result<()> {
let (tx, rx): (Sender<DemiBuffer>, Receiver<DemiBuffer>) = crossbeam_channel::unbounded();
let mut libos: DummyLibOS = match DummyLibOS::new_test(ALICE_CONFIG_PATH, tx, rx) {
Ok(libos) => libos,
Err(e) => anyhow::bail!("Could not create inetstack: {:?}", e),
};
#[cfg(target_os = "linux")]
let domains: Vec<libc::c_int> = vec![
libc::AF_ALG,
libc::AF_APPLETALK,
libc::AF_ASH,
libc::AF_ATMPVC,
libc::AF_ATMSVC,
libc::AF_AX25,
libc::AF_BLUETOOTH,
libc::AF_BRIDGE,
libc::AF_CAIF,
libc::AF_CAN,
libc::AF_DECnet,
libc::AF_ECONET,
libc::AF_IB,
libc::AF_IEEE802154,
// libc::AF_INET,
libc::AF_INET6,
libc::AF_IPX,
libc::AF_IRDA,
libc::AF_ISDN,
libc::AF_IUCV,
libc::AF_KEY,
libc::AF_LLC,
libc::AF_LOCAL,
libc::AF_MPLS,
libc::AF_NETBEUI,
libc::AF_NETLINK,
libc::AF_NETROM,
libc::AF_NFC,
libc::AF_PACKET,
libc::AF_PHONET,
libc::AF_PPPOX,
libc::AF_RDS,
libc::AF_ROSE,
libc::AF_ROUTE,
libc::AF_RXRPC,
libc::AF_SECURITY,
libc::AF_SNA,
libc::AF_TIPC,
libc::AF_UNIX,
libc::AF_UNSPEC,
libc::AF_VSOCK,
libc::AF_WANPIPE,
libc::AF_X25,
libc::AF_XDP,
];
#[cfg(target_os = "windows")]
let domains: Vec<libc::c_int> = vec![
WinSock::AF_APPLETALK as i32,
WinSock::AF_DECnet as i32,
// WinSock::AF_INET as i32,
WinSock::AF_INET6.0 as i32,
WinSock::AF_IPX as i32,
WinSock::AF_IRDA as i32,
WinSock::AF_SNA as i32,
WinSock::AF_UNIX as i32,
WinSock::AF_UNSPEC.0 as i32,
];
#[cfg(target_os = "linux")]
let socket_types: Vec<libc::c_int> = vec![
libc::SOCK_DCCP,
// libc::SOCK_DGRAM,
libc::SOCK_PACKET,
libc::SOCK_RAW,
libc::SOCK_RDM,
libc::SOCK_SEQPACKET,
// libc::SOCK_STREAM,
];
#[cfg(target_os = "windows")]
let socket_types: Vec<libc::c_int> = vec![
WinSock::SOCK_RAW.0 as i32,
WinSock::SOCK_RDM.0 as i32,
WinSock::SOCK_SEQPACKET.0 as i32,
];
// Invalid domain.
for d in domains {
match libos.socket(d.into(), Type::STREAM, 0.into()) {
Err(e) if e.errno == libc::ENOTSUP => (),
_ => anyhow::bail!("invalid call to socket() should fail with ENOTSUP"),
};
}
// Invalid socket tpe.
for t in socket_types {
match libos.socket(AF_INET.into(), t.into(), 0.into()) {
Err(e) if e.errno == libc::ENOTSUP => (),
_ => anyhow::bail!("invalid call to socket() should fail with ENOTSUP"),
};
}
Ok(())
}
//======================================================================================================================
// Bad Bind
//======================================================================================================================
/// Tests bad calls for `bind()`.
#[test]
fn tcp_bad_bind() -> Result<()> {
let (tx, rx): (Sender<DemiBuffer>, Receiver<DemiBuffer>) = crossbeam_channel::unbounded();
let mut libos: DummyLibOS = match DummyLibOS::new_test(ALICE_CONFIG_PATH, tx, rx) {
Ok(libos) => libos,
Err(e) => anyhow::bail!("Could not create inetstack: {:?}", e),
};
let port: u16 = PORT_BASE;
let port2: u16 = PORT_BASE + 1;
let local: SocketAddr = SocketAddr::new(ALICE_IP, port);
let local2: SocketAddr = SocketAddr::new(ALICE_IP, port2);
let localv6: SocketAddr = SocketAddr::V6(SocketAddrV6::new(Ipv6Addr::LOCALHOST, port, 0, 0));
// IPv6 unsupported
let sockqd: QDesc = safe_socket(&mut libos)?;
match libos.bind(sockqd, localv6) {
Err(e) if e.errno == libc::EINVAL => (),
_ => anyhow::bail!("invalid call to bind should fail with EINVAL"),
}
// Can't re-bind an address
let sockqd2: QDesc = safe_socket(&mut libos)?;
safe_bind(&mut libos, sockqd, local)?;
match libos.bind(sockqd2, local) {
Err(e) if e.errno == libc::EADDRINUSE => (),
_ => anyhow::bail!("invalid call to bind should fail with EADDRINUSE"),
};
// Can't bind a bound socket
match libos.bind(sockqd, local2) {
Err(e) if e.errno == libc::EINVAL => (),
_ => anyhow::bail!("invalid call to bind should fail with EINVAL"),
};
Ok(())
}
//======================================================================================================================
// Bad Listen
//======================================================================================================================
/// Tests bad calls for `listen()`.
#[test]
fn tcp_bad_listen() -> Result<()> {
let (tx, rx): (Sender<DemiBuffer>, Receiver<DemiBuffer>) = crossbeam_channel::unbounded();
let mut libos: DummyLibOS = match DummyLibOS::new_test(ALICE_CONFIG_PATH, tx, rx) {
Ok(libos) => libos,
Err(e) => anyhow::bail!("Could not create inetstack: {:?}", e),
};
let port: u16 = PORT_BASE;
let port2: u16 = PORT_BASE + 1;
let local: SocketAddr = SocketAddr::new(ALICE_IP, port);
let local2: SocketAddr = SocketAddr::new(ALICE_IP, port2);
// Invalid queue descriptor.
match libos.listen(QDesc::from(0), SOMAXCONN as usize) {
Err(e) if e.errno == libc::EBADF => (),
_ => {
// Close socket if not error because this test cannot continue.
// FIXME: https://github.com/demikernel/demikernel/issues/633
anyhow::bail!("invalid call to listen() should fail with EBADF")
},
};
// Invalid backlog length
let sockqd: QDesc = safe_socket(&mut libos)?;
safe_bind(&mut libos, sockqd, local)?;
match libos.listen(sockqd, 0) {
Err(e) if e.errno == libc::EINVAL => (),
_ => {
// Close socket if not error because this test cannot continue.
// FIXME: https://github.com/demikernel/demikernel/issues/633
anyhow::bail!("invalid call to listen() should fail with EINVAL")
},
};
safe_close_active(&mut libos, sockqd)?;
// Listen on an already listening socket.
// TODO: use a single IP and port when we properly clean up bound addresses on close.
let sockqd: QDesc = safe_socket(&mut libos)?;
safe_bind(&mut libos, sockqd, local2)?;
safe_listen(&mut libos, sockqd)?;
match libos.listen(sockqd, SOMAXCONN as usize) {
Err(e) if e.errno == libc::EADDRINUSE => (),
_ => {
// Close socket if not error because this test cannot continue.
// FIXME: https://github.com/demikernel/demikernel/issues/633
anyhow::bail!("listen() called on an already listening socket should fail with EADDRINUSE")
},
};
safe_close_passive(&mut libos, sockqd)?;
// TODO: Add unit test for "Listen on an in-use address/port pair." (see issue #178).
// Listen on unbound socket.
let sockqd: QDesc = safe_socket(&mut libos)?;
match libos.listen(sockqd, SOMAXCONN as usize) {
Err(e) if e.errno == libc::EDESTADDRREQ => (),
Err(e) => {
// Close socket if not the correct error because this test cannot continue.
// FIXME: https://github.com/demikernel/demikernel/issues/633
anyhow::bail!("listen() to unbound address should fail with EDESTADDRREQ {:?}", e)
},
_ => {
// Close socket if not error because this test cannot continue.
// FIXME: https://github.com/demikernel/demikernel/issues/633
anyhow::bail!("should fail")
},
};
safe_close_active(&mut libos, sockqd)?;
Ok(())
}
//======================================================================================================================
// Bad Accept
//======================================================================================================================
/// Tests bad calls for `accept()`.
#[test]
fn tcp_bad_accept() -> Result<()> {
let (tx, rx): (Sender<DemiBuffer>, Receiver<DemiBuffer>) = crossbeam_channel::unbounded();
let mut libos: DummyLibOS = match DummyLibOS::new_test(ALICE_CONFIG_PATH, tx, rx) {
Ok(libos) => libos,
Err(e) => anyhow::bail!("Could not create inetstack: {:?}", e),
};
// Invalid queue descriptor.
match libos.accept(QDesc::from(0)) {
Err(e) if e.errno == libc::EBADF => (),
_ => {
// Close socket if we somehow got a socket back?
// FIXME: https://github.com/demikernel/demikernel/issues/633
anyhow::bail!("invalid call to accept() should fail with EBADF")
},
};
Ok(())
}
//======================================================================================================================
// Bad Connect
//======================================================================================================================
/// Tests if data can be successfully established.
#[test]
fn tcp_bad_connect() -> Result<()> {
let (alice_tx, alice_rx): (Sender<DemiBuffer>, Receiver<DemiBuffer>) = crossbeam_channel::unbounded();
let (bob_tx, bob_rx): (Sender<DemiBuffer>, Receiver<DemiBuffer>) = crossbeam_channel::unbounded();
let bob_barrier: Arc<Barrier> = Arc::new(Barrier::new(2));
let alice_barrier: Arc<Barrier> = bob_barrier.clone();
let alice: JoinHandle<Result<()>> = thread::spawn(move || {
let mut libos: DummyLibOS = match DummyLibOS::new_test(ALICE_CONFIG_PATH, alice_tx, bob_rx) {
Ok(libos) => libos,
Err(e) => anyhow::bail!("Could not create inetstack: {:?}", e),
};
let port: u16 = PORT_BASE;
let local: SocketAddr = SocketAddr::new(ALICE_IP, port);
// Open connection.
let sockqd: QDesc = safe_socket(&mut libos)?;
safe_bind(&mut libos, sockqd, local)?;
safe_listen(&mut libos, sockqd)?;
let qt: QToken = safe_accept(&mut libos, sockqd)?;
let (_, qr): (QDesc, OperationResult) = safe_wait(&mut libos, qt)?;
let qd: QDesc = match qr {
OperationResult::Accept((qd, addr)) if addr.ip() == &BOB_IP => qd,
_ => {
// Close socket on error.
// FIXME: https://github.com/demikernel/demikernel/issues/633
anyhow::bail!("accept() has failed")
},
};
// Close connection.
safe_close_active(&mut libos, qd)?;
safe_close_passive(&mut libos, sockqd)?;
alice_barrier.wait();
Ok(())
});
let bob: JoinHandle<Result<()>> = thread::spawn(move || {
let mut libos: DummyLibOS = match DummyLibOS::new_test(BOB_CONFIG_PATH, bob_tx, alice_rx) {
Ok(libos) => libos,
Err(e) => anyhow::bail!("Could not create inetstack: {:?}", e),
};
let port: u16 = PORT_BASE;
let remote: SocketAddr = SocketAddr::new(ALICE_IP, port);
// Bad queue descriptor.
match libos.connect(QDesc::from(0), remote) {
Err(e) if e.errno == libc::EBADF => (),
_ => {
// Close socket if not error because this test cannot continue.
// FIXME: https://github.com/demikernel/demikernel/issues/633
anyhow::bail!("invalid call to connect() should fail with EBADF")
},
};
// Bad endpoint.
let bad_remote: SocketAddr = SocketAddr::new(IpAddr::V4(Ipv4Addr::new(0, 0, 0, 0)), port);
let sockqd: QDesc = safe_socket(&mut libos)?;
let qt: QToken = safe_connect(&mut libos, sockqd, bad_remote)?;
match libos.wait(qt, Some(BAD_WAIT_TIMEOUT)) {
Err(e) if e.errno == libc::ETIMEDOUT => (),
Ok((_, OperationResult::Connect)) => {
// Close socket if not error because this test cannot continue.
// FIXME: https://github.com/demikernel/demikernel/issues/633
anyhow::bail!("connect() should have timed out")
},
_ => anyhow::bail!("connect() should have timed out"),
}
// Close connection.
let remote: SocketAddr = SocketAddr::new(ALICE_IP, port);
let sockqd: QDesc = safe_socket(&mut libos)?;
let qt: QToken = safe_connect(&mut libos, sockqd, remote)?;
let (_, qr): (QDesc, OperationResult) = safe_wait(&mut libos, qt)?;
match qr {
OperationResult::Connect => (),
_ => {
// Close socket if not error because this test cannot continue.
// FIXME: https://github.com/demikernel/demikernel/issues/633
anyhow::bail!("connect() has failed")
},
}
// Close connection.
safe_close_active(&mut libos, sockqd)?;
bob_barrier.wait();
Ok(())
});
// It is safe to use unwrap here because there should not be any reason that we can't join the thread and if there
// is, there is nothing to clean up here on the main thread.
alice.join().unwrap()?;
bob.join().unwrap()?;
Ok(())
}
//======================================================================================================================
// Bad Close
//======================================================================================================================
/// Tests if bad calls t `close()`.
#[test]
fn tcp_bad_close() -> Result<()> {
let (alice_tx, alice_rx): (Sender<DemiBuffer>, Receiver<DemiBuffer>) = crossbeam_channel::unbounded();
let (bob_tx, bob_rx): (Sender<DemiBuffer>, Receiver<DemiBuffer>) = crossbeam_channel::unbounded();
let bob_barrier: Arc<Barrier> = Arc::new(Barrier::new(2));
let alice_barrier: Arc<Barrier> = bob_barrier.clone();
let alice: JoinHandle<Result<()>> = thread::spawn(move || {
let mut libos: DummyLibOS = match DummyLibOS::new_test(ALICE_CONFIG_PATH, alice_tx, bob_rx) {
Ok(libos) => libos,
Err(e) => anyhow::bail!("Could not create inetstack: {:?}", e),
};
let port: u16 = PORT_BASE;
let local: SocketAddr = SocketAddr::new(ALICE_IP, port);
// Open connection.
let sockqd: QDesc = safe_socket(&mut libos)?;
safe_bind(&mut libos, sockqd, local)?;
safe_listen(&mut libos, sockqd)?;
let qt: QToken = safe_accept(&mut libos, sockqd)?;
let (_, qr): (QDesc, OperationResult) = safe_wait(&mut libos, qt)?;
let qd: QDesc = match qr {
OperationResult::Accept((qd, addr)) if addr.ip() == &BOB_IP => qd,
_ => {
// Close socket if error.
// FIXME: https://github.com/demikernel/demikernel/issues/633
anyhow::bail!("accept() has failed")
},
};
// Close bad queue descriptor.
match libos.async_close(QDesc::from(2)) {
Ok(_) => anyhow::bail!("close() invalid file descriptir should fail"),
Err(_) => (),
};
// Close connection.
safe_close_active(&mut libos, qd)?;
safe_close_passive(&mut libos, sockqd)?;
// Double close queue descriptor.
match libos.async_close(qd) {
Ok(_) => anyhow::bail!("double close() should fail"),
Err(_) => (),
};
alice_barrier.wait();
Ok(())
});
let bob: JoinHandle<Result<()>> = thread::spawn(move || {
let mut libos: DummyLibOS = match DummyLibOS::new_test(BOB_CONFIG_PATH, bob_tx, alice_rx) {
Ok(libos) => libos,
Err(e) => anyhow::bail!("Could not create inetstack: {:?}", e),
};
let port: u16 = PORT_BASE;
let remote: SocketAddr = SocketAddr::new(ALICE_IP, port);
// Open connection.
let sockqd: QDesc = safe_socket(&mut libos)?;
let qt: QToken = safe_connect(&mut libos, sockqd, remote)?;
let (_, qr): (QDesc, OperationResult) = safe_wait(&mut libos, qt)?;
match qr {
OperationResult::Connect => (),
_ => {
// Close socket if error.
// FIXME: https://github.com/demikernel/demikernel/issues/633
anyhow::bail!("connect() has failed")
},
}
// Close bad queue descriptor.
match libos.async_close(QDesc::from(2)) {
// Should not be able to close bad queue descriptor.
Ok(_) => anyhow::bail!("close() invalid queue descriptor should fail"),
Err(_) => (),
};
// Close connection.
safe_close_active(&mut libos, sockqd)?;
// Double close queue descriptor.
match libos.async_close(sockqd) {
// Should not be able to double close.
Ok(_) => anyhow::bail!("double close() should fail"),
Err(_) => (),
};
bob_barrier.wait();
Ok(())
});
// It is safe to use unwrap here because there should not be any reason that we can't join the thread and if there
// is, there is nothing to clean up here on the main thread.
alice.join().unwrap()?;
bob.join().unwrap()?;
Ok(())
}
//======================================================================================================================
// Bad Push
//======================================================================================================================
/// Tests bad calls to `push()`.
#[test]
fn tcp_bad_push() -> Result<()> {
let (alice_tx, alice_rx): (Sender<DemiBuffer>, Receiver<DemiBuffer>) = crossbeam_channel::unbounded();
let (bob_tx, bob_rx): (Sender<DemiBuffer>, Receiver<DemiBuffer>) = crossbeam_channel::unbounded();
let bob_barrier: Arc<Barrier> = Arc::new(Barrier::new(2));
let alice_barrier: Arc<Barrier> = bob_barrier.clone();
let alice: JoinHandle<Result<()>> = thread::spawn(move || {
let mut libos: DummyLibOS = match DummyLibOS::new_test(ALICE_CONFIG_PATH, alice_tx, bob_rx) {
Ok(libos) => libos,
Err(e) => anyhow::bail!("Could not create inetstack: {:?}", e),
};
let port: u16 = PORT_BASE;
let local: SocketAddr = SocketAddr::new(ALICE_IP, port);
// Open connection.
let sockqd: QDesc = safe_socket(&mut libos)?;
safe_bind(&mut libos, sockqd, local)?;
safe_listen(&mut libos, sockqd)?;
let qt: QToken = safe_accept(&mut libos, sockqd)?;
let (_, qr): (QDesc, OperationResult) = safe_wait(&mut libos, qt)?;
let qd: QDesc = match qr {
OperationResult::Accept((qd, addr)) if addr.ip() == &BOB_IP => qd,
_ => {
// Close socket if error.
// FIXME: https://github.com/demikernel/demikernel/issues/633
anyhow::bail!("accept() has failed")
},
};
// Pop data.
let qt: QToken = safe_pop(&mut libos, qd)?;
let (qd, qr): (QDesc, OperationResult) = safe_wait(&mut libos, qt)?;
match qr {
OperationResult::Pop(_, _) => (),
_ => {
// Close socket if error.
// FIXME: https://github.com/demikernel/demikernel/issues/633
anyhow::bail!("pop() has has failed {:?}", qr)
},
}
// Close connection.
safe_close_active(&mut libos, qd)?;
safe_close_passive(&mut libos, sockqd)?;
alice_barrier.wait();
Ok(())
});
let bob: JoinHandle<Result<()>> = thread::spawn(move || {
let mut libos: DummyLibOS = match DummyLibOS::new_test(BOB_CONFIG_PATH, bob_tx, alice_rx) {
Ok(libos) => libos,
Err(e) => anyhow::bail!("Could not create inetstack: {:?}", e),
};
let port: u16 = PORT_BASE;
let remote: SocketAddr = SocketAddr::new(ALICE_IP, port);
// Open connection.
let sockqd: QDesc = safe_socket(&mut libos)?;
let qt: QToken = safe_connect(&mut libos, sockqd, remote)?;
let (_, qr): (QDesc, OperationResult) = safe_wait(&mut libos, qt)?;
match qr {
OperationResult::Connect => (),
_ => {
// Close socket if error.
// FIXME: https://github.com/demikernel/demikernel/issues/633
anyhow::bail!("connect() has failed")
},
}
// Cook some data and push to a bad socket.
let bytes = libos.cook_data(32)?;
match libos.push(QDesc::from(2), &bytes) {
Ok(_) => {
// Close socket if not error because this test cannot continue.
// FIXME: https://github.com/demikernel/demikernel/issues/633
anyhow::bail!("push() to bad socket should fail.")
},
Err(_) => (),
};
// Push bad data to socket.
let zero_bytes: [u8; 0] = [];
let buf: DemiBuffer = match DemiBuffer::from_slice(&zero_bytes) {
Ok(buf) => buf,
Err(e) => anyhow::bail!("(zero-byte) slice should fit in a DemiBuffer: {:?}", e),
};
let data: demi_sgarray_t = libos.get_transport().into_sgarray(buf)?;
match libos.push(sockqd, &data) {
Ok(_) =>
// Close socket if not error because this test cannot continue.
// FIXME: https://github.com/demikernel/demikernel/issues/633
{
anyhow::bail!("push() zero-length slice should fail.")
},
Err(_) => (),
};
// Push data.
let bytes = libos.cook_data(32)?;
let qt: QToken = safe_push(&mut libos, sockqd, bytes)?;
let (_, qr): (QDesc, OperationResult) = safe_wait(&mut libos, qt)?;
match qr {
OperationResult::Push => (),
_ => {
// Close socket if error.
// FIXME: https://github.com/demikernel/demikernel/issues/633
anyhow::bail!("push() has failed")
},
}
// Close connection.
safe_close_active(&mut libos, sockqd)?;
bob_barrier.wait();
Ok(())
});
// It is safe to use unwrap here because there should not be any reason that we can't join the thread and if there
// is, there is nothing to clean up here on the main thread.
alice.join().unwrap()?;
bob.join().unwrap()?;
Ok(())
}
//======================================================================================================================
// Bad Pop
//======================================================================================================================
/// Tests bad calls to `pop()`.
#[test]
fn tcp_bad_pop() -> Result<()> {
let (alice_tx, alice_rx): (Sender<DemiBuffer>, Receiver<DemiBuffer>) = crossbeam_channel::unbounded();
let (bob_tx, bob_rx): (Sender<DemiBuffer>, Receiver<DemiBuffer>) = crossbeam_channel::unbounded();
let bob_barrier: Arc<Barrier> = Arc::new(Barrier::new(2));
let alice_barrier: Arc<Barrier> = bob_barrier.clone();
let alice: JoinHandle<Result<()>> = thread::spawn(move || {
let mut libos: DummyLibOS = match DummyLibOS::new_test(ALICE_CONFIG_PATH, alice_tx, bob_rx) {
Ok(libos) => libos,
Err(e) => anyhow::bail!("Could not create inetstack: {:?}", e),
};
let port: u16 = PORT_BASE;
let local: SocketAddr = SocketAddr::new(ALICE_IP, port);
// Open connection.
let sockqd: QDesc = safe_socket(&mut libos)?;
safe_bind(&mut libos, sockqd, local)?;
safe_listen(&mut libos, sockqd)?;
let qt: QToken = safe_accept(&mut libos, sockqd)?;
let (_, qr): (QDesc, OperationResult) = safe_wait(&mut libos, qt)?;
let qd: QDesc = match qr {
OperationResult::Accept((qd, addr)) if addr.ip() == &BOB_IP => qd,
_ => {
// Close socket if error.
// FIXME: https://github.com/demikernel/demikernel/issues/633
anyhow::bail!("accept() has failed")
},
};
// Pop from bad socket.
match libos.pop(QDesc::from(2), None) {
Ok(_) => {
// Close socket if not error.
// FIXME: https://github.com/demikernel/demikernel/issues/633
anyhow::bail!("pop() form bad socket should fail.")
},
Err(_) => (),
};
// Pop data.
let qt: QToken = safe_pop(&mut libos, qd)?;
let (qd, qr): (QDesc, OperationResult) = safe_wait(&mut libos, qt)?;
match qr {
OperationResult::Pop(_, _) => (),
_ => {
// Close socket if error.
// FIXME: https://github.com/demikernel/demikernel/issues/633
anyhow::bail!("pop() has has failed {:?}", qr)
},
}
// Close connection.
safe_close_active(&mut libos, qd)?;
safe_close_passive(&mut libos, sockqd)?;
alice_barrier.wait();
Ok(())
});
let bob: JoinHandle<Result<()>> = thread::spawn(move || {
let mut libos: DummyLibOS = match DummyLibOS::new_test(BOB_CONFIG_PATH, bob_tx, alice_rx) {
Ok(libos) => libos,
Err(e) => anyhow::bail!("Could not create inetstack: {:?}", e),
};
let port: u16 = PORT_BASE;
let remote: SocketAddr = SocketAddr::new(ALICE_IP, port);
// Open connection.
let sockqd: QDesc = safe_socket(&mut libos)?;
let qt: QToken = safe_connect(&mut libos, sockqd, remote)?;
let (_, qr): (QDesc, OperationResult) = safe_wait(&mut libos, qt)?;
match qr {
OperationResult::Connect => (),
_ => {
// Close socket if error.
// FIXME: https://github.com/demikernel/demikernel/issues/633
anyhow::bail!("connect() has failed")
},
}
// Cook some data and push data.
let bytes = libos.cook_data(32)?;
let qt: QToken = safe_push(&mut libos, sockqd, bytes)?;
let (_, qr): (QDesc, OperationResult) = safe_wait(&mut libos, qt)?;
match qr {
OperationResult::Push => (),
_ => {
// Close socket if error.
// FIXME: https://github.com/demikernel/demikernel/issues/633
anyhow::bail!("push() has failed")
},
}
// Close connection.
safe_close_active(&mut libos, sockqd)?;
bob_barrier.wait();
Ok(())
});
// It is safe to use unwrap here because there should not be any reason that we can't join the thread and if there
// is, there is nothing to clean up here on the main thread.
alice.join().unwrap()?;
bob.join().unwrap()?;
Ok(())
}
//======================================================================================================================
// Standalone Functions
//======================================================================================================================
/// Safe call to `socket()`.
fn safe_socket(libos: &mut DummyLibOS) -> Result<QDesc> {
match libos.socket(Domain::IPV4, Type::STREAM, Protocol::TCP) {
Ok(sockqd) => Ok(sockqd),
Err(e) => anyhow::bail!("failed to create socket: {:?}", e),
}
}
/// Safe call to `connect()`.
fn safe_connect(libos: &mut DummyLibOS, sockqd: QDesc, remote: SocketAddr) -> Result<QToken> {
match libos.connect(sockqd, remote) {
Ok(qt) => Ok(qt),
Err(e) => {
// Close socket on error.
// FIXME: https://github.com/demikernel/demikernel/issues/633
anyhow::bail!("failed to establish connection: {:?}", e)
},
}
}
/// Safe call to `bind()`.
fn safe_bind(libos: &mut DummyLibOS, sockqd: QDesc, local: SocketAddr) -> Result<()> {
match libos.bind(sockqd, local) {
Ok(_) => Ok(()),
Err(e) => {
// Close socket on error.
// FIXME: https://github.com/demikernel/demikernel/issues/633
anyhow::bail!("bind() failed: {:?}", e)
},
}
}
/// Safe call to `listen()`.
fn safe_listen(libos: &mut DummyLibOS, sockqd: QDesc) -> Result<()> {
match libos.listen(sockqd, SOMAXCONN as usize) {
Ok(_) => Ok(()),
Err(e) => {
// Close socket on error.
// FIXME: https://github.com/demikernel/demikernel/issues/633
anyhow::bail!("listen() failed: {:?}", e)
},
}
}
/// Safe call to `accept()`.
fn safe_accept(libos: &mut DummyLibOS, sockqd: QDesc) -> Result<QToken> {
match libos.accept(sockqd) {
Ok(qt) => Ok(qt),
Err(e) => {
// Close socket on error.
// FIXME: https://github.com/demikernel/demikernel/issues/633
anyhow::bail!("accept() failed: {:?}", e)
},
}
}
/// Safe call to `pop()`.
fn safe_pop(libos: &mut DummyLibOS, qd: QDesc) -> Result<QToken> {
match libos.pop(qd, None) {
Ok(qt) => Ok(qt),
Err(e) => {
// Close socket on error.
// FIXME: https://github.com/demikernel/demikernel/issues/633
anyhow::bail!("pop() failed: {:?}", e)
},
}
}
/// Safe call to `push()`
fn safe_push(libos: &mut DummyLibOS, sockqd: QDesc, bytes: demi_sgarray_t) -> Result<QToken> {
match libos.push(sockqd, &bytes) {
Ok(qt) => Ok(qt),
Err(e) => {
// Close socket on error.
// FIXME: https://github.com/demikernel/demikernel/issues/633
anyhow::bail!("failed to push: {:?}", e)
},
}
}
/// Safe call to `wait2()`.
fn safe_wait(libos: &mut DummyLibOS, qt: QToken) -> Result<(QDesc, OperationResult)> {
// Set this to something reasonably high because it should eventually complete.
match libos.wait(qt, Some(DEFAULT_TIMEOUT)) {
Ok(result) => Ok(result),
Err(e) => anyhow::bail!("wait failed: {:?}", e),
}
}
/// Safe call to `close()` on passive socket.
fn safe_close_passive(libos: &mut DummyLibOS, sockqd: QDesc) -> Result<(QDesc, OperationResult)> {
match libos.async_close(sockqd) {
Ok(qt) => safe_wait(libos, qt),
Err(_) => anyhow::bail!("close() on passive socket has failed"),
}
}
/// Safe call to `close()` on active socket.
fn safe_close_active(libos: &mut DummyLibOS, qd: QDesc) -> Result<(QDesc, OperationResult)> {
match libos.async_close(qd) {
Ok(qt) => safe_wait(libos, qt),
Err(_) => anyhow::bail!("close() on active socket has failed"),
}
}
}