Class Poll
- All Implemented Interfaces:
Proxy
GstPoll
keeps track of file descriptors much like fd_set (used with
select ()) or a struct pollfd array (used with poll ()). Once created with
gst_poll_new(), the set can be used to wait for file descriptors to be
readable and/or writable. It is possible to make this wait be controlled
by specifying true
for the controllable
flag when creating the set (or
later calling gst_poll_set_controllable()).
New file descriptors are added to the set using gst_poll_add_fd(), and removed using gst_poll_remove_fd(). Controlling which file descriptors should be waited for to become readable and/or writable are done using gst_poll_fd_ctl_read(), gst_poll_fd_ctl_write() and gst_poll_fd_ctl_pri().
Use gst_poll_wait() to wait for the file descriptors to actually become readable and/or writable, or to timeout if no file descriptor is available in time. The wait can be controlled by calling gst_poll_restart() and gst_poll_set_flushing().
Once the file descriptor set has been waited for, one can use gst_poll_fd_has_closed() to see if the file descriptor has been closed, gst_poll_fd_has_error() to see if it has generated an error, gst_poll_fd_can_read() to see if it is possible to read from the file descriptor, and gst_poll_fd_can_write() to see if it is possible to write to it.
-
Constructor Summary
ConstructorDescriptionPoll
(MemorySegment address) Create a Poll proxy instance for the provided memory address. -
Method Summary
Modifier and TypeMethodDescriptionboolean
Add a file descriptor to the file descriptor set.boolean
Check iffd
in this Poll has data to be read.boolean
fdCanWrite
(PollFD fd) Check iffd
in this Poll can be used for writing.boolean
Control whether the descriptorfd
in this Poll will be monitored for exceptional conditions (POLLPRI).boolean
Control whether the descriptorfd
in this Poll will be monitored for readability.boolean
fdCtlWrite
(PollFD fd, boolean active) Control whether the descriptorfd
in this Poll will be monitored for writability.boolean
fdHasClosed
(PollFD fd) Check iffd
in this Poll has closed the connection.boolean
fdHasError
(PollFD fd) Check iffd
in this Poll has an error.boolean
Check iffd
in this Poll has an exceptional condition (POLLPRI).void
Markfd
as ignored so that the next call to gst_poll_wait() will yield the same result forfd
as last time.void
free()
Free a file descriptor set.void
getReadGpollfd
(PollFD fd) Get a GPollFD for the reading part of the control socket.static Poll
new_
(boolean controllable) Create a new file descriptor set.static Poll
newTimer()
Create a new poll object that can be used for scheduling cancellable timeouts.boolean
Read a byte from the control socket of the controllable this Poll.boolean
Remove a file descriptor from the file descriptor set.void
restart()
Restart any gst_poll_wait() that is in progress.boolean
setControllable
(boolean controllable) Whencontrollable
istrue
, this function ensures that future calls to gst_poll_wait() will be affected by gst_poll_restart() and gst_poll_set_flushing().void
setFlushing
(boolean flushing) Whenflushing
istrue
, this function ensures that current and future calls to gst_poll_wait() will return -1, with errno set to EBUSY.int
Wait for activity on the file descriptors in this Poll.boolean
Write a byte to the control socket of the controllable this Poll.Methods inherited from class io.github.jwharm.javagi.base.ProxyInstance
equals, handle, hashCode
-
Constructor Details
-
Poll
Create a Poll proxy instance for the provided memory address.- Parameters:
address
- the memory address of the native object
-
-
Method Details
-
new_
Create a new file descriptor set. Ifcontrollable
, it is possible to restart or flush a call to gst_poll_wait() with gst_poll_restart() and gst_poll_set_flushing() respectively.Free-function: gst_poll_free
- Parameters:
controllable
- whether it should be possible to control a wait.- Returns:
- a new
GstPoll
, ornull
in case of an error. Free with gst_poll_free().
-
newTimer
Create a new poll object that can be used for scheduling cancellable timeouts.A timeout is performed with gst_poll_wait(). Multiple timeouts can be performed from different threads.
Free-function: gst_poll_free
- Returns:
- a new
GstPoll
, ornull
in case of an error. Free with gst_poll_free().
-
addFd
Add a file descriptor to the file descriptor set.- Parameters:
fd
- a file descriptor.- Returns:
true
if the file descriptor was successfully added to the set.
-
fdCanRead
Check iffd
in this Poll has data to be read.- Parameters:
fd
- a file descriptor.- Returns:
true
if the descriptor has data to be read.
-
fdCanWrite
Check iffd
in this Poll can be used for writing.- Parameters:
fd
- a file descriptor.- Returns:
true
if the descriptor can be used for writing.
-
fdCtlPri
Control whether the descriptorfd
in this Poll will be monitored for exceptional conditions (POLLPRI).Not implemented on Windows (will just return
false
there).- Parameters:
fd
- a file descriptor.active
- a new status.- Returns:
true
if the descriptor was successfully updated.
-
fdCtlRead
Control whether the descriptorfd
in this Poll will be monitored for readability.- Parameters:
fd
- a file descriptor.active
- a new status.- Returns:
true
if the descriptor was successfully updated.
-
fdCtlWrite
Control whether the descriptorfd
in this Poll will be monitored for writability.- Parameters:
fd
- a file descriptor.active
- a new status.- Returns:
true
if the descriptor was successfully updated.
-
fdHasClosed
Check iffd
in this Poll has closed the connection.- Parameters:
fd
- a file descriptor.- Returns:
true
if the connection was closed.
-
fdHasError
Check iffd
in this Poll has an error.- Parameters:
fd
- a file descriptor.- Returns:
true
if the descriptor has an error.
-
fdHasPri
Check iffd
in this Poll has an exceptional condition (POLLPRI).Not implemented on Windows (will just return
false
there).- Parameters:
fd
- a file descriptor.- Returns:
true
if the descriptor has an exceptional condition.
-
fdIgnored
Markfd
as ignored so that the next call to gst_poll_wait() will yield the same result forfd
as last time. This function must be called if no operation (read/write/recv/send/etc.) will be performed onfd
before the next call to gst_poll_wait().The reason why this is needed is because the underlying implementation might not allow querying the fd more than once between calls to one of the re-enabling operations.
- Parameters:
fd
- a file descriptor.
-
free
public void free()Free a file descriptor set. -
getReadGpollfd
Get a GPollFD for the reading part of the control socket. This is useful when integrating with a GSource and GMainLoop.- Parameters:
fd
- aGPollFD
-
readControl
public boolean readControl()Read a byte from the control socket of the controllable this Poll.This function only works for timer
GstPoll
objects created with gst_poll_new_timer().- Returns:
true
on success.false
when when there was no byte to read or reading the byte failed. If there was no byte to read, and only then, errno will contain EWOULDBLOCK or EAGAIN. For all other values of errno this always signals a critical error.
-
removeFd
Remove a file descriptor from the file descriptor set.- Parameters:
fd
- a file descriptor.- Returns:
true
if the file descriptor was successfully removed from the set.
-
restart
public void restart()Restart any gst_poll_wait() that is in progress. This function is typically used after adding or removing descriptors to this Poll.If this Poll is not controllable, then this call will have no effect.
This function only works for non-timer
GstPoll
objects created with gst_poll_new(). -
setControllable
public boolean setControllable(boolean controllable) Whencontrollable
istrue
, this function ensures that future calls to gst_poll_wait() will be affected by gst_poll_restart() and gst_poll_set_flushing().This function only works for non-timer
GstPoll
objects created with gst_poll_new().- Parameters:
controllable
- new controllable state.- Returns:
true
if the controllability of this Poll could be updated.
-
setFlushing
public void setFlushing(boolean flushing) Whenflushing
istrue
, this function ensures that current and future calls to gst_poll_wait() will return -1, with errno set to EBUSY.Unsetting the flushing state will restore normal operation of this Poll.
This function only works for non-timer
GstPoll
objects created with gst_poll_new().- Parameters:
flushing
- new flushing state.
-
wait_
Wait for activity on the file descriptors in this Poll. This function waits up to the specifiedtimeout
. A timeout ofGST_CLOCK_TIME_NONE
waits forever.For
GstPoll
objects created with gst_poll_new(), this function can only be called from a single thread at a time. If called from multiple threads, -1 will be returned with errno set to EPERM.This is not true for timer
GstPoll
objects created with gst_poll_new_timer(), where it is allowed to have multiple threads waiting simultaneously.- Parameters:
timeout
- a timeout in nanoseconds.- Returns:
- The number of
GstPollFD
in this Poll that have activity or 0 when no activity was detected aftertimeout
. If an error occurs, -1 is returned and errno is set.
-
writeControl
public boolean writeControl()Write a byte to the control socket of the controllable this Poll. This function is mostly useful for timerGstPoll
objects created with gst_poll_new_timer().It will make any current and future gst_poll_wait() function return with 1, meaning the control socket is set. After an equal amount of calls to gst_poll_read_control() have been performed, calls to gst_poll_wait() will block again until their timeout expired.
This function only works for timer
GstPoll
objects created with gst_poll_new_timer().- Returns:
true
on success.false
when when the byte could not be written. errno contains the detailed error code but will never be EAGAIN, EINTR or EWOULDBLOCK.false
always signals a critical error.
-