loudmouth/lm-socket.c
author Ryan Schmidt <git@ryandesign.com>
Fri, 09 Jul 2021 10:38:43 -0500
changeset 742 ad6ffcac88a4
parent 690 7ccf2113ec5f
permissions -rw-r--r--
Fix typo: GnuTSL -> GnuTLS committer: GitHub <noreply@github.com>
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
516
4dd3aa6b83e5 Change the tab width to 4 steps in the emacs headers
Mikael Hallendal <micke@imendio.com>
parents: 515
diff changeset
     1
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
432
63a049d146c3 Added basic API for the new LmSocket
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
     2
/*
63a049d146c3 Added basic API for the new LmSocket
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
     3
 * Copyright (C) 2008 Imendio AB
63a049d146c3 Added basic API for the new LmSocket
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
     4
 *
63a049d146c3 Added basic API for the new LmSocket
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
     5
 * This program is free software; you can redistribute it and/or
63a049d146c3 Added basic API for the new LmSocket
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
     6
 * modify it under the terms of the GNU Lesser General Public License as
63a049d146c3 Added basic API for the new LmSocket
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
     7
 * published by the Free Software Foundation; either version 2 of the
63a049d146c3 Added basic API for the new LmSocket
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
     8
 * License, or (at your option) any later version.
63a049d146c3 Added basic API for the new LmSocket
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
     9
 *
63a049d146c3 Added basic API for the new LmSocket
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    10
 * This program is distributed in the hope that it will be useful,
63a049d146c3 Added basic API for the new LmSocket
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
63a049d146c3 Added basic API for the new LmSocket
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
63a049d146c3 Added basic API for the new LmSocket
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    13
 * Lesser General Public License for more details.
63a049d146c3 Added basic API for the new LmSocket
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    14
 *
63a049d146c3 Added basic API for the new LmSocket
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    15
 * You should have received a copy of the GNU Lesser General Public
690
7ccf2113ec5f Update the postal address of the FSF
Frank Zschockelt <lm@freakysoft.de>
parents: 607
diff changeset
    16
 * License along with this program; if not, see <https://www.gnu.org/licenses>
432
63a049d146c3 Added basic API for the new LmSocket
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    17
 */
63a049d146c3 Added basic API for the new LmSocket
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    18
63a049d146c3 Added basic API for the new LmSocket
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    19
#include <config.h>
63a049d146c3 Added basic API for the new LmSocket
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    20
434
579db9f99cc5 Worked on the LmSocket interface and added a LmSoupSocket class.
Mikael Hallendal <micke@imendio.com>
parents: 433
diff changeset
    21
#include "lm-marshal.h"
432
63a049d146c3 Added basic API for the new LmSocket
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    22
#include "lm-socket.h"
63a049d146c3 Added basic API for the new LmSocket
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    23
433
2ed69f025f4a Made LmSocket into an interface and hooked up implementation of it in LmTcpSocket.
Mikael Hallendal <micke@imendio.com>
parents: 432
diff changeset
    24
static void    socket_base_init (LmSocketIface *iface);
432
63a049d146c3 Added basic API for the new LmSocket
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    25
434
579db9f99cc5 Worked on the LmSocket interface and added a LmSoupSocket class.
Mikael Hallendal <micke@imendio.com>
parents: 433
diff changeset
    26
enum {
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
    27
    READABLE,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
    28
    WRITABLE,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
    29
    DISCONNECTED,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
    30
    LAST_SIGNAL
434
579db9f99cc5 Worked on the LmSocket interface and added a LmSoupSocket class.
Mikael Hallendal <micke@imendio.com>
parents: 433
diff changeset
    31
};
579db9f99cc5 Worked on the LmSocket interface and added a LmSoupSocket class.
Mikael Hallendal <micke@imendio.com>
parents: 433
diff changeset
    32
579db9f99cc5 Worked on the LmSocket interface and added a LmSoupSocket class.
Mikael Hallendal <micke@imendio.com>
parents: 433
diff changeset
    33
