LCOV - code coverage report
Current view: top level - glib/gio/tests - socket-common.c (source / functions) Hit Total Coverage
Test: unnamed Lines: 0 47 0.0 %
Date: 2024-04-23 05:16:05 Functions: 0 6 0.0 %
Branches: 0 28 0.0 %

           Branch data     Line data    Source code
       1                 :            : /* #included into both socket-testclient.c and socket-testserver.c */
       2                 :            : 
       3                 :            : #ifdef G_OS_UNIX
       4                 :            : static const char *unix_socket_address_types[] = {
       5                 :            :   "invalid",
       6                 :            :   "anonymous",
       7                 :            :   "path",
       8                 :            :   "abstract",
       9                 :            :   "padded"
      10                 :            : };
      11                 :            : #endif
      12                 :            : 
      13                 :            : static char *
      14                 :          0 : socket_address_to_string (GSocketAddress *address)
      15                 :            : {
      16                 :          0 :   char *res = NULL;
      17                 :            : 
      18   [ #  #  #  #  :          0 :   if (G_IS_INET_SOCKET_ADDRESS (address))
             #  #  #  # ]
      19                 :            :     {
      20                 :            :       GInetAddress *inet_address;
      21                 :            :       char *str;
      22                 :            :       int port;
      23                 :            : 
      24                 :          0 :       inet_address = g_inet_socket_address_get_address (G_INET_SOCKET_ADDRESS (address));
      25                 :          0 :       str = g_inet_address_to_string (inet_address);
      26                 :          0 :       port = g_inet_socket_address_get_port (G_INET_SOCKET_ADDRESS (address));
      27                 :          0 :       res = g_strdup_printf ("%s:%d", str, port);
      28                 :          0 :       g_free (str);
      29                 :            :     }
      30                 :            : #ifdef G_OS_UNIX
      31   [ #  #  #  #  :          0 :   else if (G_IS_UNIX_SOCKET_ADDRESS (address))
             #  #  #  # ]
      32                 :            :     {
      33                 :          0 :       GUnixSocketAddress *uaddr = G_UNIX_SOCKET_ADDRESS (address);
      34                 :            : 
      35                 :          0 :       res = g_strdup_printf ("%s:%s",
      36                 :          0 :                              unix_socket_address_types[g_unix_socket_address_get_address_type (uaddr)],
      37                 :            :                              g_unix_socket_address_get_path (uaddr));
      38                 :            :     }
      39                 :            : #endif
      40                 :            : 
      41                 :          0 :   return res;
      42                 :            : }
      43                 :            : 
      44                 :            : static GSocketAddress *
      45                 :          0 : socket_address_from_string (const char *name)
      46                 :            : {
      47                 :            : #ifdef G_OS_UNIX
      48                 :            :   gsize i, len;
      49                 :            : 
      50         [ #  # ]:          0 :   for (i = 0; i < G_N_ELEMENTS (unix_socket_address_types); i++)
      51                 :            :     {
      52                 :          0 :       len = strlen (unix_socket_address_types[i]);
      53         [ #  # ]:          0 :       if (!strncmp (name, unix_socket_address_types[i], len) &&
      54         [ #  # ]:          0 :           name[len] == ':')
      55                 :            :         {
      56                 :          0 :           return g_unix_socket_address_new_with_type (name + len + 1, -1,
      57                 :            :                                                       (GUnixSocketAddressType)i);
      58                 :            :         }
      59                 :            :     }
      60                 :            : #endif
      61                 :          0 :   return NULL;
      62                 :            : }
      63                 :            : 
      64                 :            : static gboolean
      65                 :          0 : source_ready (GPollableInputStream *stream,
      66                 :            :               gpointer              data)
      67                 :            : {
      68                 :          0 :   g_main_loop_quit (loop);
      69                 :          0 :   return FALSE;
      70                 :            : }
      71                 :            : 
      72                 :            : static void
      73                 :          0 : ensure_socket_condition (GSocket      *socket,
      74                 :            :                          GIOCondition  condition,
      75                 :            :                          GCancellable *cancellable)
      76                 :            : {
      77                 :            :   GSource *source;
      78                 :            : 
      79         [ #  # ]:          0 :   if (!non_blocking)
      80                 :          0 :     return;
      81                 :            : 
      82                 :          0 :   source = g_socket_create_source (socket, condition, cancellable);
      83                 :          0 :   g_source_set_callback (source,
      84                 :            :                          (GSourceFunc) source_ready,
      85                 :            :                          NULL, NULL);
      86                 :          0 :   g_source_attach (source, NULL);
      87                 :          0 :   g_source_unref (source);
      88                 :          0 :   g_main_loop_run (loop);
      89                 :            : }
      90                 :            : 
      91                 :            : static void
      92                 :          0 : ensure_connection_condition (GIOStream    *stream,
      93                 :            :                              GIOCondition  condition,
      94                 :            :                              GCancellable *cancellable)
      95                 :            : {
      96                 :            :   GSource *source;
      97                 :            : 
      98         [ #  # ]:          0 :   if (!non_blocking)
      99                 :          0 :     return;
     100                 :            : 
     101         [ #  # ]:          0 :   if (condition & G_IO_IN)
     102                 :          0 :     source = g_pollable_input_stream_create_source (G_POLLABLE_INPUT_STREAM (g_io_stream_get_input_stream (stream)), cancellable);
     103                 :            :   else
     104                 :          0 :     source = g_pollable_output_stream_create_source (G_POLLABLE_OUTPUT_STREAM (g_io_stream_get_output_stream (stream)), cancellable);
     105                 :            : 
     106                 :          0 :   g_source_set_callback (source,
     107                 :            :                          (GSourceFunc) source_ready,
     108                 :            :                          NULL, NULL);
     109                 :          0 :   g_source_attach (source, NULL);
     110                 :          0 :   g_source_unref (source);
     111                 :          0 :   g_main_loop_run (loop);
     112                 :            : }
     113                 :            : 
     114                 :            : static gpointer
     115                 :          0 : cancel_thread (gpointer data)
     116                 :            : {
     117                 :          0 :   GCancellable *cancellable = data;
     118                 :            : 
     119                 :          0 :   g_usleep (1000*1000*cancel_timeout);
     120                 :          0 :   g_print ("Cancelling\n");
     121                 :          0 :   g_cancellable_cancel (cancellable);
     122                 :          0 :   return NULL;
     123                 :            : }

Generated by: LCOV version 1.14