Top |
The GnomeVFSSocket function family unifies network I/O through functions similar to the standard POSIX read/write functions. The main difference is that all operations are cancellable through the standard GnomeVFS cancellation mechanism and you can specify a maximum amount of time an operation may take through gnome_vfs_socket_set_timeout.
GnomeVFSResult (*GnomeVFSSocketReadFunc) (gpointer connection
,gpointer buffer
,GnomeVFSFileSize bytes
,GnomeVFSFileSize *bytes_read_out
,GnomeVFSCancellation *cancellation
);
This is a generic prototype for a function that reads from a socket.
This function is implemented by a GnomeVFSSocketImpl, and it defines how data
should be written to a buffer using the gnome_vfs_socket_read()
function which hides the socket implementation details.
GnomeVFSResult (*GnomeVFSSocketWriteFunc) (gpointer connection
,gconstpointer buffer
,GnomeVFSFileSize bytes
,GnomeVFSFileSize *bytes_written_out
,GnomeVFSCancellation *cancellation
);
This is a generic prototype for a function that writes to a socket.
This function is implemented by a GnomeVFSSocketImpl, and it defines how data
should be written to a buffer using the gnome_vfs_socket_write()
function which hides the socket implementation details.
void (*GnomeVFSSocketCloseFunc) (gpointer connection
,GnomeVFSCancellation *cancellation
);
This is a generic prototype for a function that closes a socket.
This function is implemented by a GnomeVFSSocketImpl, and it defines how an
open socket that was previously opened by gnome_vfs_socket_new()
should be closed using the gnome_vfs_socket_set_timeout()
function which
hides the socket implementation details.
GnomeVFSResult (*GnomeVFSSocketSetTimeoutFunc) (gpointer connection
,GTimeVal *timeout
,GnomeVFSCancellation *cancellation
);
This is a generic prototype for a function that sets a socket timeout.
This function is implemented by a GnomeVFSSocketImpl, and it defines how
a socket timeout should be set using
should be closed by the gnome_vfs_socket_close()
function which
hides the socket implementation details.
GnomeVFSSocket * gnome_vfs_socket_new (GnomeVFSSocketImpl *impl
,void *connection
);
Creates a new GnomeVFSSocket using the specific implementation
impl
.
impl |
an implementation of socket, e.g. GnomeVFSSSL. |
|
connection |
pointer to a connection object used by |
GnomeVFSResult gnome_vfs_socket_write (GnomeVFSSocket *socket
,gconstpointer buffer
,int bytes
,GnomeVFSFileSize *bytes_written
,GnomeVFSCancellation *cancellation
);
Write bytes
bytes of data from buffer
to socket
.
socket |
socket to write data to. |
|
buffer |
data to write to the socket. |
|
bytes |
number of bytes from |
|
bytes_written |
pointer to a GnomeVFSFileSize, will contain
the number of bytes actually written to the |
|
cancellation |
optional cancellation object. |
GnomeVFSResult gnome_vfs_socket_close (GnomeVFSSocket *socket
,GnomeVFSCancellation *cancellation
);
Close socket
, freeing any resources it may be using.
GnomeVFSResult gnome_vfs_socket_read (GnomeVFSSocket *socket
,gpointer buffer
,GnomeVFSFileSize bytes
,GnomeVFSFileSize *bytes_read
,GnomeVFSCancellation *cancellation
);
Read bytes
bytes of data from the socket
into buffer
.
socket |
socket to read data from. |
|
buffer |
allocated buffer of at least |
|
bytes |
number of bytes to read from |
|
bytes_read |
pointer to a GnomeVFSFileSize, will contain the number of bytes actually read from the socket on return. |
|
cancellation |
optional cancellation object. |
void
gnome_vfs_socket_free (GnomeVFSSocket *socket
);
Frees the memory allocated for socket
, but does
not call any GnomeVFSSocketImpl function.
Since: 2.8
GnomeVFSResult gnome_vfs_socket_set_timeout (GnomeVFSSocket *socket
,GTimeVal *timeout
,GnomeVFSCancellation *cancellation
);
Set a timeout of timeout
. If timeout
is NULL
, following operations
will block indefinitely).
Note if you set timeout
to 0 (means tv_sec and tv_usec are both 0)
every following operation will return immediately. (This can be used
for polling.)
socket |
socket to set the timeout of. |
|
timeout |
the timeout. |
|
cancellation |
optional cancellation object. |
Since: 2.8
typedef struct GnomeVFSSocket GnomeVFSSocket;
An handle to a generic unbuffered socket connection established with
gnome_vfs_socket_new()
.
The specifics of the underlying socket implementation are hidden inside the GnomeVFSSocketImpl passed on construction.
If you need buffered I/O, you will also have to create a GnomeVFSSocketBuffer.
typedef struct { GnomeVFSSocketReadFunc read; GnomeVFSSocketWriteFunc write; GnomeVFSSocketCloseFunc close; GnomeVFSSocketSetTimeoutFunc set_timeout; } GnomeVFSSocketImpl;
An implementation of a generic socket (i.e. of GnomeVFSSocket) encapsulating the details of how socket I/O works.
Please refer to GnomeVFSSSL for a sample implementation of this interface.
GnomeVFSSocketReadFunc |
A GnomeVFSSocketReadFunc function used for reading from a socket. |
|
GnomeVFSSocketWriteFunc |
A GnomeVFSSocketWriteFunc function used for writing to a socket. |
|
GnomeVFSSocketCloseFunc |
A GnomeVFSSocketCloseFunc function used for closing an open socket. |
|
GnomeVFSSocketSetTimeoutFunc |
A GnomeVFSSocketSetTimeoutFunc function used for setting a socket's timeout. |