Coverage Report

Created: 2025-07-11 06:48

/src/tinysparql/subprojects/glib-2.80.3/gio/gtcpwrapperconnection.c
Line
Count
Source (jump to first uncovered line)
1
/* GIO - GLib Input, Output and Streaming Library
2
 *
3
 * Copyright © 2010 Collabora Ltd.
4
 *
5
 * SPDX-License-Identifier: LGPL-2.1-or-later
6
 *
7
 * This library is free software; you can redistribute it and/or
8
 * modify it under the terms of the GNU Lesser General Public
9
 * License as published by the Free Software Foundation; either
10
 * version 2.1 of the License, or (at your option) any later version.
11
 *
12
 * This 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
 * Lesser General Public License for more details.
16
 *
17
 * You should have received a copy of the GNU Lesser General
18
 * Public License along with this library; if not, see <http://www.gnu.org/licenses/>.
19
 *
20
 * Authors: Nicolas Dufresne <nicolas.dufresne@colllabora.co.uk>
21
 */
22
23
/**
24
 * GTcpWrapperConnection:
25
 *
26
 * A `GTcpWrapperConnection` can be used to wrap a [class@Gio.IOStream] that is
27
 * based on a [class@Gio.Socket], but which is not actually a
28
 * [class@Gio.SocketConnection]. This is used by [class@Gio.SocketClient] so
29
 * that it can always return a [class@Gio.SocketConnection], even when the
30
 * connection it has actually created is not directly a
31
 * [class@Gio.SocketConnection].
32
 *
33
 * Since: 2.28
34
 */
35
36
#include "config.h"
37
38
#include "gtcpwrapperconnection.h"
39
40
#include "gtcpconnection.h"
41
#include "glibintl.h"
42
43
struct _GTcpWrapperConnectionPrivate
44
{
45
  GIOStream *base_io_stream;
46
};
47
48
G_DEFINE_TYPE_WITH_PRIVATE (GTcpWrapperConnection, g_tcp_wrapper_connection, G_TYPE_TCP_CONNECTION)
49
50
enum
51
{
52
  PROP_NONE,
53
  PROP_BASE_IO_STREAM
54
};
55
56
static GInputStream *
57
g_tcp_wrapper_connection_get_input_stream (GIOStream *io_stream)
58
0
{
59
0
  GTcpWrapperConnection *connection = G_TCP_WRAPPER_CONNECTION (io_stream);
60
61
0
  return g_io_stream_get_input_stream (connection->priv->base_io_stream);
62
0
}
63
64
static GOutputStream *
65
g_tcp_wrapper_connection_get_output_stream (GIOStream *io_stream)
66
0
{
67
0
  GTcpWrapperConnection *connection = G_TCP_WRAPPER_CONNECTION (io_stream);
68
69
0
  return g_io_stream_get_output_stream (connection->priv->base_io_stream);
70
0
}
71
72
static void
73
g_tcp_wrapper_connection_get_property (GObject    *object,
74
               guint       prop_id,
75
               GValue     *value,
76
               GParamSpec *pspec)
77
0
{
78
0
  GTcpWrapperConnection *connection = G_TCP_WRAPPER_CONNECTION (object);
79
80
0
  switch (prop_id)
81
0
    {
82
0
     case PROP_BASE_IO_STREAM:
83
0
      g_value_set_object (value, connection->priv->base_io_stream);
84
0
      break;
85
86
0
     default:
87
0
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
88
0
    }
89
0
}
90
91
static void
92
g_tcp_wrapper_connection_set_property (GObject      *object,
93
                                        guint         prop_id,
94
                                        const GValue *value,
95
                                        GParamSpec   *pspec)
96
0
{
97
0
  GTcpWrapperConnection *connection = G_TCP_WRAPPER_CONNECTION (object);
98
99
0
  switch (prop_id)
100
0
    {
101
0
     case PROP_BASE_IO_STREAM:
102
0
      connection->priv->base_io_stream = g_value_dup_object (value);
103
0
      break;
104
105
0
     default:
106
0
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
107
0
    }
108
0
}
109
110
static void
111
g_tcp_wrapper_connection_finalize (GObject *object)
112
0
{
113
0
  GTcpWrapperConnection *connection = G_TCP_WRAPPER_CONNECTION (object);
114
115
0
  if (connection->priv->base_io_stream)
116
0
    g_object_unref (connection->priv->base_io_stream);
117
118
0
  G_OBJECT_CLASS (g_tcp_wrapper_connection_parent_class)->finalize (object);
119
0
}
120
121
static void
122
g_tcp_wrapper_connection_class_init (GTcpWrapperConnectionClass *klass)
123
0
{
124
0
  GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
125
0
  GIOStreamClass *stream_class = G_IO_STREAM_CLASS (klass);
126
127
0
  gobject_class->set_property = g_tcp_wrapper_connection_set_property;
128
0
  gobject_class->get_property = g_tcp_wrapper_connection_get_property;
129
0
  gobject_class->finalize = g_tcp_wrapper_connection_finalize;
130
131
0
  stream_class->get_input_stream = g_tcp_wrapper_connection_get_input_stream;
132
0
  stream_class->get_output_stream = g_tcp_wrapper_connection_get_output_stream;
133
134
  /**
135
   * GTcpWrapperConnection:base-io-stream:
136
   *
137
   * The wrapped [class@Gio.IOStream].
138
   *
139
   * Since: 2.28
140
   */
141
0
  g_object_class_install_property (gobject_class,
142
0
                                   PROP_BASE_IO_STREAM,
143
0
                                   g_param_spec_object ("base-io-stream", NULL, NULL,
144
0
                                                        G_TYPE_IO_STREAM,
145
0
                                                        G_PARAM_CONSTRUCT_ONLY |
146
0
                                                        G_PARAM_READWRITE |
147
0
                                                        G_PARAM_STATIC_STRINGS));
148
0
}
149
150
static void
151
g_tcp_wrapper_connection_init (GTcpWrapperConnection *connection)
152
0
{
153
0
  connection->priv = g_tcp_wrapper_connection_get_instance_private (connection);
154
0
}
155
156
/**
157
 * g_tcp_wrapper_connection_new:
158
 * @base_io_stream: the #GIOStream to wrap
159
 * @socket: the #GSocket associated with @base_io_stream
160
 *
161
 * Wraps @base_io_stream and @socket together as a #GSocketConnection.
162
 *
163
 * Returns: the new #GSocketConnection.
164
 *
165
 * Since: 2.28
166
 */
167
GSocketConnection *
168
g_tcp_wrapper_connection_new (GIOStream *base_io_stream,
169
            GSocket   *socket)
170
0
{
171
0
  g_return_val_if_fail (G_IS_IO_STREAM (base_io_stream), NULL);
172
0
  g_return_val_if_fail (G_IS_SOCKET (socket), NULL);
173
0
  g_return_val_if_fail (g_socket_get_family (socket) == G_SOCKET_FAMILY_IPV4 ||
174
0
      g_socket_get_family (socket) == G_SOCKET_FAMILY_IPV6, NULL);
175
0
  g_return_val_if_fail (g_socket_get_socket_type (socket) == G_SOCKET_TYPE_STREAM, NULL);
176
177
0
  return g_object_new (G_TYPE_TCP_WRAPPER_CONNECTION,
178
0
           "base-io-stream", base_io_stream,
179
0
           "socket", socket,
180
0
           NULL);
181
0
}
182
183
/**
184
 * g_tcp_wrapper_connection_get_base_io_stream:
185
 * @conn: a #GTcpWrapperConnection
186
 *
187
 * Gets @conn's base #GIOStream
188
 *
189
 * Returns: (transfer none): @conn's base #GIOStream
190
 */
191
GIOStream *
192
g_tcp_wrapper_connection_get_base_io_stream (GTcpWrapperConnection *conn)
193
0
{
194
0
  g_return_val_if_fail (G_IS_TCP_WRAPPER_CONNECTION (conn), NULL);
195
196
0
  return conn->priv->base_io_stream;
197
0
}