1 /* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
3 /* GIO - GLib Input, Output and Streaming Library
5 * Copyright (C) 2011 Red Hat, Inc.
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 of the License, or (at your option) any later version.
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.
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/>.
23 #include "gnetworking.h"
27 * @title: gnetworking.h
28 * @short_description: System networking includes
29 * @include: gio/gnetworking.h
31 * The `<gio/gnetworking.h>` header can be included to get
32 * various low-level networking-related system headers, automatically
33 * taking care of certain portability issues for you.
35 * This can be used, for example, if you want to call setsockopt()
38 * Note that while WinSock has many of the same APIs as the
39 * traditional UNIX socket API, most of them behave at least slightly
40 * differently (particularly with respect to error handling). If you
41 * want your code to work under both UNIX and Windows, you will need
42 * to take these differences into account.
44 * Also, under GNU libc, certain non-portable functions are only visible
45 * in the headers if you define %_GNU_SOURCE before including them. Note
46 * that this symbol must be defined before including any headers, or it
47 * may not take effect.
53 * Initializes the platform networking libraries (eg, on Windows, this
54 * calls WSAStartup()). GLib will call this itself if it is needed, so
55 * you only need to call it if you directly call system networking
56 * functions (without calling any GLib networking functions first).
61 g_networking_init (void)
64 static volatile gsize inited = 0;
66 if (g_once_init_enter (&inited))
70 if (WSAStartup (MAKEWORD (2, 0), &wsadata) != 0)
71 g_error ("Windows Sockets could not be initialized");
73 g_once_init_leave (&inited, 1);