rcore-os / rCore

Rust version of THU uCore OS. Linux compatible.
MIT License
3.43k stars 369 forks source link

[Bug Report] wrong of fn write in the TcpSocketState #69

Closed dingiso closed 3 years ago

dingiso commented 3 years ago

I think there are something wrong within the fn write in the TcpSocketState, Code below:

fn write(&self, data: &[u8], _sendto_endpoint: Option<Endpoint>) -> SysResult {
        // get the lock and handle of the global SOCKETS
        let mut sockets = SOCKETS.lock();
        let mut socket = sockets.get::<TcpSocket>(self.handle.0);

        if socket.is_open() {
            if socket.can_send() {
                match socket.send_slice(&data) {
                    Ok(size) => {
                        // avoid deadlock
                        drop(socket);
                        drop(sockets);

                        poll_ifaces();
                        Ok(size)
                    }
                    Err(_) => Err(SysError::ENOBUFS),
                }
            } else {
                Err(SysError::ENOBUFS)
            }
        } else {
            Err(SysError::ENOTCONN)
        }
    }

Withourt using the second parameter _sendto_endpoint
I'm considering that there maybe some problems , the parameter is not necessary , tcp first bind and connect with a endpoint which ensure the data transfer to the endpoint

jiegec commented 3 years ago

I'm considering that there maybe some problems , the parameter is not necessary , tcp first bind and connect with a endpoint which ensure the data transfer to the endpoint

That's why the endpoint parameter is not used. It is saved in socket. The endpoint is here because the trait requires it, and UDP uses that.

dingiso commented 3 years ago

Thank you , I understand it !!