UnixInputStream

GUnixInputStream implements GInputStream for reading from a UNIX file descriptor, including asynchronous operations. (If the file descriptor refers to a socket or pipe, this will use poll() to do asynchronous I/O. If it refers to a regular file, it will fall back to doing asynchronous I/O in another thread.)

Note that <gio/gunixinputstream.h> belongs to the UNIX-specific GIO interfaces, thus you have to use the gio-unix-2.0.pc pkg-config file when using it.

Constructors

this
this(GUnixInputStream* gUnixInputStream)

Sets our main struct and passes it to the parent class

this
this(int fd, int closeFd)

Creates a new GUnixInputStream for the given fd. If close_fd is TRUE, the file descriptor will be closed when the stream is closed.

Members

Functions

getCloseFd
int getCloseFd()

Returns whether the file descriptor of stream will be closed when the stream is closed. Since 2.20

getFd
int getFd()

Return the UNIX file descriptor that the stream reads from. Since 2.20

getStruct
void* getStruct()

the main Gtk struct as a void*

getUnixInputStreamStruct
GUnixInputStream* getUnixInputStreamStruct()

Get the main Gtk struct

setCloseFd
void setCloseFd(int closeFd)

Sets whether the file descriptor of stream shall be closed when the stream is closed. Since 2.20

setStruct
void setStruct(GObject* obj)
Undocumented in source. Be warned that the author may not have intended to support it.

Mixins

__anonymous
mixin PollableInputStreamT!(GUnixInputStream)
Undocumented in source.

Variables

gUnixInputStream
GUnixInputStream* gUnixInputStream;

the main Gtk struct

Inherited Members

From InputStream

gInputStream
GInputStream* gInputStream;

the main Gtk struct

getInputStreamStruct
GInputStream* getInputStreamStruct()

Get the main Gtk struct

getStruct
void* getStruct()

the main Gtk struct as a void*

setStruct
void setStruct(GObject* obj)
Undocumented in source. Be warned that the author may not have intended to support it.
read
gssize read(void* buffer, gsize count, Cancellable cancellable)

Tries to read count bytes from the stream into the buffer starting at buffer. Will block during this read. If count is zero returns zero and does nothing. A value of count larger than G_MAXSSIZE will cause a G_IO_ERROR_INVALID_ARGUMENT error. On success, the number of bytes read into the buffer is returned. It is not an error if this is not the same as the requested size, as it can happen e.g. near the end of a file. Zero is returned on end of file (or if count is zero), but never otherwise. If cancellable is not NULL, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the error G_IO_ERROR_CANCELLED will be returned. If an operation was partially finished when the operation was cancelled the partial result will be returned, without an error. On error -1 is returned and error is set accordingly.

readAll
int readAll(void* buffer, gsize count, gsize bytesRead, Cancellable cancellable)

Tries to read count bytes from the stream into the buffer starting at buffer. Will block during this read. This function is similar to g_input_stream_read(), except it tries to read as many bytes as requested, only stopping on an error or end of stream. On a successful read of count bytes, or if we reached the end of the stream, TRUE is returned, and bytes_read is set to the number of bytes read into buffer. If there is an error during the operation FALSE is returned and error is set to indicate the error status, bytes_read is updated to contain the number of bytes read into buffer before the error occurred.

skip
gssize skip(gsize count, Cancellable cancellable)

Tries to skip count bytes from the stream. Will block during the operation. This is identical to g_input_stream_read(), from a behaviour standpoint, but the bytes that are skipped are not returned to the user. Some streams have an implementation that is more efficient than reading the data. This function is optional for inherited classes, as the default implementation emulates it using read. If cancellable is not NULL, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the error G_IO_ERROR_CANCELLED will be returned. If an operation was partially finished when the operation was cancelled the partial result will be returned, without an error.

close
int close(Cancellable cancellable)

