static int local_waitlisten(FAR struct local_conn_s *server)
{
    int ret;

    /* Loop until a connection is requested or we receive a signal */

    while (dq_empty(&server->u.server.lc_waiters))
    {
        /* No.. wait for a connection or a signal */

        ret = sem_wait(&server->lc_waitsem);
        if (ret < 0)
        {
            int errval = get_errno();
            DEBUGASSERT(errval == EINTR);
            return -errval;
        }
    }

    /* There is a client waiting for the connection */

    return OK;
}
void *
dq_peek_back(dqueue q)
{
	assert(!dq_empty(q));
	return q -> sentinel -> prev -> element;
}
void *
dq_deq_back(dqueue q)
{
	assert(!dq_empty(q));
	return unlink_and_free(q -> sentinel -> prev);
}
void *
dq_peek_front(dqueue q)
{
	assert(!dq_empty(q));
	return q -> sentinel -> next -> element;
}
void *
dq_deq_front(dqueue q)
{
	assert(!dq_empty(q));
	return unlink_and_free(q -> sentinel -> next);
}
int local_listen(FAR struct local_conn_s *server, int backlog)
{
  net_lock_t state;
  int ret;

  /* Some sanity checks */

  DEBUGASSERT(server);

  if (server->lc_proto != SOCK_STREAM ||
      server->lc_state == LOCAL_STATE_UNBOUND ||
      server->lc_type != LOCAL_TYPE_PATHNAME)
    {
      return -EOPNOTSUPP;
    }

  DEBUGASSERT(server->lc_state == LOCAL_STATE_BOUND ||
              server->lc_state == LOCAL_STATE_LISTENING);

  /* Set the backlog value */

  DEBUGASSERT((unsigned)backlog < 256);
  server->u.server.lc_backlog = backlog;

  /* Is this the first time since being bound to an address and that
   * listen() was called?  If so, the state should be LOCAL_STATE_BOUND.
   */

  if (server->lc_state == LOCAL_STATE_BOUND)
    {
      /* The connection should not reside in any other list */

      DEBUGASSERT(server->lc_node.flink == NULL &&
                  server->lc_node.flink == NULL);

      /* Add the connection structure to the list of listeners */

      state = net_lock();
      dq_addlast(&server->lc_node, &g_local_listeners);
      net_unlock(state);

      /* And change the server state to listing */

      server->lc_state = LOCAL_STATE_LISTENING;
    }

  /* Loop until a connection is requested or we receive a signal */

  while (dq_empty(&server->u.server.lc_waiters))
    {
      /* No.. wait for a connection or a signal */

      ret = sem_wait(&server->lc_waitsem);
      if (ret < 0)
        {
          int errval = errno;
          DEBUGASSERT(errval == EINTR);
          return -errval;
        }
    }

  /* There is a client waiting for the connection */

  return OK;
}