static guint signals[LAST_SIGNAL] = { 0 };
579db9f99cc5 Worked on the LmSocket interface and added a LmSoupSocket class.
Mikael Hallendal <micke@imendio.com>
parents: 433
diff changeset
    34
433
2ed69f025f4a Made LmSocket into an interface and hooked up implementation of it in LmTcpSocket.
Mikael Hallendal <micke@imendio.com>
parents: 432
diff changeset
    35
GType
2ed69f025f4a Made LmSocket into an interface and hooked up implementation of it in LmTcpSocket.
Mikael Hallendal <micke@imendio.com>
parents: 432
diff changeset
    36
lm_socket_get_type (void)
2ed69f025f4a Made LmSocket into an interface and hooked up implementation of it in LmTcpSocket.
Mikael Hallendal <micke@imendio.com>
parents: 432
diff changeset
    37
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
    38
    static GType iface_type = 0;
432
63a049d146c3 Added basic API for the new LmSocket
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    39
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
    40
    if (!iface_type) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
    41
        static const GTypeInfo iface_info = {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
    42
            sizeof (LmSocketIface),
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
    43
            (GBaseInitFunc)     socket_base_init,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
    44
            (GBaseFinalizeFunc) NULL,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
    45
        };
432
63a049d146c3 Added basic API for the new LmSocket
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    46
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
    47
        iface_type = g_type_register_static (G_TYPE_INTERFACE,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
    48
                                             "LmSocketIface",
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
    49
                                             &iface_info,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
    50
                                             0);
433
2ed69f025f4a Made LmSocket into an interface and hooked up implementation of it in LmTcpSocket.
Mikael Hallendal <micke@imendio.com>
parents: 432
diff changeset
    51
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
    52
        g_type_interface_add_prerequisite (iface_type, G_TYPE_OBJECT);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
    53
    }
433
2ed69f025f4a Made LmSocket into an interface and hooked up implementation of it in LmTcpSocket.
Mikael Hallendal <micke@imendio.com>
parents: 432
diff changeset
    54
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
    55
    return iface_type;
432
63a049d146c3 Added basic API for the new LmSocket
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    56
}
63a049d146c3 Added basic API for the new LmSocket
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    57
63a049d146c3 Added basic API for the new LmSocket
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    58
static void
433
2ed69f025f4a Made LmSocket into an interface and hooked up implementation of it in LmTcpSocket.
Mikael Hallendal <micke@imendio.com>
parents: 432
diff changeset
    59
socket_base_init (LmSocketIface *iface)
432
63a049d146c3 Added basic API for the new LmSocket
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    60
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
    61
    static gboolean initialized = FALSE;
432
63a049d146c3 Added basic API for the new LmSocket
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    62
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
    63
    if (!initialized) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
    64
        signals[READABLE] =
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
    65
            g_signal_new ("readable",
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
    66
                          LM_TYPE_SOCKET,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
    67
                          G_SIGNAL_RUN_LAST,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
    68
                          0,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
    69
                          NULL, NULL,
521
50294ce6587e Updated the build system to use a build directory and a common marshal Makefile.
Mikael Hallendal <micke@imendio.com>
parents: 518
diff changeset
    70
                          _lm_marshal_VOID__VOID,
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
    71
                          G_TYPE_NONE,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
    72
                          0);
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 521
diff changeset
    73
        signals[WRITABLE] =
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
    74
            g_signal_new ("writable",
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
    75
                          LM_TYPE_SOCKET,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
    76
                          G_SIGNAL_RUN_LAST,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
    77
                          0,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
    78
                          NULL, NULL,
521
50294ce6587e Updated the build system to use a build directory and a common marshal Makefile.
Mikael Hallendal <micke@imendio.com>
parents: 518
diff changeset
    79
                          _lm_marshal_VOID__VOID,
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
    80
                          G_TYPE_NONE,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
    81
                          0);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
    82
        signals[DISCONNECTED] =
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
    83
            g_signal_new ("disconnected",
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
    84
                          LM_TYPE_SOCKET,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
    85
                          G_SIGNAL_RUN_LAST,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
    86
                          0,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
    87
                          NULL, NULL,
521
50294ce6587e Updated the build system to use a build directory and a common marshal Makefile.
Mikael Hallendal <micke@imendio.com>
parents: 518
diff changeset
    88
                          _lm_marshal_VOID__VOID,
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
    89
                          G_TYPE_NONE,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
    90
                          0);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
    91
        initialized = TRUE;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
    92
    }