Closes the stream, releasing resources related to it. Once the stream is closed, all other operations will return G_IO_ERROR_CLOSED. Closing a stream multiple times will not return an error. Streams will be automatically closed when the last reference is dropped, but you might want to call this function to make sure resources are released as early as possible. Some streams might keep the backing store of the stream (e.g. a file descriptor) open after the stream is closed. See the documentation for the individual stream for details. On failure the first error that happened will be reported, but the close operation will finish as much as possible. A stream that failed to close will still return G_IO_ERROR_CLOSED for all operations. Still, it is important to check and report the error to the user. If cancellable is not NULL, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the error G_IO_ERROR_CANCELLED will be returned. Cancelling a close will still leave the stream closed, but some streams can use a faster close that doesn't block to e.g. check errors.

readAsync
void readAsync(void* buffer, gsize count, int ioPriority, Cancellable cancellable, GAsyncReadyCallback callback, void* userData)

Request an asynchronous read of count bytes from the stream into the buffer starting at buffer. When the operation is finished callback will be called. You can then call g_input_stream_read_finish() to get the result of the operation. During an async request no other sync and async calls are allowed on stream, and will result in G_IO_ERROR_PENDING errors. A value of count larger than G_MAXSSIZE will cause a G_IO_ERROR_INVALID_ARGUMENT error. On success, the number of bytes read into the buffer will be passed to the callback. It is not an error if this is not the same as the requested size, as it can happen e.g. near the end of a file, but generally we try to read as many bytes as requested. Zero is returned on end of file (or if count is zero), but never otherwise. Any outstanding i/o request with higher priority (lower numerical value) will be executed before an outstanding request with lower priority. Default priority is G_PRIORITY_DEFAULT. The asyncronous methods have a default fallback that uses threads to implement asynchronicity, so they are optional for inheriting classes. However, if you override one you must override all.

readFinish
gssize readFinish(AsyncResultIF result)

Finishes an asynchronous stream read operation.

skipAsync
void skipAsync(gsize count, int ioPriority, Cancellable cancellable, GAsyncReadyCallback callback, void* userData)

Request an asynchronous skip of count bytes from the stream. When the operation is finished callback will be called. You can then call g_input_stream_skip_finish() to get the result of the operation. During an async request no other sync and async calls are allowed, and will result in G_IO_ERROR_PENDING errors. A value of count larger than G_MAXSSIZE will cause a G_IO_ERROR_INVALID_ARGUMENT error. On success, the number of bytes skipped will be passed to the callback. It is not an error if this is not the same as the requested size, as it can happen e.g. near the end of a file, but generally we try to skip as many bytes as requested. Zero is returned on end of file (or if count is zero), but never otherwise. Any outstanding i/o request with higher priority (lower numerical value) will be executed before an outstanding request with lower priority. Default priority is G_PRIORITY_DEFAULT. The asynchronous methods have a default fallback that uses threads to implement asynchronicity, so they are optional for inheriting classes. However, if you override one, you must override all.

skipFinish
gssize skipFinish(AsyncResultIF result)

Finishes a stream skip operation.

closeAsync
void closeAsync(int ioPriority, Cancellable cancellable, GAsyncReadyCallback callback, void* userData)

Requests an asynchronous closes of the stream, releasing resources related to it. When the operation is finished callback will be called. You can then call g_input_stream_close_finish() to get the result of the operation. For behaviour details see g_input_stream_close(). The asyncronous methods have a default fallback that uses threads to implement asynchronicity, so they are optional for inheriting classes. However, if you override one you must override all.

closeFinish
int closeFinish(AsyncResultIF result)

Finishes closing a stream asynchronously, started from g_input_stream_close_async().

isClosed
int isClosed()

Checks if an input stream is closed.

hasPending
int hasPending()

Checks if an input stream has pending actions.

setPending
int setPending()

Sets stream to have actions pending. If the pending flag is already set or stream is closed, it will return FALSE and set error.

clearPending
void clearPending()

