ftp://ftp.redhat.com/pub/redhat/linux/rawhide/SRPMS/SRPMS/gnome-vfs2-2.3.8-1.src.rpm
[gnome-vfs-httpcaptive.git] / libgnomevfs / gnome-vfs-socket.c
1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
2 /* gnome-vfs-socket.c
3  *
4  * Copyright (C) 2001 Seth Nickell
5  * Copyright (C) 2001 Maciej Stachowiak
6  *
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.
11  *
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.
16  *
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. 
21  *
22  */
23 /*
24  * Authors: Seth Nickell <snickell@stanford.edu>
25  *          Maciej Stachowiak <mjs@noisehavoc.org>
26  *          (reverse-engineered from code by Ian McKellar <yakk@yakk.net>)
27  */
28
29 #include <config.h>
30 #include "gnome-vfs-socket.h"
31
32 #include <glib/gmem.h>
33
34 struct GnomeVFSSocket {
35         GnomeVFSSocketImpl *impl;
36         gpointer connection;
37 };
38
39
40 /**
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
45  * implementation)
46  *
47  * Creates a new GnomeVFS Socket using the specific implementation
48  * @impl.
49  *
50  * Return value: a newly created socket
51  **/
52 GnomeVFSSocket* gnome_vfs_socket_new (GnomeVFSSocketImpl *impl, 
53                                       void               *connection) 
54 {
55         GnomeVFSSocket *socket;
56         
57         socket = g_new0 (GnomeVFSSocket, 1);
58         socket->impl = impl;
59         socket->connection = connection; 
60         
61         return socket;
62 }
63
64 /**
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.
71  *
72  * Write @bytes bytes of data from @buffer to @socket.
73  *
74  * Return value: GnomeVFSResult indicating the success of the operation
75  **/
76 GnomeVFSResult  
77 gnome_vfs_socket_write (GnomeVFSSocket *socket, 
78                         gconstpointer buffer,
79                         int bytes, 
80                         GnomeVFSFileSize *bytes_written)
81 {
82         return socket->impl->write (socket->connection,
83                                     buffer, bytes, bytes_written);
84 }
85
86 /**
87  * gnome_vfs_socket_close:
88  * @socket: the socket to be closed
89  *
90  * Close @socket, freeing any resources it may be using.
91  *
92  * Return value: GnomeVFSResult indicating the success of the operation
93  **/
94 GnomeVFSResult  
95 gnome_vfs_socket_close (GnomeVFSSocket *socket)
96 {
97         socket->impl->close (socket->connection);
98         return GNOME_VFS_OK;
99 }
100
101 /**
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.
108  *
109  * Read @bytes bytes of data from the @socket into @buffer.
110  *
111  * Return value: GnomeVFSResult indicating the success of the operation
112  **/
113 GnomeVFSResult  
114 gnome_vfs_socket_read  (GnomeVFSSocket *socket, 
115                         gpointer buffer, 
116                         GnomeVFSFileSize bytes,
117                         GnomeVFSFileSize *bytes_read)
118 {
119         return socket->impl->read (socket->connection,
120                                    buffer, bytes, bytes_read);
121 }