432
63a049d146c3 Added basic API for the new LmSocket
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    93
}
63a049d146c3 Added basic API for the new LmSocket
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    94
63a049d146c3 Added basic API for the new LmSocket
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    95
LmSocket *
63a049d146c3 Added basic API for the new LmSocket
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    96
lm_socket_new (const gchar *host, guint port)
63a049d146c3 Added basic API for the new LmSocket
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    97
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
    98
    g_return_val_if_fail (host != NULL, NULL);
433
2ed69f025f4a Made LmSocket into an interface and hooked up implementation of it in LmTcpSocket.
Mikael Hallendal <micke@imendio.com>
parents: 432
diff changeset
    99
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   100
    return NULL;
432
63a049d146c3 Added basic API for the new LmSocket
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   101
}
63a049d146c3 Added basic API for the new LmSocket
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   102
63a049d146c3 Added basic API for the new LmSocket
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   103
/* Use DNS lookup to find the port and the host */
63a049d146c3 Added basic API for the new LmSocket
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   104
LmSocket *
433
2ed69f025f4a Made LmSocket into an interface and hooked up implementation of it in LmTcpSocket.
Mikael Hallendal <micke@imendio.com>
parents: 432
diff changeset
   105
lm_socket_new_to_service (const gchar *service)
432
63a049d146c3 Added basic API for the new LmSocket
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   106
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   107
    g_return_val_if_fail (service != NULL, NULL);
433
2ed69f025f4a Made LmSocket into an interface and hooked up implementation of it in LmTcpSocket.
Mikael Hallendal <micke@imendio.com>
parents: 432
diff changeset
   108
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   109
    return NULL;
432
63a049d146c3 Added basic API for the new LmSocket
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   110
}
63a049d146c3 Added basic API for the new LmSocket
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   111
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 521
diff changeset
   112
void
432
63a049d146c3 Added basic API for the new LmSocket
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   113
lm_socket_connect (LmSocket *socket)
63a049d146c3 Added basic API for the new LmSocket
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   114
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   115
    g_return_if_fail (LM_IS_SOCKET (socket));
433
2ed69f025f4a Made LmSocket into an interface and hooked up implementation of it in LmTcpSocket.
Mikael Hallendal <micke@imendio.com>
parents: 432
diff changeset
   116
2ed69f025f4a Made LmSocket into an interface and hooked up implementation of it in LmTcpSocket.
Mikael Hallendal <micke@imendio.com>
parents: 432
diff changeset
   117
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   118
    /* Initiate the connection process                 */
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   119
    /* DNS lookup, connect thing, create IOchannel etc */
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   120
    if (!LM_SOCKET_GET_IFACE(socket)->write) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   121
        g_assert_not_reached ();
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   122
    }
433
2ed69f025f4a Made LmSocket into an interface and hooked up implementation of it in LmTcpSocket.
Mikael Hallendal <micke@imendio.com>
parents: 432
diff changeset
   123
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   124
    LM_SOCKET_GET_IFACE(socket)->connect (socket);
432
63a049d146c3 Added basic API for the new LmSocket
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   125
}
63a049d146c3 Added basic API for the new LmSocket
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   126
63a049d146c3 Added basic API for the new LmSocket
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   127
gboolean
433
2ed69f025f4a Made LmSocket into an interface and hooked up implementation of it in LmTcpSocket.
Mikael Hallendal <micke@imendio.com>
parents: 432
diff changeset
   128
