1 | /* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */ |
2 | |
3 | /* GIO - GLib Input, Output and Streaming Library |
4 | * |
5 | * Copyright (C) 2011 Red Hat, Inc. |
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 | |
21 | #include "config.h" |
22 | |
23 | #include "gnetworking.h" |
24 | |
25 | /** |
26 | * SECTION:gnetworking |
27 | * @title: gnetworking.h |
28 | * @short_description: System networking includes |
29 | * @include: gio/gnetworking.h |
30 | * |
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. |
34 | * |
35 | * This can be used, for example, if you want to call setsockopt() |
36 | * on a #GSocket. |
37 | * |
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. |
43 | * |
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. |
48 | */ |
49 | |
50 | /** |
51 | * g_networking_init: |
52 | * |
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). |
57 | * |
58 | * Since: 2.36 |
59 | */ |
60 | void |
61 | g_networking_init (void) |
62 | { |
63 | #ifdef G_OS_WIN32 |
64 | static gsize inited = 0; |
65 | |
66 | if (g_once_init_enter (&inited)) |
67 | { |
68 | WSADATA wsadata; |
69 | |
70 | if (WSAStartup (MAKEWORD (2, 0), &wsadata) != 0) |
71 | g_error ("Windows Sockets could not be initialized" ); |
72 | |
73 | g_once_init_leave (&inited, 1); |
74 | } |
75 | #endif |
76 | } |
77 | |