コード例 #1
0
ファイル: virtio-9p-local.c プロジェクト: 01org/KVMGT-qemu
static int local_ioc_getversion(FsContext *ctx, V9fsPath *path,
                                mode_t st_mode, uint64_t *st_gen)
{
    int err;
#ifdef FS_IOC_GETVERSION
    V9fsFidOpenState fid_open;

    /*
     * Do not try to open special files like device nodes, fifos etc
     * We can get fd for regular files and directories only
     */
    if (!S_ISREG(st_mode) && !S_ISDIR(st_mode)) {
            return 0;
    }
    err = local_open(ctx, path, O_RDONLY, &fid_open);
    if (err < 0) {
        return err;
    }
    err = ioctl(fid_open.fd, FS_IOC_GETVERSION, st_gen);
    local_close(ctx, &fid_open);
#else
    err = -ENOTTY;
#endif
    return err;
}
コード例 #2
0
ファイル: shcodecs-encdec.c プロジェクト: pedwo/libshcodecs
int decode(struct dec_opts *opts)
{
	struct shdec dec1;
	struct shdec * dec = &dec1;
	SHCodecs_Decoder * decoder;
	int bytes_decoded;
	ssize_t n;

	debug_printf("Format: %s\n", opts->format == SHCodecs_Format_H264 ? "H.264" : "MPEG4");
	debug_printf("Resolution: %dx%d\n", opts->w, opts->h);
	debug_printf("Input  file: %s\n", opts->file_in);
	debug_printf("Output file: %s\n", opts->file_out);

	/* H.264 spec: Max NAL size is the size of an uncompressed image divided
	   by the "Minimum Compression Ratio", MinCR. This is 2 for most levels
	   but is 4 for levels 3.1 to 4. Since we don't know the level, we just
	   use MinCR=2. */
	dec->max_nal_size = (opts->w * opts->h * 3) / 2; /* YCbCr420 */
	dec->max_nal_size /= 2;                          /* Apply MinCR */

	if ((decoder = shcodecs_decoder_init(opts->w, opts->h, opts->format)) == NULL) {
		return -1;
	}

	if (local_init(dec, opts->file_in, opts->file_out) < 0)
		return -1;

	shcodecs_decoder_set_decoded_callback (decoder, frame_decoded, dec);

	/* decode main loop */
	do {
		int rem;

		bytes_decoded = shcodecs_decode (decoder, dec->input_buffer, dec->si_isize);

		rem = dec->si_isize - bytes_decoded;
		memmove(dec->input_buffer, dec->input_buffer + bytes_decoded, rem);
		n = read (dec->input_fd, dec->input_buffer + rem, dec->max_nal_size - rem);
		if (n < 0) break;

		dec->si_isize = rem + n;
	} while (!(n == 0 && bytes_decoded == 0));

	bytes_decoded = shcodecs_decode (decoder, dec->input_buffer, dec->si_isize);

	/* Finalize the decode output, in case a final frame is available */
	shcodecs_decoder_finalize (decoder);

	local_close (dec);

	shcodecs_decoder_close(decoder);

	return 0;
}
コード例 #3
0
ファイル: net_close.c プロジェクト: acassis/ros2_nuttx
int psock_close(FAR struct socket *psock)
{
  int err;

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

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

  /* We perform the uIP close operation only if this is the last count on
   * the socket. (actually, I think the socket crefs only takes the values
   * 0 and 1 right now).
   *
   * It is possible for a psock to have no connection, e.g. a TCP socket
   * waiting in accept.
   */

  if (psock->s_crefs <= 1 && psock->s_conn != NULL)
    {
      /* Perform uIP side of the close depending on the protocol type */

      switch (psock->s_type)
        {
#if defined(CONFIG_NET_TCP) || defined(CONFIG_NET_LOCAL_STREAM)
          case SOCK_STREAM:
            {
#ifdef CONFIG_NET_LOCAL_STREAM
#ifdef CONFIG_NET_TCP
              if (psock->s_domain == PF_LOCAL)
#endif
                {
                  /* Release our reference to the local connection structure */

                  local_close(psock);
                }
#endif /* CONFIG_NET_LOCAL_STREAM */

#ifdef CONFIG_NET_TCP
#ifdef CONFIG_NET_LOCAL_STREAM
              else
#endif
                {
                  FAR struct tcp_conn_s *conn = psock->s_conn;

                  /* Is this the last reference to the connection structure
                   * (there could be more if the socket was dup'ed).
                   */

                  if (conn->crefs <= 1)
                    {
                      /* Yes... then perform the disconnection now */

                      tcp_unlisten(conn); /* No longer accepting connections */
                      conn->crefs = 0;    /* Discard our reference to the connection */

                      /* Break any current connections */

                      err = netclose_disconnect(psock);
                      if (err < 0)
                        {
                          /* This would normally occur only if there is a
                           * timeout from a lingering close.
                           */

                          goto errout_with_psock;
                        }

                      /* Stop the network monitor */

                      net_stopmonitor(conn);
                    }
                  else
                    {
                      /* No.. Just decrement the reference count */

                      conn->crefs--;
                    }
                }
#endif /* CONFIG_NET_TCP || CONFIG_NET_LOCAL_STREAM */
            }
            break;
#endif

#if defined(CONFIG_NET_UDP) || defined(CONFIG_NET_LOCAL_DGRAM)
          case SOCK_DGRAM:
            {
#ifdef CONFIG_NET_LOCAL_DGRAM
#ifdef CONFIG_NET_UDP
              if (psock->s_domain == PF_LOCAL)
#endif
                {
                  /* Release our reference to the local connection structure */

                  local_close(psock);
                }
#endif /* CONFIG_NET_LOCAL_DGRAM */

#ifdef CONFIG_NET_UDP
#ifdef CONFIG_NET_LOCAL_DGRAM
              else
#endif
                {
                  FAR struct udp_conn_s *conn = psock->s_conn;

                  /* Is this the last reference to the connection structure
                   * (there could be more if the socket was dup'ed).
                   */

                  if (conn->crefs <= 1)
                    {
                      /* Yes... free the connection structure */

                      conn->crefs = 0;
                      udp_free(psock->s_conn);
                    }
                  else
                    {
                      /* No.. Just decrement the reference count */

                      conn->crefs--;
                    }
                }
#endif /* CONFIG_NET_UDP || CONFIG_NET_LOCAL_DGRAM */
            }
            break;
#endif

#ifdef CONFIG_NET_PKT
          case SOCK_RAW:
            {
              FAR struct pkt_conn_s *conn = psock->s_conn;

              /* Is this the last reference to the connection structure (there
               * could be more if the socket was dup'ed).
               */

              if (conn->crefs <= 1)
                {
                  /* Yes... free the connection structure */

                  conn->crefs = 0;          /* No more references on the connection */
                  pkt_free(psock->s_conn);  /* Free uIP resources */
                }
              else
                {
                  /* No.. Just decrement the reference count */

                  conn->crefs--;
                }
            }
            break;
#endif

          default:
            err = EBADF;
            goto errout;
        }
    }

  /* Then release our reference on the socket structure containing the connection */

  sock_release(psock);
  return OK;

#ifdef CONFIG_NET_TCP
errout_with_psock:
  sock_release(psock);
#endif

errout:
  set_errno(err);
  return ERROR;
}