lm_socket_write (LmSocket *socket, gchar *buf, gsize len)
432
63a049d146c3 Added basic API for the new LmSocket
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   129
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   130
    g_return_val_if_fail (LM_IS_SOCKET (socket), FALSE);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   131
    g_return_val_if_fail (buf != NULL, FALSE);
433
2ed69f025f4a Made LmSocket into an interface and hooked up implementation of it in LmTcpSocket.
Mikael Hallendal <micke@imendio.com>
parents: 432
diff changeset
   132
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   133
    if (!LM_SOCKET_GET_IFACE(socket)->write) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   134
        g_assert_not_reached ();
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   135
    }
433
2ed69f025f4a Made LmSocket into an interface and hooked up implementation of it in LmTcpSocket.
Mikael Hallendal <micke@imendio.com>
parents: 432
diff changeset
   136
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   137
    return LM_SOCKET_GET_IFACE(socket)->write (socket, buf, len);
432
63a049d146c3 Added basic API for the new LmSocket
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   138
}
63a049d146c3 Added basic API for the new LmSocket
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   139
63a049d146c3 Added basic API for the new LmSocket
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   140
gboolean
63a049d146c3 Added basic API for the new LmSocket
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   141
lm_socket_read (LmSocket *socket,
63a049d146c3 Added basic API for the new LmSocket
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   142
                gchar    *buf,
63a049d146c3 Added basic API for the new LmSocket
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   143
                gsize     buf_len,
441
b666e4d63a3a Some more work on the soup socket
Mikael Hallendal <micke@imendio.com>
parents: 436
diff changeset
   144
                gsize    *read_len)
432
63a049d146c3 Added basic API for the new LmSocket
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   145
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   146
    g_return_val_if_fail (LM_IS_SOCKET (socket), FALSE);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   147
    g_return_val_if_fail (buf != NULL, FALSE);
433
2ed69f025f4a Made LmSocket into an interface and hooked up implementation of it in LmTcpSocket.
Mikael Hallendal <micke@imendio.com>
parents: 432
diff changeset
   148
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   149
    if (!LM_SOCKET_GET_IFACE(socket)->read) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   150
        g_assert_not_reached ();
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   151
    }
433
2ed69f025f4a Made LmSocket into an interface and hooked up implementation of it in LmTcpSocket.
Mikael Hallendal <micke@imendio.com>
parents: 432
diff changeset
   152
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   153
    return LM_SOCKET_GET_IFACE(socket)->read (socket, buf, buf_len, read_len);
432
63a049d146c3 Added basic API for the new LmSocket
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   154
}
63a049d146c3 Added basic API for the new LmSocket
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   155
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 521
diff changeset
   156
void
432
63a049d146c3 Added basic API for the new LmSocket
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   157
lm_socket_disconnect (LmSocket *socket)
63a049d146c3 Added basic API for the new LmSocket
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   158
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   159
    g_return_if_fail (LM_IS_SOCKET (socket));
433
2ed69f025f4a Made LmSocket into an interface and hooked up implementation of it in LmTcpSocket.
Mikael Hallendal <micke@imendio.com>
parents: 432
diff changeset
   160
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   161
    if (!LM_SOCKET_GET_IFACE(socket)->disconnect) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   162
        g_assert_not_reached ();
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   163
    }
433
2ed69f025f4a Made LmSocket into an interface and hooked up implementation of it in LmTcpSocket.
Mikael Hallendal <micke@imendio.com>
parents: 432
diff changeset
   164
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   165
    LM_SOCKET_GET_IFACE(socket)->disconnect (socket);
432
63a049d146c3 Added basic API for the new LmSocket
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   166
}
63a049d146c3 Added basic API for the new LmSocket
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   167