You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
SimplexStream is basically a bytes::BytesMut, its read cursor is stored as a pointer, and appending to it can trigger re-allocation, which will invalidate the stored pointer, then a segfault would happen if such an invalidated pointer is accessed. So SimplexStream should not implement the unsafe trait Split.
Tokio's split() and read/write halves do not use UnsafeCell, instead, it uses std::sync::Mutex to ensure read and write to the type instance won't happen at the same time, this explains why it can blindly do the split operation to anything that has AsyncRead + AsyncWrite implemented:
For a type that implements
unsafe trait Split
, when being split into 2 read/write halves, Monoio usesUnsafeCell
internally to acquire mutable access to the type instance, this is the reason whytrait Split
is unsafe. It would be only safe if your type can support read/write at the same time.SimplexStream
is basically abytes::BytesMut
, its read cursor is stored as a pointer, and appending to it can trigger re-allocation, which will invalidate the stored pointer, then a segfault would happen if such an invalidated pointer is accessed. SoSimplexStream
should not implement theunsafe trait Split
.Tokio's
split()
and read/write halves do not useUnsafeCell
, instead, it usesstd::sync::Mutex
to ensure read and write to the type instance won't happen at the same time, this explains why it can blindly do the split operation to anything that hasAsyncRead + AsyncWrite
implemented:The text was updated successfully, but these errors were encountered: