2 * Copyright (C) 2008 Benjamin Otte <otte@gnome.org>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301 USA
24 #include "swfdec_socket.h"
25 #include "swfdec_loader_internal.h"
30 * SECTION:SwfdecSocket
31 * @title: SwfdecSocket
32 * @short_description: object used for network connections
34 * SwfdecSockets are used to implement TCP streams. These are for example used
35 * to implement RTMP support or the XMLSocket script class. Backends are
36 * supposed to provide an implementation for this, as by default this class is
37 * unimplemented. However, swfdec-gtk or other convenience libraries provide
38 * a socket implementation by default.
40 * The socket implementation used by a #SwfdecPlayer can be set with the
41 * SwfdecPlayer:socket-type property.
47 * This is the base object used for providing input. It is abstract, create a
48 * subclass to provide your own socket implementation. All members are
54 * @connect: Connect the given newly created socket to the given hostname and
55 * port. If you encounter an error, call swfdec_stream_error(), but
56 * still make sure the socket object does not break.
57 * @send: Called to send data down the given socket. This function will only be
58 * called when the socket is open. The function is supposed to write as
59 * much data as possible to the socket and return the amount of data
60 * written. If not all data could be written, the socket is assumed to
61 * be full and no attempt at writing to it will be made until you call
62 * swfdec_socket_signal_writable().
64 * This is the socket class. When you create a subclass, you need to implement
65 * the functions listed above.
68 /*** SWFDEC_SOCKET ***/
70 G_DEFINE_TYPE (SwfdecSocket
, swfdec_socket
, SWFDEC_TYPE_STREAM
)
73 swfdec_socket_do_connect (SwfdecSocket
*socket
, SwfdecPlayer
*player
,
74 const char *hostname
, guint port
)
76 swfdec_stream_error (SWFDEC_STREAM (socket
), "no socket implementation exists");
80 swfdec_socket_do_send (SwfdecSocket
*socket
, SwfdecBuffer
*buffer
)
86 swfdec_socket_describe (SwfdecStream
*stream
)
88 /* FIXME: add host/port */
89 return G_OBJECT_TYPE_NAME (stream
);
93 swfdec_socket_class_init (SwfdecSocketClass
*klass
)
95 SwfdecStreamClass
*stream_class
= SWFDEC_STREAM_CLASS (klass
);
97 stream_class
->describe
= swfdec_socket_describe
;
99 klass
->connect
= swfdec_socket_do_connect
;
100 klass
->send
= swfdec_socket_do_send
;
104 swfdec_socket_init (SwfdecSocket
*socket
)
109 * swfdec_socket_send:
110 * @sock: a #SwfdecSocket
111 * @buffer: data to send to the stream, no reference will be taken.
113 * Tries to push the data of @buffer down the stream. If all of the data could
114 * be sent, @buffer->length will be returned. Otherwise the amount of data
115 * written will be returned and when more data can be written, the stream
116 * target's writable vfunc will be called.
119 swfdec_socket_send (SwfdecSocket
*sock
, SwfdecBuffer
*buffer
)
121 SwfdecSocketClass
*klass
;
123 g_return_val_if_fail (SWFDEC_IS_SOCKET (sock
), 0);
124 g_return_val_if_fail (swfdec_stream_is_open (SWFDEC_STREAM (sock
)), 0);
125 g_return_val_if_fail (buffer
!= NULL
, 0);
127 klass
= SWFDEC_SOCKET_GET_CLASS (sock
);
128 return klass
->send (sock
, buffer
);