Skip to content

Conversation

@heheda12345
Copy link
Contributor

Pass 16/26 of SocketTest

The main fail reasons are:

  1. Datagram based socket is not implemented
  2. The buffer size of the socket is unlimited

@wangrunji0408 wangrunji0408 self-requested a review May 13, 2020 17:44
@wangrunji0408 wangrunji0408 self-assigned this May 13, 2020
@wangrunji0408 wangrunji0408 added the enhancement New feature or request label May 13, 2020
pub struct Socket {
base: KObjectBase,
peer: Weak<Socket>,
lock: Arc<Mutex<u8>>,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个 lock 的作用和目的是啥?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

同时给自己和peer上锁,以防两个线程同时操作self 和 peer导致的死锁

Copy link
Member

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>,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

是不是用 VecDeque 更好?

Copy link
Contributor Author

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())
}

Copy link
Member

@wangrunji0408 wangrunji0408 May 14, 2020

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])

就是处理起来稍微麻烦一些(

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

好的,我去改

@wangrunji0408 wangrunji0408 merged commit 35ec874 into rcore-os:master May 14, 2020
zhangsn-19 pushed a commit to zhangsn-19/zCore that referenced this pull request Apr 23, 2022
@coveralls
Copy link

coveralls commented Jul 14, 2024

Pull Request Test Coverage Report for Build 103839393

Warning: 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

  • 3 of 497 (0.6%) changed or added relevant lines in 16 files are covered.
  • 60 unchanged lines in 5 files lost coverage.
  • Overall coverage decreased (-1.5%) to 22.176%

Changes Missing Coverage Covered Lines Changed/Added Lines %
zircon-syscall/src/port.rs 0 1 0.0%
zircon-syscall/src/time.rs 0 3 0.0%
kernel-hal-bare/src/arch/x86_64/mod.rs 0 4 0.0%
zircon-object/src/dev/interrupt/virtual_interrupt.rs 0 6 0.0%
zircon-object/src/signal/port_packet.rs 0 6 0.0%
zircon-object/src/task/thread.rs 0 7 0.0%
kernel-hal/src/dummy.rs 0 8 0.0%
zircon-object/src/dev/resource.rs 0 12 0.0%
kernel-hal-bare/src/arch/x86_64/interrupt.rs 0 23 0.0%
zircon-object/src/dev/interrupt/event_interrupt.rs 0 24 0.0%
Files with Coverage Reduction New Missed Lines %
zircon-object/src/signal/port_packet.rs 1 24.39%
zircon-object/src/signal/port.rs 1 22.92%
kernel-hal-bare/src/arch/x86_64/mod.rs 5 0.0%
kernel-hal-bare/src/arch/x86_64/interrupt.rs 21 0.0%
../../../../../usr/share/rust/.cargo/registry/src/github.com-1ecc6299db9ec823/numeric-enum-macro-0.2.0/src/lib.rs 32 0.0%
Totals Coverage Status
Change from base Build 102173235: -1.5%
Covered Lines: 1702
Relevant Lines: 7675

💛 - Coveralls

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants