You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@nuttx.apache.org by Jernej Turnsek <je...@gmail.com> on 2022/11/03 17:10:14 UTC

fcntl(fd, F_SETFL, O_NONBLOCK) on Local Socket not working

Hi,

I am trying to set O_NONBLOCK flag with the help of fcntl on Local Socket
structure (AF_UNIX) and I am not getting the non blocking functionality. If
setting the SOCK_NONBLOCK flag while creating the socket, it is working
fine. I am using some Linux based code, where this functionality is
working. Is this a bug?

Regards,
Jernej

Re: fcntl(fd, F_SETFL, O_NONBLOCK) on Local Socket not working

Posted by Jernej Turnsek <je...@gmail.com>.
I already have this commit in my branch.

My solution was:

static int local_ioctl(FAR struct socket *psock, int cmd, unsigned long arg)
{
  FAR struct local_conn_s *conn;
  int ret = -ENOTTY; // before was OK

  conn = (FAR struct local_conn_s *)psock->s_conn;

  switch (cmd)
    {
      case FIONBIO:
        if (conn->lc_infile.f_inode != NULL) // in my case this evaluate to
false
          {
            ret = file_ioctl(&conn->lc_infile, cmd, arg);
          }

        if (ret >= 0 && conn->lc_outfile.f_inode != NULL)  // in my case
this evaluate to false
          {
            ret = file_ioctl(&conn->lc_outfile, cmd, arg);
          }
        break;
      case FIONREAD:
        if (conn->lc_infile.f_inode != NULL)
          {
            ret = file_ioctl(&conn->lc_infile, cmd, arg);
          }
        else
          {
            ret = -ENOTCONN;
          }
        break;
      case FIONSPACE:
        if (conn->lc_outfile.f_inode != NULL)
          {
            ret = file_ioctl(&conn->lc_outfile, cmd, arg);
          }
        else
          {
            ret = -ENOTCONN;
          }
        break;
      default:
        ret = -ENOTTY;
        break;
    }

  return ret; // before was returning OK, now -ENOTTY
}

Function local_ioctl is called from  netdev_ioctl and if this
function returns -ENOTTY, then netdev_file_ioctl is called next, which is
then responsible to set s_flags for the socket.


On Fri, Nov 4, 2022 at 3:42 AM Xiang Xiao <xi...@gmail.com> wrote:

> In the old design, the driver/socket needed to return -ENOTTY to activate
> the default action(in file_vioctl) even if they handle O_NONBLOCK
> internally. This approach confuses many people and introduces the error you
> hit several times.
> So https://github.com/apache/incubator-nuttx/pull/6976 fixes this problem:
> the default action is activated when driver/socket return either OK or
> -ENOTTY.
> I suggest you cherry-pick this patch to enter the final solution.
>
> On Fri, Nov 4, 2022 at 3:00 AM Jernej Turnsek <je...@gmail.com>
> wrote:
>
> > I think I have a fix to this problem. If I change the initialization
> > value of the variable ret in function local_ioctl (file local_sockif.c)
> > from OK to -ENOTTY (like the fix in netdev_ioctl), it starts to work in
> my
> > case. I think it should not be a problem for other cases. What do you
> > think?
> >
> > On Thu, Nov 3, 2022 at 7:04 PM Xiang Xiao <xi...@gmail.com>
> > wrote:
> >
> > > Does your branch contain this patch?
> > > https://github.com/apache/incubator-nuttx/pull/5933
> > >
> > > On Fri, Nov 4, 2022 at 1:11 AM Jernej Turnsek <
> jernej.turnsek@gmail.com>
> > > wrote:
> > >
> > > > Hi,
> > > >
> > > > I am trying to set O_NONBLOCK flag with the help of fcntl on Local
> > Socket
> > > > structure (AF_UNIX) and I am not getting the non blocking
> > functionality.
> > > If
> > > > setting the SOCK_NONBLOCK flag while creating the socket, it is
> working
> > > > fine. I am using some Linux based code, where this functionality is
> > > > working. Is this a bug?
> > > >
> > > > Regards,
> > > > Jernej
> > > >
> > >
> >
>

Re: fcntl(fd, F_SETFL, O_NONBLOCK) on Local Socket not working

Posted by Xiang Xiao <xi...@gmail.com>.
In the old design, the driver/socket needed to return -ENOTTY to activate
the default action(in file_vioctl) even if they handle O_NONBLOCK
internally. This approach confuses many people and introduces the error you
hit several times.
So https://github.com/apache/incubator-nuttx/pull/6976 fixes this problem:
the default action is activated when driver/socket return either OK or
-ENOTTY.
I suggest you cherry-pick this patch to enter the final solution.

On Fri, Nov 4, 2022 at 3:00 AM Jernej Turnsek <je...@gmail.com>
wrote:

> I think I have a fix to this problem. If I change the initialization
> value of the variable ret in function local_ioctl (file local_sockif.c)
> from OK to -ENOTTY (like the fix in netdev_ioctl), it starts to work in my
> case. I think it should not be a problem for other cases. What do you
> think?
>
> On Thu, Nov 3, 2022 at 7:04 PM Xiang Xiao <xi...@gmail.com>
> wrote:
>
> > Does your branch contain this patch?
> > https://github.com/apache/incubator-nuttx/pull/5933
> >
> > On Fri, Nov 4, 2022 at 1:11 AM Jernej Turnsek <je...@gmail.com>
> > wrote:
> >
> > > Hi,
> > >
> > > I am trying to set O_NONBLOCK flag with the help of fcntl on Local
> Socket
> > > structure (AF_UNIX) and I am not getting the non blocking
> functionality.
> > If
> > > setting the SOCK_NONBLOCK flag while creating the socket, it is working
> > > fine. I am using some Linux based code, where this functionality is
> > > working. Is this a bug?
> > >
> > > Regards,
> > > Jernej
> > >
> >
>

Re: fcntl(fd, F_SETFL, O_NONBLOCK) on Local Socket not working

Posted by Jernej Turnsek <je...@gmail.com>.
I think I have a fix to this problem. If I change the initialization
value of the variable ret in function local_ioctl (file local_sockif.c)
from OK to -ENOTTY (like the fix in netdev_ioctl), it starts to work in my
case. I think it should not be a problem for other cases. What do you think?

On Thu, Nov 3, 2022 at 7:04 PM Xiang Xiao <xi...@gmail.com> wrote:

> Does your branch contain this patch?
> https://github.com/apache/incubator-nuttx/pull/5933
>
> On Fri, Nov 4, 2022 at 1:11 AM Jernej Turnsek <je...@gmail.com>
> wrote:
>
> > Hi,
> >
> > I am trying to set O_NONBLOCK flag with the help of fcntl on Local Socket
> > structure (AF_UNIX) and I am not getting the non blocking functionality.
> If
> > setting the SOCK_NONBLOCK flag while creating the socket, it is working
> > fine. I am using some Linux based code, where this functionality is
> > working. Is this a bug?
> >
> > Regards,
> > Jernej
> >
>

Re: fcntl(fd, F_SETFL, O_NONBLOCK) on Local Socket not working

Posted by Jernej Turnsek <je...@gmail.com>.
My branch is not the latest one, but I have checked the code which PR is
fixing and I have the latest one. I think the problem is with the
local_ioctl function, where there is no code to properly set s_flags in
case of FIONBIO.

On Thu, Nov 3, 2022 at 7:04 PM Xiang Xiao <xi...@gmail.com> wrote:

> Does your branch contain this patch?
> https://github.com/apache/incubator-nuttx/pull/5933
>
> On Fri, Nov 4, 2022 at 1:11 AM Jernej Turnsek <je...@gmail.com>
> wrote:
>
> > Hi,
> >
> > I am trying to set O_NONBLOCK flag with the help of fcntl on Local Socket
> > structure (AF_UNIX) and I am not getting the non blocking functionality.
> If
> > setting the SOCK_NONBLOCK flag while creating the socket, it is working
> > fine. I am using some Linux based code, where this functionality is
> > working. Is this a bug?
> >
> > Regards,
> > Jernej
> >
>

Re: fcntl(fd, F_SETFL, O_NONBLOCK) on Local Socket not working

Posted by Xiang Xiao <xi...@gmail.com>.
Does your branch contain this patch?
https://github.com/apache/incubator-nuttx/pull/5933

On Fri, Nov 4, 2022 at 1:11 AM Jernej Turnsek <je...@gmail.com>
wrote:

> Hi,
>
> I am trying to set O_NONBLOCK flag with the help of fcntl on Local Socket
> structure (AF_UNIX) and I am not getting the non blocking functionality. If
> setting the SOCK_NONBLOCK flag while creating the socket, it is working
> fine. I am using some Linux based code, where this functionality is
> working. Is this a bug?
>
> Regards,
> Jernej
>