File tree Expand file tree Collapse file tree 3 files changed +55
-32
lines changed Expand file tree Collapse file tree 3 files changed +55
-32
lines changed Original file line number Diff line number Diff line change 1010//! connect, and don't clone it out of the future.
1111use std:: {
1212 collections:: { HashMap , VecDeque } ,
13+ ops:: Deref ,
1314 sync:: Arc ,
1415 time:: Duration ,
1516} ;
@@ -30,7 +31,7 @@ use tokio::{
3031use tokio_util:: time:: FutureExt as TimeFutureExt ;
3132use tracing:: { debug, error, trace} ;
3233
33- use crate :: { ConnectionCounter , ConnectionRef } ;
34+ use crate :: { ConnectionCounter , OneConnection } ;
3435
3536/// Configuration options for the connection pool
3637#[ derive( Debug , Clone , Copy ) ]
@@ -50,6 +51,30 @@ impl Default for Options {
5051 }
5152}
5253
54+ /// A reference to a connection that is owned by a connection pool.
55+ #[ derive( Debug ) ]
56+ pub struct ConnectionRef {
57+ connection : iroh:: endpoint:: Connection ,
58+ _permit : OneConnection ,
59+ }
60+
61+ impl Deref for ConnectionRef {
62+ type Target = iroh:: endpoint:: Connection ;
63+
64+ fn deref ( & self ) -> & Self :: Target {
65+ & self . connection
66+ }
67+ }
68+
69+ impl ConnectionRef {
70+ fn new ( connection : iroh:: endpoint:: Connection , counter : OneConnection ) -> Self {
71+ Self {
72+ connection,
73+ _permit : counter,
74+ }
75+ }
76+ }
77+
5378struct Context {
5479 options : Options ,
5580 endpoint : Endpoint ,
Original file line number Diff line number Diff line change 1010//! [blog post](https://www.iroh.computer/blog/0rtt-api).
1111use std:: {
1212 collections:: { HashMap , VecDeque } ,
13+ ops:: Deref ,
1314 pin:: Pin ,
1415 sync:: Arc ,
1516 task:: Poll ,
@@ -33,7 +34,7 @@ use tokio::{
3334use tokio_util:: time:: FutureExt as TimeFutureExt ;
3435use tracing:: { debug, error, trace} ;
3536
36- use crate :: { ConnectionCounter , ConnectionRef } ;
37+ use crate :: { ConnectionCounter , OneConnection } ;
3738
3839/// Configuration options for the connection pool
3940#[ derive( Debug , Clone , Copy ) ]
@@ -53,6 +54,30 @@ impl Default for Options {
5354 }
5455}
5556
57+ /// A reference to a connection that is owned by a connection pool.
58+ #[ derive( Debug ) ]
59+ pub struct ConnectionRef {
60+ connection : iroh:: endpoint:: Connection ,
61+ _permit : OneConnection ,
62+ }
63+
64+ impl Deref for ConnectionRef {
65+ type Target = iroh:: endpoint:: Connection ;
66+
67+ fn deref ( & self ) -> & Self :: Target {
68+ & self . connection
69+ }
70+ }
71+
72+ impl ConnectionRef {
73+ fn new ( connection : iroh:: endpoint:: Connection , counter : OneConnection ) -> Self {
74+ Self {
75+ connection,
76+ _permit : counter,
77+ }
78+ }
79+ }
80+
5681struct Context {
5782 options : Options ,
5883 endpoint : Endpoint ,
Original file line number Diff line number Diff line change 1- use std:: {
2- ops:: Deref ,
3- sync:: {
4- Arc ,
5- atomic:: { AtomicUsize , Ordering } ,
6- } ,
1+ use std:: sync:: {
2+ Arc ,
3+ atomic:: { AtomicUsize , Ordering } ,
74} ;
85
96use n0_future:: Stream ;
@@ -15,30 +12,6 @@ pub mod connection_pool_0rtt;
1512#[ cfg( test) ]
1613mod tests;
1714
18- /// A reference to a connection that is owned by a connection pool.
19- #[ derive( Debug ) ]
20- pub struct ConnectionRef {
21- connection : iroh:: endpoint:: Connection ,
22- _permit : OneConnection ,
23- }
24-
25- impl Deref for ConnectionRef {
26- type Target = iroh:: endpoint:: Connection ;
27-
28- fn deref ( & self ) -> & Self :: Target {
29- & self . connection
30- }
31- }
32-
33- impl ConnectionRef {
34- fn new ( connection : iroh:: endpoint:: Connection , counter : OneConnection ) -> Self {
35- Self {
36- connection,
37- _permit : counter,
38- }
39- }
40- }
41-
4215#[ derive( Debug ) ]
4316struct ConnectionCounterInner {
4417 count : AtomicUsize ,
You can’t perform that action at this time.
0 commit comments