@@ -983,73 +983,90 @@ pub enum OpenStreamError {
983
983
984
984
#[ cfg( feature = "h3" ) ]
985
985
pub ( crate ) mod h3_impl {
986
- use compio_buf:: bytes:: { Buf , BytesMut } ;
986
+ use compio_buf:: bytes:: Buf ;
987
987
use futures_util:: ready;
988
988
use h3:: {
989
989
error:: Code ,
990
- quic:: { self , Error , WriteBuf } ,
990
+ quic:: { self , ConnectionErrorIncoming , StreamErrorIncoming , WriteBuf } ,
991
991
} ;
992
992
use h3_datagram:: {
993
- datagram:: Datagram ,
994
- quic_traits:: { RecvDatagramExt , SendDatagramExt } ,
993
+ datagram:: EncodedDatagram ,
994
+ quic_traits:: {
995
+ DatagramConnectionExt , RecvDatagram , SendDatagram , SendDatagramErrorIncoming ,
996
+ } ,
995
997
} ;
996
998
997
999
use super :: * ;
998
- use crate :: { ReadError , WriteError , send_stream:: h3_impl:: SendStream } ;
999
-
1000
- impl Error for ConnectionError {
1001
- fn is_timeout ( & self ) -> bool {
1002
- matches ! ( self , ConnectionError :: TimedOut )
1003
- }
1000
+ use crate :: send_stream:: h3_impl:: SendStream ;
1001
+
1002
+ impl From < ConnectionError > for ConnectionErrorIncoming {
1003
+ fn from ( e : ConnectionError ) -> Self {
1004
+ use ConnectionError :: * ;
1005
+ match e {
1006
+ ApplicationClosed ( e) => Self :: ApplicationClose {
1007
+ error_code : e. error_code . into_inner ( ) ,
1008
+ } ,
1009
+ TimedOut => Self :: Timeout ,
1004
1010
1005
- fn err_code ( & self ) -> Option < u64 > {
1006
- match & self {
1007
- ConnectionError :: ApplicationClosed ( quinn_proto:: ApplicationClose {
1008
- error_code,
1009
- ..
1010
- } ) => Some ( error_code. into_inner ( ) ) ,
1011
- _ => None ,
1011
+ e => Self :: Undefined ( Arc :: new ( e) ) ,
1012
1012
}
1013
1013
}
1014
1014
}
1015
1015
1016
- impl Error for SendDatagramError {
1017
- fn is_timeout ( & self ) -> bool {
1018
- false
1016
+ impl From < ConnectionError > for StreamErrorIncoming {
1017
+ fn from ( e : ConnectionError ) -> Self {
1018
+ Self :: ConnectionErrorIncoming {
1019
+ connection_error : e. into ( ) ,
1020
+ }
1019
1021
}
1022
+ }
1020
1023
1021
- fn err_code ( & self ) -> Option < u64 > {
1022
- match self {
1023
- SendDatagramError :: ConnectionLost ( ConnectionError :: ApplicationClosed (
1024
- quinn_proto:: ApplicationClose { error_code, .. } ,
1025
- ) ) => Some ( error_code. into_inner ( ) ) ,
1026
- _ => None ,
1024
+ impl From < SendDatagramError > for SendDatagramErrorIncoming {
1025
+ fn from ( e : SendDatagramError ) -> Self {
1026
+ use SendDatagramError :: * ;
1027
+ match e {
1028
+ UnsupportedByPeer | Disabled => Self :: NotAvailable ,
1029
+ TooLarge => Self :: TooLarge ,
1030
+ ConnectionLost ( e) => Self :: ConnectionError ( e. into ( ) ) ,
1027
1031
}
1028
1032
}
1029
1033
}
1030
1034
1031
- impl < B > SendDatagramExt < B > for Connection
1035
+ impl < B > SendDatagram < B > for Connection
1032
1036
where
1033
1037
B : Buf ,
1034
1038
{
1035
- type Error = SendDatagramError ;
1036
-
1037
- fn send_datagram ( & mut self , data : Datagram < B > ) -> Result < ( ) , Self :: Error > {
1038
- let mut buf = BytesMut :: new ( ) ;
1039
- data. encode ( & mut buf) ;
1040
- Connection :: send_datagram ( self , buf. freeze ( ) )
1039
+ fn send_datagram < T : Into < EncodedDatagram < B > > > (
1040
+ & mut self ,
1041
+ data : T ,
1042
+ ) -> Result < ( ) , SendDatagramErrorIncoming > {
1043
+ let mut buf: EncodedDatagram < B > = data. into ( ) ;
1044
+ let buf = buf. copy_to_bytes ( buf. remaining ( ) ) ;
1045
+ Ok ( Connection :: send_datagram ( self , buf) ?)
1041
1046
}
1042
1047
}
1043
1048
1044
- impl RecvDatagramExt for Connection {
1045
- type Buf = Bytes ;
1046
- type Error = ConnectionError ;
1049
+ impl RecvDatagram for Connection {
1050
+ type Buffer = Bytes ;
1047
1051
1048
- fn poll_accept_datagram (
1052
+ fn poll_incoming_datagram (
1049
1053
& mut self ,
1050
- cx : & mut Context < ' _ > ,
1051
- ) -> Poll < Result < Option < Self :: Buf > , Self :: Error > > {
1052
- Poll :: Ready ( Ok ( Some ( ready ! ( self . poll_recv_datagram( cx) ) ?) ) )
1054
+ cx : & mut core:: task:: Context < ' _ > ,
1055
+ ) -> Poll < Result < Self :: Buffer , ConnectionErrorIncoming > > {
1056
+ Poll :: Ready ( Ok ( ready ! ( self . poll_recv_datagram( cx) ) ?) )
1057
+ }
1058
+ }
1059
+
1060
+ impl < B : Buf > DatagramConnectionExt < B > for Connection {
1061
+ type RecvDatagramHandler = Self ;
1062
+ type SendDatagramHandler = Self ;
1063
+
1064
+ fn send_datagram_handler ( & self ) -> Self :: SendDatagramHandler {
1065
+ self . clone ( )
1066
+ }
1067
+
1068
+ fn recv_datagram_handler ( & self ) -> Self :: RecvDatagramHandler {
1069
+ self . clone ( )
1053
1070
}
1054
1071
}
1055
1072
@@ -1085,12 +1102,11 @@ pub(crate) mod h3_impl {
1085
1102
B : Buf ,
1086
1103
{
1087
1104
type Buf = Bytes ;
1088
- type Error = ReadError ;
1089
1105
1090
1106
fn poll_data (
1091
1107
& mut self ,
1092
1108
cx : & mut Context < ' _ > ,
1093
- ) -> Poll < Result < Option < Self :: Buf > , Self :: Error > > {
1109
+ ) -> Poll < Result < Option < Self :: Buf > , StreamErrorIncoming > > {
1094
1110
self . recv . poll_data ( cx)
1095
1111
}
1096
1112
@@ -1107,17 +1123,15 @@ pub(crate) mod h3_impl {
1107
1123
where
1108
1124
B : Buf ,
1109
1125
{
1110
- type Error = WriteError ;
1111
-
1112
- fn poll_ready ( & mut self , cx : & mut Context < ' _ > ) -> Poll < Result < ( ) , Self :: Error > > {
1126
+ fn poll_ready ( & mut self , cx : & mut Context < ' _ > ) -> Poll < Result < ( ) , StreamErrorIncoming > > {
1113
1127
self . send . poll_ready ( cx)
1114
1128
}
1115
1129
1116
- fn send_data < T : Into < WriteBuf < B > > > ( & mut self , data : T ) -> Result < ( ) , Self :: Error > {
1130
+ fn send_data < T : Into < WriteBuf < B > > > ( & mut self , data : T ) -> Result < ( ) , StreamErrorIncoming > {
1117
1131
self . send . send_data ( data)
1118
1132
}
1119
1133
1120
- fn poll_finish ( & mut self , cx : & mut Context < ' _ > ) -> Poll < Result < ( ) , Self :: Error > > {
1134
+ fn poll_finish ( & mut self , cx : & mut Context < ' _ > ) -> Poll < Result < ( ) , StreamErrorIncoming > > {
1121
1135
self . send . poll_finish ( cx)
1122
1136
}
1123
1137
@@ -1138,7 +1152,7 @@ pub(crate) mod h3_impl {
1138
1152
& mut self ,
1139
1153
cx : & mut Context < ' _ > ,
1140
1154
buf : & mut D ,
1141
- ) -> Poll < Result < usize , Self :: Error > > {
1155
+ ) -> Poll < Result < usize , StreamErrorIncoming > > {
1142
1156
self . send . poll_send ( cx, buf)
1143
1157
}
1144
1158
}
@@ -1152,21 +1166,20 @@ pub(crate) mod h3_impl {
1152
1166
B : Buf ,
1153
1167
{
1154
1168
type BidiStream = BidiStream < B > ;
1155
- type OpenError = ConnectionError ;
1156
1169
type SendStream = SendStream < B > ;
1157
1170
1158
1171
fn poll_open_bidi (
1159
1172
& mut self ,
1160
1173
cx : & mut Context < ' _ > ,
1161
- ) -> Poll < Result < Self :: BidiStream , Self :: OpenError > > {
1174
+ ) -> Poll < Result < Self :: BidiStream , StreamErrorIncoming > > {
1162
1175
let ( stream, is_0rtt) = ready ! ( self . 0 . poll_open_stream( Some ( cx) , Dir :: Bi ) ) ?;
1163
1176
Poll :: Ready ( Ok ( BidiStream :: new ( self . 0 . 0 . clone ( ) , stream, is_0rtt) ) )
1164
1177
}
1165
1178
1166
1179
fn poll_open_send (
1167
1180
& mut self ,
1168
1181
cx : & mut Context < ' _ > ,
1169
- ) -> Poll < Result < Self :: SendStream , Self :: OpenError > > {
1182
+ ) -> Poll < Result < Self :: SendStream , StreamErrorIncoming > > {
1170
1183
let ( stream, is_0rtt) = ready ! ( self . 0 . poll_open_stream( Some ( cx) , Dir :: Uni ) ) ?;
1171
1184
Poll :: Ready ( Ok ( SendStream :: new ( self . 0 . 0 . clone ( ) , stream, is_0rtt) ) )
1172
1185
}
@@ -1182,21 +1195,20 @@ pub(crate) mod h3_impl {
1182
1195
B : Buf ,
1183
1196
{
1184
1197
type BidiStream = BidiStream < B > ;
1185
- type OpenError = ConnectionError ;
1186
1198
type SendStream = SendStream < B > ;
1187
1199
1188
1200
fn poll_open_bidi (
1189
1201
& mut self ,
1190
1202
cx : & mut Context < ' _ > ,
1191
- ) -> Poll < Result < Self :: BidiStream , Self :: OpenError > > {
1203
+ ) -> Poll < Result < Self :: BidiStream , StreamErrorIncoming > > {
1192
1204
let ( stream, is_0rtt) = ready ! ( self . poll_open_stream( Some ( cx) , Dir :: Bi ) ) ?;
1193
1205
Poll :: Ready ( Ok ( BidiStream :: new ( self . 0 . clone ( ) , stream, is_0rtt) ) )
1194
1206
}
1195
1207
1196
1208
fn poll_open_send (
1197
1209
& mut self ,
1198
1210
cx : & mut Context < ' _ > ,
1199
- ) -> Poll < Result < Self :: SendStream , Self :: OpenError > > {
1211
+ ) -> Poll < Result < Self :: SendStream , StreamErrorIncoming > > {
1200
1212
let ( stream, is_0rtt) = ready ! ( self . poll_open_stream( Some ( cx) , Dir :: Uni ) ) ?;
1201
1213
Poll :: Ready ( Ok ( SendStream :: new ( self . 0 . clone ( ) , stream, is_0rtt) ) )
1202
1214
}
@@ -1210,24 +1222,23 @@ pub(crate) mod h3_impl {
1210
1222
where
1211
1223
B : Buf ,
1212
1224
{
1213
- type AcceptError = ConnectionError ;
1214
1225
type OpenStreams = OpenStreams ;
1215
1226
type RecvStream = RecvStream ;
1216
1227
1217
1228
fn poll_accept_recv (
1218
1229
& mut self ,
1219
1230
cx : & mut std:: task:: Context < ' _ > ,
1220
- ) -> Poll < Result < Option < Self :: RecvStream > , Self :: AcceptError > > {
1231
+ ) -> Poll < Result < Self :: RecvStream , ConnectionErrorIncoming > > {
1221
1232
let ( stream, is_0rtt) = ready ! ( self . poll_accept_stream( cx, Dir :: Uni ) ) ?;
1222
- Poll :: Ready ( Ok ( Some ( RecvStream :: new ( self . 0 . clone ( ) , stream, is_0rtt) ) ) )
1233
+ Poll :: Ready ( Ok ( RecvStream :: new ( self . 0 . clone ( ) , stream, is_0rtt) ) )
1223
1234
}
1224
1235
1225
1236
fn poll_accept_bidi (
1226
1237
& mut self ,
1227
1238
cx : & mut std:: task:: Context < ' _ > ,
1228
- ) -> Poll < Result < Option < Self :: BidiStream > , Self :: AcceptError > > {
1239
+ ) -> Poll < Result < Self :: BidiStream , ConnectionErrorIncoming > > {
1229
1240
let ( stream, is_0rtt) = ready ! ( self . poll_accept_stream( cx, Dir :: Bi ) ) ?;
1230
- Poll :: Ready ( Ok ( Some ( BidiStream :: new ( self . 0 . clone ( ) , stream, is_0rtt) ) ) )
1241
+ Poll :: Ready ( Ok ( BidiStream :: new ( self . 0 . clone ( ) , stream, is_0rtt) ) )
1231
1242
}
1232
1243
1233
1244
fn opener ( & self ) -> Self :: OpenStreams {
0 commit comments