-
Notifications
You must be signed in to change notification settings - Fork 214
Implement stream based socket #35
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
| pub struct Socket { | ||
| base: KObjectBase, | ||
| peer: Weak<Socket>, | ||
| lock: Arc<Mutex<u8>>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个 lock 的作用和目的是啥?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
同时给自己和peer上锁,以防两个线程同时操作self 和 peer导致的死锁
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
我简单看了一下,似乎没发现有同时 lock self 和 peer 的情况。
所以应该可以去掉吧?测试的时候发生过死锁吗?
| read_disabled: bool, | ||
| read_threshold: usize, | ||
| write_threshold: usize, // only for core-test | ||
| data: Vec<u8>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
是不是用 VecDeque 更好?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
是的,但是我没找到deque里下面这段代码的对应写法
let data = if options.contains(SocketOptions::PEEK) {
Vec::from_iter(inner.data[0..size].iter().cloned())
}There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
对,因为VecDeque里面是个ringbuffer,不像Vec一样保证数据连续,而是可能分成前后两段。它有一个 as_slices 方法可以干这件事:
pub fn as_slices(&self) -> (&[T], &[T])就是处理起来稍微麻烦一些(
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
好的,我去改
Implement stream based socket
Pull Request Test Coverage Report for Build 103839393Warning: This coverage report may be inaccurate.This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.
Details
💛 - Coveralls |
Pass 16/26 of SocketTest
The main fail reasons are: