VND_POLLFD man page on SmartOS

Man page or keyword search:  
man Server   16655 pages
apropos Keyword Search (all sections)
Output format
SmartOS logo
[printable version]

VND_POLLFD(3VND)					      VND_POLLFD(3VND)

NAME
       vnd_pollfd - get file descriptor for polling

SYNOPSIS
       cc [ flag... ] file... -lvnd [ library... ]
       #include <libvnd.h>

       int vnd_pollfd(vnd_handle_t *vhp);

DESCRIPTION
       The  vnd_pollfd()  function  returns an integer id which corresponds to
       the file descriptor that represents the underlying device that is asso‐
       ciated  with  the  vnd handle vhp. This file descriptor is suitable for
       use with port_associate(3C) and	similar	 polling  techniques  such  as
       poll(2).	 Use  of  the  file descriptor outside of these uses may cause
       undocumented behavior from the rest of the library.

       The file descriptor in question is still managed by libvnd. The	caller
       must not call close(2) on it. Once vnd_close(3VND) has been called, any
       further use of the file descriptor is undefined behavior.

RETURN VALUES
       The function returns the integer id of the file descriptor that	corre‐
       sponds to the underlying vnd device.

EXAMPLES
       Example 1   Use event ports for vnd notifications

       The following sample C program shows how to use the vnd_pollfd function
       with event ports to be notified whenever there is data available to  be
       read. This program assumes that a vnd device named "vnd0" exists in the
       current zone. For an example of creating the device, see Example	 1  in
       vnd_create(3VND).

	 #include <libvnd.h>
	 #include <port.h>
	 #include <sys/types.h>
	 #include <unistd.h>
	 #include <fcntl.h>

	 int
	 main(void)
	 {
	      vnd_handle_t *vhp;
	      vnd_errno_t vnderr;
	      int port, syserr, vfd, ret;

	      port = port_create();
	      if (port < 0) {
		   perror("port_create");
		   return (1);
	      }

	      vhp = vnd_open(NULL, "vnd0", &vnderr, &syserr);
	      if (vhp == NULL) {
		   if (vnderr == VND_E_SYS)
			(void) fprintf(stderr, "failed to open device: %s",
			    vnd_strsyserror(syserr));
		   else
			(void) fprintf(stderr, "failed to open device: %s",
			    vnd_strerror(vnderr));
		   (void) close(port);
		   return (1);
	      }

	      vfd = vnd_pollfd(vhp);
	      if (fcntl(vfd, F_SETFL, O_NONBLOCK) != 0) {
		   perror("fcntl");
		   vnd_close(vhp);
		   (void) close(port);
		   return (1);
	      }

	      if (port_associate(port, PORT_SOURCE_FD, vfd, POLLIN, NULL) != 0) {
		   perror("port_associate");
		   vnd_close(vhp);
		   (void) close(port);
		   return (1);
	      }

	      for (;;) {
		   port_event_t pe;

		   if (port_get(port, &pe, NULL) != 0) {
			if (errno == EINTR)
			     continue;
			perror("port_get");
			vnd_close(vhp);
			(void) close(port);
			return (1);
		   }

		   /*
		    * Read the data with vnd_frameio_read(3VND) and
		    * optionally break out of the loop or continue to the
		    * next iteration and reassociate vfd with the event
		    * port.
		    */
	      }
	 }

ATTRIBUTES
       See attributes(5) for descriptions of the following attributes:

       ┌───────────────┬─────────────────────────────────┐
       │ATTRIBUTE TYPE │	 ATTRIBUTE VALUE	 │
       ├───────────────┼─────────────────────────────────┤
       │Stability      │ Committed			 │
       ├───────────────┼─────────────────────────────────┤
       │MT-Level       │ See "THREADING" in libvnd(3LIB) │
       └───────────────┴─────────────────────────────────┘

SEE ALSO
       close(2), poll(2), port_create(3C), libvnd(3LIB), vnd_close(3VND)

				 Feb 21, 2014		      VND_POLLFD(3VND)
[top]

List of man pages available for SmartOS

Copyright (c) for man pages and the logo by the respective OS vendor.

For those who want to learn more, the polarhome community provides shell access and support.

[legal] [privacy] [GNU] [policy] [cookies] [netiquette] [sponsors] [FAQ]
Tweet
Polarhome, production since 1999.
Member of Polarhome portal.
Based on Fawad Halim's script.
....................................................................
Vote for polarhome
Free Shell Accounts :: the biggest list on the net