Clears the pending flag on stream.

readBytes
Bytes readBytes(gsize count, Cancellable cancellable)

Like g_input_stream_read(), this tries to read count bytes from the stream in a blocking fashion. However, rather than reading into a user-supplied buffer, this will create a new GBytes containing the data that was read. This may be easier to use from language bindings. If count is zero, returns a zero-length GBytes and does nothing. A value of count larger than G_MAXSSIZE will cause a G_IO_ERROR_INVALID_ARGUMENT error. On success, a new GBytes is returned. It is not an error if the size of this object is not the same as the requested size, as it can happen e.g. near the end of a file. A zero-length GBytes is returned on end of file (or if count is zero), but never otherwise. If cancellable is not NULL, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the error G_IO_ERROR_CANCELLED will be returned. If an operation was partially finished when the operation was cancelled the partial result will be returned, without an error. On error NULL is returned and error is set accordingly.

readBytesAsync
void readBytesAsync(gsize count, int ioPriority, Cancellable cancellable, GAsyncReadyCallback callback, void* userData)

Request an asynchronous read of count bytes from the stream into a new GBytes. When the operation is finished callback will be called. You can then call g_input_stream_read_bytes_finish() to get the result of the operation. During an async request no other sync and async calls are allowed on stream, and will result in G_IO_ERROR_PENDING errors. A value of count larger than G_MAXSSIZE will cause a G_IO_ERROR_INVALID_ARGUMENT error. On success, the new GBytes will be passed to the callback. It is not an error if this is smaller than the requested size, as it can happen e.g. near the end of a file, but generally we try to read as many bytes as requested. Zero is returned on end of file (or if count is zero), but never otherwise. Any outstanding I/O request with higher priority (lower numerical value) will be executed before an outstanding request with lower priority. Default priority is G_PRIORITY_DEFAULT.

readBytesFinish
Bytes readBytesFinish(AsyncResultIF result)

Finishes an asynchronous stream read-into-GBytes operation.

From PollableInputStreamIF

getPollableInputStreamTStruct
GPollableInputStream* getPollableInputStreamTStruct()

Get the main Gtk struct

getStruct
void* getStruct()

the main Gtk struct as a void*

canPoll
int canPoll()

Checks if stream is actually pollable. Some classes may implement GPollableInputStream but have only certain instances of that class be pollable. If this method returns FALSE, then the behavior of other GPollableInputStream methods is undefined. For any given stream, the value returned by this method is constant; a stream cannot switch from pollable to non-pollable or vice versa. Since 2.28

isReadable
int isReadable()

Checks if stream can be read. Note that some stream types may not be able to implement this 100% reliably, and it is possible that a call to g_input_stream_read() after this returns TRUE would still block. To guarantee non-blocking behavior, you should always use g_pollable_input_stream_read_nonblocking(), which will return a G_IO_ERROR_WOULD_BLOCK error rather than blocking. Since 2.28

createSource
Source createSource(Cancellable cancellable)

Creates a GSource that triggers when stream can be read, or cancellable is triggered or an error occurs. The callback on the source is of the GPollableSourceFunc type. As with g_pollable_input_stream_is_readable(), it is possible that the stream may not actually be readable even after the source triggers, so you should use g_pollable_input_stream_read_nonblocking() rather than g_input_stream_read() from the callback. Since 2.28

readNonblocking
gssize readNonblocking(void[] buffer, gsize count, Cancellable cancellable)

Attempts to read up to count bytes from stream into buffer, as with g_input_stream_read(). If stream is not currently readable, this will immediately return G_IO_ERROR_WOULD_BLOCK, and you can use g_pollable_input_stream_create_source() to create a GSource that will be triggered when stream is readable. Note that since this method never blocks, you cannot actually use cancellable to cancel it. However, it will return an error if cancellable has already been cancelled when you call, which may happen if you call this method after a source triggers due to having been cancelled. Virtual: read_nonblocking

Meta