Skip site navigation (1)Skip section navigation (2)

FreeBSD Manual Pages

  
 
  

home | help
open_nonblock(3)		 Arcan Lua API		      open_nonblock(3)

NAME
       open_nonblock - Open a file in read or write mode for non-blocking I/O.

SYNOPSIS
       blocktbl
       open_nonblock( vid:res )
       open_nonblock( vid:res, bool:write )
       open_nonblock( vid:res, bool:write, string:identifier=stream )
       open_nonblock(  vid:res,	 bool:write,  string:identifier=stream,	 user-
       data:nbioud )
       open_nonblock( vid:res, table:opts, string:identifier=stream )
       open_nonblock(  vid:res,	 table:opts,  string:identifier=stream,	 user-
       data:nbioud )
       open_nonblock( string:res )
       open_nonblock( string:res, bool:write )

DESCRIPTION
       Create or open the resource indicated by	res  in	(default) read-mode or
       (if mode	 is provided, write mode)

       If  res	  is a vid connected to	a frameserver, either a	streaming fifo
       session will be set up over the connection along	with the corresponding
       _BCHUNK	events or an pre-existing nonblock-io stream, nbioud , will be
       redirected to said client and the backing descriptor closed locally.

       The identifier  argument	can then be used to specify  some  client  an-
       nounced	type  identifier,  or  one  of the reserved "stdin", "stdout",
       "stderr".

       If res  is a string, the	initial	character determines if	it  creates  a
       FIFO    (<)  or a SOCKET	 (=). Unless a namespace is explicitly set and
       the namespace is	marked as valid	for IPC	, FIFO s and SOCKET s will  be
       created	in  the	RESOURCE_APPL_TEMP  namespace. For sockets, the	write
       argument	determines if the connection should  be	 outbound  (=true)  or
       listening (=false).

       If the identifier  starts with a	valid namespace	identifier and separa-
       tor  (alphanum:/)   the	identifier will	first be matched to a user de-
       fined namespace (see list_namespaces ).

       If the res  is connected	to a frameserver, the namespace	identifier  is
       fixed  and  only	defined	for connections	coming from net_open . The de-
       fault is	to target the private store of the  authenticated  client.  To
       let  the	 server	 side controller script	decide,	prefix the identifier
       with appl:/

       If successful, FIFO s and normal	resources return a table wih  a	 close
       operation  (which  is  activated	on garbage collection unless called in
       beforehand) and a read or write function	depending on the mode that the
       resource	was opened in.

       The socket table	is special in that it allows multiple connections. the
       initial table for a socket only has a close and an accept function. The
       accept function takes no	arguments and returns a	table in both read and
       write mode when there is	a client waiting.

       The opts	 table argument	form is	used to	tune transfer parameters.

NOTES
       1      Do note that input processing has	soft realtime constraints, and
	      care should be taken to avoid processing large chunks of data in
	      one go as	it may affect application responsiveness.

       2

	      FIFO s and sockets that were created will	be unlinked  when  the
	      close  method  is	 called	or when	the table reference is garbage
	      collected.

       3      When a nonblocking userdata is handed over to a frameserver, the

	      write  argument will be ignored and the  corresponding  BCHUNK
	      event will match the userdata. This was a	bug in a previous ver-
	      sion where the write argument was	respected and the argument had
	      to be kept to avoid breaking compatibility.

EXAMPLE
       function	open_nonblock0()
	     a = open_nonblock("test.txt")
	     if	(a == nil) then
		   return shutdown("couldn't open test.txt");
	     end
       end
       function	main_clock_pulse()
	     local line	= a:read();
	     if	(line ~= nil) then
		   print(line);
	     end
       end

EXAMPLE
       function	open_nonblock1()
	     a = open_nonblock("=test",	false)
	     b = open_nonblock("=test",	true)
       -- our reader, note the scoping and the closure here
	     local counter = 20
	     local dh
	     dh	=
	     function()
		   local res, alive = a:read()
		   if res then
			 print("read:",	res)
			 counter = counter - 1
			 if alive and counter >	0 then
			       a:data_handler(dh)
			       return
			 end
		   end
		   a:close() --	will close on error or if counter reaches 0
	     end
	     a:data_handler(dh)
       end
       function	main_clock_pulse()
	     if	CLOCK %	100 == 0 then
		   local _, alive = b:write("sent at " .. tostring(CLOCK))
		   if not alive	then
			 return	shutdown()
		   end
	     end
       end

SEE ALSO:
resource			  March	2026		      open_nonblock(3)

Want to link to this manual page? Use this URL:
<https://man.freebsd.org/cgi/man.cgi?query=open_nonblock&sektion=3&manpath=FreeBSD+Ports+15.0.quarterly>

home | help