1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
4 * Copyright (C) 2001 Seth Nickell
5 * Copyright (C) 2001 Maciej Stachowiak
7 * The Gnome Library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public License as
9 * published by the Free Software Foundation; either version 2 of the
10 * License, or (at your option) any later version.
12 * The Gnome Library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Library General Public License for more details.
17 * You should have received a copy of the GNU Library General Public
18 * License along with the Gnome Library; see the file COPYING.LIB. If not,
19 * write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 * Boston, MA 02111-1307, USA.
24 * Authors: Seth Nickell <snickell@stanford.edu>
25 * Maciej Stachowiak <mjs@noisehavoc.org>
26 * (reverse-engineered from code by Ian McKellar <yakk@yakk.net>)
30 #include "gnome-vfs-socket.h"
32 #include <glib/gmem.h>
34 struct GnomeVFSSocket {
35 GnomeVFSSocketImpl *impl;
41 * gnome_vfs_socket_new:
42 * @impl: an implementation of a socket, e.g. GnomeVFSSSL
43 * @connection: pointer to a connection object used by @impl to track
44 * state (the exact nature of @connection varies from implementation to
47 * Creates a new GnomeVFS Socket using the specific implementation
50 * Return value: a newly created socket
52 GnomeVFSSocket* gnome_vfs_socket_new (GnomeVFSSocketImpl *impl,
55 GnomeVFSSocket *socket;
57 socket = g_new0 (GnomeVFSSocket, 1);
59 socket->connection = connection;
65 * gnome_vfs_socket_write:
66 * @socket: socket to write data to
67 * @buffer: data to write to the socket
68 * @bytes: number of bytes from @buffer to write to @socket
69 * @bytes_written: pointer to a GnomeVFSFileSize, will contain
70 * the number of bytes actually written to the socket on return.
72 * Write @bytes bytes of data from @buffer to @socket.
74 * Return value: GnomeVFSResult indicating the success of the operation
77 gnome_vfs_socket_write (GnomeVFSSocket *socket,
80 GnomeVFSFileSize *bytes_written)
82 return socket->impl->write (socket->connection,
83 buffer, bytes, bytes_written);
87 * gnome_vfs_socket_close:
88 * @socket: the socket to be closed
90 * Close @socket, freeing any resources it may be using.
92 * Return value: GnomeVFSResult indicating the success of the operation
95 gnome_vfs_socket_close (GnomeVFSSocket *socket)
97 socket->impl->close (socket->connection);
102 * gnome_vfs_socket_read:
103 * @socket: socket to read data from
104 * @buffer: allocated buffer of at least @bytes bytes to be read into
105 * @bytes: number of bytes to read from @socket into @buffer
106 * @bytes_read: pointer to a GnomeVFSFileSize, will contain
107 * the number of bytes actually read from the socket on return.
109 * Read @bytes bytes of data from the @socket into @buffer.
111 * Return value: GnomeVFSResult indicating the success of the operation
114 gnome_vfs_socket_read (GnomeVFSSocket *socket,
116 GnomeVFSFileSize bytes,
117 GnomeVFSFileSize *bytes_read)
119 return socket->impl->read (socket->connection,
120 buffer, bytes, bytes_read);