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
ConstructorsConstructorDescriptionPoll(MemorySegment address) Create a Poll proxy instance for the provided memory address. -
Method Summary
Modifier and TypeMethodDescriptionbooleanAdd a file descriptor to the file descriptor set.booleanCheck iffdin this Poll has data to be read.booleanfdCanWrite(PollFD fd) Check iffdin this Poll can be used for writing.booleanControl whether the descriptorfdin this Poll will be monitored for exceptional conditions (POLLPRI).booleanControl whether the descriptorfdin this Poll will be monitored for readability.booleanfdCtlWrite(PollFD fd, boolean active) Control whether the descriptorfdin this Poll will be monitored for writability.booleanfdHasClosed(PollFD fd) Check iffdin this Poll has closed the connection.booleanfdHasError(PollFD fd) Check iffdin this Poll has an error.booleanCheck iffdin this Poll has an exceptional condition (POLLPRI).voidMarkfdas ignored so that the next call to gst_poll_wait() will yield the same result forfdas last time.voidfree()Free a file descriptor set.voidgetReadGpollfd(PollFD fd) Get a GPollFD for the reading part of the control socket.static @Nullable Pollnew_(boolean controllable) Create a new file descriptor set.static @Nullable PollnewTimer()Create a new poll object that can be used for scheduling cancellable timeouts.booleanRead a byte from the control socket of the controllableset.booleanRemove a file descriptor from the file descriptor set.voidrestart()Restart any gst_poll_wait() that is in progress.booleansetControllable(boolean controllable) Whencontrollableistrue, this function ensures that future calls to gst_poll_wait() will be affected by gst_poll_restart() and gst_poll_set_flushing().voidsetFlushing(boolean flushing) Whenflushingistrue, this function ensures that current and future calls to gst_poll_wait() will return -1, with errno set to EBUSY.intWait for activity on the file descriptors inset.This function waits up to the specifiedtimeout.A timeout ofGST_CLOCK_TIME_NONEwaits forever.booleanWrite a byte to the control socket of the controllableset.This function is mostly useful for timerGstPollobjects created with gst_poll_new_timer().Methods inherited from class org.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, ornullin 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, ornullin 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:
trueif the file descriptor was successfully added to the set.
-
fdCanRead
Check iffdin this Poll has data to be read.- Parameters:
fd- a file descriptor.- Returns:
trueif the descriptor has data to be read.
-
fdCanWrite
Check iffdin this Poll can be used for writing.- Parameters:
fd- a file descriptor.- Returns:
trueif the descriptor can be used for writing.
-
fdCtlPri
Control whether the descriptorfdin this Poll will be monitored for exceptional conditions (POLLPRI).Not implemented on Windows (will just return
falsethere).- Parameters:
fd- a file descriptor.active- a new status.- Returns:
trueif the descriptor was successfully updated.- Since:
- 1.16
-
fdCtlRead
Control whether the descriptorfdin this Poll will be monitored for readability.- Parameters:
fd- a file descriptor.active- a new status.- Returns:
trueif the descriptor was successfully updated.
-
fdCtlWrite
Control whether the descriptorfdin this Poll will be monitored for writability.- Parameters:
fd- a file descriptor.active- a new status.- Returns:
trueif the descriptor was successfully updated.
-
fdHasClosed
Check iffdin this Poll has closed the connection.- Parameters:
fd- a file descriptor.- Returns:
trueif the connection was closed.
-
fdHasError
Check iffdin this Poll has an error.- Parameters:
fd- a file descriptor.- Returns:
trueif the descriptor has an error.
-
fdHasPri
Check iffdin this Poll has an exceptional condition (POLLPRI).Not implemented on Windows (will just return
falsethere).- Parameters:
fd- a file descriptor.- Returns:
trueif the descriptor has an exceptional condition.- Since:
- 1.16
-
fdIgnored
Markfdas ignored so that the next call to gst_poll_wait() will yield the same result forfdas last time. This function must be called if no operation (read/write/recv/send/etc.) will be performed onfdbefore 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 controllableset.This function only works for timer
GstPollobjects created with gst_poll_new_timer().- Returns:
trueon success.falsewhen 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:
trueif 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 toset.If this Poll is not controllable, then this call will have no effect.
This function only works for non-timer
GstPollobjects created with gst_poll_new(). -
setControllable
public boolean setControllable(boolean controllable) Whencontrollableistrue, 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
GstPollobjects created with gst_poll_new().- Parameters:
controllable- new controllable state.- Returns:
trueif the controllability of this Poll could be updated.
-
setFlushing
public void setFlushing(boolean flushing) Whenflushingistrue, 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
set.This function only works for non-timer
GstPollobjects created with gst_poll_new().- Parameters:
flushing- new flushing state.
-
wait_
Wait for activity on the file descriptors inset.This function waits up to the specifiedtimeout.A timeout ofGST_CLOCK_TIME_NONEwaits forever.For
GstPollobjects 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
GstPollobjects 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
GstPollFDin 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 controllableset.This function is mostly useful for timerGstPollobjects 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
GstPollobjects created with gst_poll_new_timer().- Returns:
trueon success.falsewhen when the byte could not be written. errno contains the detailed error code but will never be EAGAIN, EINTR or EWOULDBLOCK.falsealways signals a critical error.
-