Ejemplo n.º 1
0
static size_t      httpfs_read(    struct uufile *f, void *buf, size_t len)
{
    struct uusocket *s = f->impl;

    if( s == 0 || s->prot_data == 0 )
        return -1;

    return tcp_recvfrom( s->prot_data, buf, len, &s->addr, 0, 0 );
}
Ejemplo n.º 2
0
ssize_t psock_recvfrom(FAR struct socket *psock, FAR void *buf, size_t len,
                       int flags,FAR struct sockaddr *from,
                       FAR socklen_t *fromlen)
{
#if defined(CONFIG_NET_UDP) || defined(CONFIG_NET_TCP)
#ifdef CONFIG_NET_IPv6
  FAR struct sockaddr_in6 *infrom = (struct sockaddr_in6 *)from;
#else
  FAR struct sockaddr_in *infrom = (struct sockaddr_in *)from;
#endif
#endif

  ssize_t ret;
  int err;

  /* Verify that non-NULL pointers were passed */

#ifdef CONFIG_DEBUG
  if (!buf)
    {
      err = EINVAL;
      goto errout;
    }
#endif

  /* Verify that the sockfd corresponds to valid, allocated socket */

  if (!psock || psock->s_crefs <= 0)
    {
      err = EBADF;
      goto errout;
    }

  /* If a 'from' address has been provided, verify that it is large
   * enough to hold this address family.
   */

  if (from)
    {
#ifdef CONFIG_NET_IPv6
      if (*fromlen < sizeof(struct sockaddr_in6))
#else
      if (*fromlen < sizeof(struct sockaddr_in))
#endif
        {
          err = EINVAL;
          goto errout;
        }
    }

  /* Set the socket state to receiving */

  psock->s_flags = _SS_SETSTATE(psock->s_flags, _SF_RECV);

  /* Perform the TCP/IP or UDP recv() operation */

#if defined(CONFIG_NET_UDP) && defined(CONFIG_NET_TCP)
  if (psock->s_type == SOCK_STREAM)
    {
      ret = tcp_recvfrom(psock, buf, len, infrom);
    }
  else
    {
      ret = udp_recvfrom(psock, buf, len, infrom);
    }
#elif defined(CONFIG_NET_TCP)
  ret = tcp_recvfrom(psock, buf, len, infrom);
#elif defined(CONFIG_NET_UDP)
  ret = udp_recvfrom(psock, buf, len, infrom);
#else
  ret = -ENOSYS;
#endif

  /* Set the socket state to idle */

  psock->s_flags = _SS_SETSTATE(psock->s_flags, _SF_IDLE);

  /* Handle returned errors */

  if (ret < 0)
    {
      err = -ret;
      goto errout;
    }

  /* Success return */

  return ret;

errout:
  errno = err;
  return ERROR;
}