Commit Graph

147 Commits

Author SHA1 Message Date
Dan Winship
634b692199 gsocket: Set SO_NOSIGPIPE on sockets on Darwin
This is a best-effort approach to preventing SIGPIPE emissions on Darwin
and iOS, where they continue to be intercepted by the Xcode debugger
even if SIG_IGN prevents them crashing the program.

This is similar to the existing code which sets MSG_NOSIGNAL on all
send() calls. MSG_NOSIGNAL doesn't exist on Darwin though.

Based on a patch from Philip Withnall.

https://bugzilla.gnome.org/show_bug.cgi?id=728730
2014-07-21 11:31:27 -04:00
Dan Winship
7b34e07ac4 gsocket: move set_fd_nonblocking() into g_socket_constructed() 2014-07-21 11:31:27 -04:00
Patrick Welche
afce39c228 gcredentials: add NetBSD support
https://bugzilla.gnome.org/show_bug.cgi?id=728256
2014-06-28 14:06:36 -04:00
Philip Withnall
00e733315d gsocket: Document that g_socket_create_source() holds a socket ref
This is quite important, as it means you can safely let the GSocket drop
out of scope while maintaining a reference to the GSource, and the
socket will remain open. That means fewer closure structures, simpler
code, and fewer allocations.

https://bugzilla.gnome.org/show_bug.cgi?id=732081
2014-06-23 16:24:47 +01:00
Philip Withnall
7f5cc2c3c5 gsocket: Add missing preconditions to g_socket_send_message()
https://bugzilla.gnome.org/show_bug.cgi?id=730190
2014-05-15 14:35:19 +01:00
Philip Withnall
2b247e1589 gio: Document that GSocket is not thread safe
https://bugzilla.gnome.org/show_bug.cgi?id=726318
2014-04-16 19:04:25 +01:00
Dan Winship
3da5d59078 gio: move Winsock error mapping to g_io_error_from_win32_error()
Rather than having special code in gsocket.c, handle Winsock errors
along with other Win32 errors in gioerror.c

Also, reference g_win32_error_message() from the
g_io_error_from_win32_error() docs, and update the
g_win32_error_message() docs to clarify that it works with Winsock
error codes too.
2014-03-30 11:55:47 -04:00
Olivier Crête
0c65f7e45a GSocket: ignore timed out state when not relevant
Do this by separating the timeout check from the other socket checks.

https://bugzilla.gnome.org/show_bug.cgi?id=726375
2014-03-23 16:17:09 -04:00
Ryan Lortie
8da795de4f gsocket: use check/prepare only on win32
There is no longer any code left in the check/prepare functions on UNIX,
so put %NULL in the GSourceFuncs vtable.

This also allows us to simplify some logic.

https://bugzilla.gnome.org/show_bug.cgi?id=724707
2014-02-22 10:25:42 -05:00
Ryan Lortie
e8f26efe0d gsocket: use _add_unix_fd() instead of _add_poll()
Use g_source_add_unix_fd() on UNIX instead of using a GPollFD.

https://bugzilla.gnome.org/show_bug.cgi?id=724707
2014-02-22 10:25:42 -05:00
Ryan Lortie
04aee2d920 gsocket: make use of g_source_set_ready_time()
Drop our own hand-rolled version of the same functionality.

https://bugzilla.gnome.org/show_bug.cgi?id=724707
2014-02-22 10:25:42 -05:00
Ryan Lortie
1f7100506a gsocket: don't abuse GPollFD.revents field
We are reusing the GPollFD.revents field of the source to store a
temporary value.  Use a local variable for that instead.

This is a refactor to make the next commit easier to understand.

https://bugzilla.gnome.org/show_bug.cgi?id=724707
2014-02-22 10:24:19 -05:00
Ryan Lortie
ff96f88e17 gsocket: use cancellable child source
Now that GCancellable's GSource is based on _set_ready_time() instead of
an fd, we should use it as a child source, instead of forcing the
creation of the fd and adding it as a poll.

https://bugzilla.gnome.org/show_bug.cgi?id=724707
2014-02-22 10:24:19 -05:00
Ryan Lortie
d8263dd793 gsocket: trivial typo fix
https://bugzilla.gnome.org/show_bug.cgi?id=724707
2014-02-22 10:24:19 -05:00
Dan Winship
4139b26f3e gsocket: fix g_socket_condition_timed_wait() recovery after EINTR
After getting an EINTR, g_socket_condition_timed_wait() has to adjust
its timeout, but it was trying to convert from nanoseconds to
microseconds by multiplying by 1000 rather than dividing... Oops.

https://bugzilla.gnome.org/show_bug.cgi?id=724239
2014-02-17 11:38:11 -05:00
Dan Winship
074df39681 Fix g_socket_get_available() with TCP on Windows
Windows needs a special inefficient hack to implement
g_socket_get_available() correctly for UDP sockets, but that hack
isn't needed for TCP, and in fact, might give the wrong answer in that
case. Fix it to only use the hack with UDP.

Also, fix that case to handle non-blocking sockets as well.

And add a test case for g_socket_get_available() with TCP.

https://bugzilla.gnome.org/show_bug.cgi?id=723422
2014-02-15 10:06:04 -05:00
Matthias Clasen
35066ed6c6 Docs: Drop entities, switch away from sgml mode
Since all element markup is now gone from the doc comments,
we can turn off the gtk-doc sgml mode, which means that from
now on, docbook markup is no longer allowed in doc comments.

To make this possible, we have to replace all remaining
entities in doc comments by their replacement text, & -> &
and so on.
2014-02-09 02:07:26 -05:00
Matthias Clasen
e7fd3de86d Eradicate links and xrefs
These are all replaced by markdown ref links.
2014-02-08 12:26:56 -05:00
Matthias Clasen
3232425785 Docs: replace <literal> by ` 2014-02-06 08:07:16 -05:00
Matthias Clasen
42cf80780b Docs: Big entity cleanup
Strip lots of entity use from |[ ]| examples (which are now
implicit CDATA). Also remove many redundant uses of <!-- -->.
2014-02-01 12:00:30 -05:00
Daniel Mustieles
078dbda148 Updated FSF's address 2014-01-31 14:31:55 +01:00
Dan Winship
3981cddbf8 Require POSIX.1 (1990) compliance on unix
Assume unix platforms support the original POSIX.1 standard.
Specifically, assume that if G_OS_UNIX, then we have chown(),
getcwd(), getgrgid(), getpwuid(), link(), <grp.h>, <pwd.h>,
<sys/types.h>, <sys/uio.h>, <sys/wait.h>, and <unistd.h>.

Additionally, since all versions of Windows that we care about also
have <sys/types.h>, we can remove HAVE_SYS_TYPES_H checks everywhere.

Also remove one include of <sys/times.h>, and the corresponding
configure check, since the include is not currently needed (and may
always have just been a typo for <sys/time.h>).

https://bugzilla.gnome.org/show_bug.cgi?id=710519
2013-11-20 09:17:42 -05:00
Dan Winship
5a269e5a90 gcredentials: add Solaris support
Based on patches from Igor Pashev.

https://bugzilla.gnome.org/show_bug.cgi?id=705029
2013-10-04 09:51:31 -04:00
Dan Winship
cedd697bf8 gcredentials: add internal macros to simplify all the #ifdefs
Rather than having lots of obscure platform-based #ifdefs all over
gio, define some macros in gcredentialsprivate.h, and use those to
simplify the rest of the code.

https://bugzilla.gnome.org/show_bug.cgi?id=701482
2013-10-04 09:51:31 -04:00
Svante Signell
1d4bb3f5d0 gio/gsocket.c: Fix error code checks when SOCK_CLOEXEC is defined but
not supported on GNU/Hurd.

https://bugzilla.gnome.org/show_bug.cgi?id=708266
2013-09-24 08:59:38 -04:00
Dan Winship
9fd0927e58 gsocket: Fix g_socket_get_available_bytes() on Windows and OS X
On Windows and OS X, FIONREAD on a UDP socket gets the total number of
bytes available, not the number of bytes available in the next packet,
which is the more useful number (and how the function always behaved
on Linux).

On OS X, fix this by using SO_NREAD. On Windows, fix this by doing a
MSG_PEEK recv() into a giant buffer, since there is apparently no
other way to get the information.

https://bugzilla.gnome.org/show_bug.cgi?id=686786
2013-08-31 11:40:44 -04:00
Dan Winship
11254b3c7d gsocket: make GSocketSource trigger on G_IO_NVAL
Getting G_IO_NVAL probably indicates bugs/race conditions in the
calling code, but if GSocket just ignores it, it will get stuck in an
infinite loop.
2013-08-29 09:25:42 -04:00
Sebastian Dröge
ab6b7dbc2e GSocket – GSocketSource finalizing not threadsafe on Windows
The requested_conditions list access is not threadsafe. When passing
the socket ownership from a GSource callback to another thread, which
also creates a GSocketSource for the socket, it can happen that the
original GSocketSource is finalized at the same time as the new one
is created. This would cause inconsistencies in the requested_conditions
list and can cause assertions or completely undefined behaviour.

https://bugzilla.gnome.org/show_bug.cgi?id=705027
2013-08-22 16:14:56 +02:00
Sebastian Dröge
01156b122c GSocket – Implement multicast interface selection on Windows
https://bugzilla.gnome.org/show_bug.cgi?id=697185
2013-08-19 12:28:20 -04:00
Dan Winship
547df5937c GSocket: fix g_socket_bind() allow_reuse semantics
With UDP sockets, g_socket_bind() with allow_reuse=TRUE on Linux
behaved in a way that the documentation didn't suggest, and that
didn't match other OSes. (Specifically, it allowed binding multiple
multicast sockets to the same address.)

Since this behavior is useful, and since allow_reuse didn't have any
other meaning with UDP sockets, update the docs to reflect the Linux
behavior, and make it do the same thing on non-Linux.

https://bugzilla.gnome.org/show_bug.cgi?id=689245
2013-08-17 13:26:42 -04:00
Dan Winship
2ea4af6f01 GSocket: fix broadcast documentation
The :broadcast property only affects sending broadcast packets, not
receiving them.
2013-08-17 13:26:42 -04:00
Dan Winship
54a76e24b3 gsocket: fix a cut-and-pasted error message 2013-07-30 09:13:18 -04:00
Dan Winship
8f80fbb2a7 Remove some unnecessary source prepare/check functions
GPollableSource and GSocket's "broken" source never trigger on their
own, so with the changes to GSources in the last cycle, their check
and prepare functions are unnecessary (and undesired).

https://bugzilla.gnome.org/show_bug.cgi?id=701511
2013-07-13 16:38:55 -04:00
Dan Winship
1da47d5ede gsourceclosure: use g_cclosure_marshal_generic
For the glib-defined source types, and any source type that defines a
closure callback but not a closure marshal, use
g_cclosure_marshal_generic. And then remove all the other remaining
source closure marshals.

https://bugzilla.gnome.org/show_bug.cgi?id=701511
2013-07-13 16:38:55 -04:00
Emmanuele Bassi
54cc43630d Rename the generated private data getter function
As it turns out, we have examples of internal functions called
type_name_get_private() in the wild (especially among older libraries),
so we need to use a name for the per-instance private data getter
function that hopefully won't conflict with anything.
2013-06-24 15:43:04 +01:00
Emmanuele Bassi
32747def4b gio: Use the new private instance data declaration
Use the newly added macros, and remove the explicit calls to
g_type_class_add_private().

https://bugzilla.gnome.org/show_bug.cgi?id=700035
2013-06-24 14:18:01 +01:00
Dan Winship
5932e16acd GNetworkMonitorNetlink: make the netlink socket cloexec
Use the same code GSocket does, to try SOCK_CLOEXEC first, and then
fall back to FD_CLOEXEC if it fails. (And fix that code to not call
fcntl if SOCK_CLOEXEC worked.)

https://bugzilla.gnome.org/show_bug.cgi?id=692332
2013-01-23 08:48:32 -05:00
Rico Tzschichholz
47c9b1e315 gio: add some missing array annotations with their element-type 2013-01-13 20:49:15 +01:00
PHO
f0f6c8d231 gsocket: Work around broken CMSG_FIRSTHDR()
As RFC 2292 points out, some platforms (e.g. Darwin 9.8.0) provide
CMSG_FIRSTHDR(msg) which just returns msg.msg_control without first
checking if msg.msg_controllen is non-zero. We need a workaround for
such platforms not to let g_socket_receive_message() segfault.

https://bugzilla.gnome.org/show_bug.cgi?id=690388
2012-12-18 13:31:02 -05:00
Dan Winship
df334d6e00 gsocket: improve sockopt handling for IPv4-wrapped-IPv6 sockets
On IPv6 sockets, set both the IPv4 and IPv6 versions of IP socket
options, in case the socket is (or might become) IPv4-wrapped. (But
ignore errors when setting the IPv4 version.)

Similarly, when joining or leaving a multicast group, pick the sockopt
to use based on the address family of the multicast address rather
than the address family of the socket.

https://bugzilla.gnome.org/show_bug.cgi?id=687092
2012-12-17 09:01:05 -05:00
Dan Winship
211ed1775d gsocket: add getsockopt/setsockopt wrappers
Add g_socket_get_option() and g_socket_set_option(), wrapping
getsockopt/setsockopt for the case of integer-valued options. Update
code to use these instead of the underlying calls.

https://bugzilla.gnome.org/show_bug.cgi?id=623187
2012-12-12 15:20:22 +01:00
Dan Winship
b377e69685 Add gnetworking.h
Install a public "gnetworking.h" header that can be used to include
the relevant OS-dependent networking headers. This does not really
abstract away unix-vs-windows however; error codes, in particular,
are incompatible.

gnetworkingprivate.h now contains just a few internal URI-related
functions

Also add a g_networking_init() function to gnetworking.h, which can be
used to explicitly initialize OS-level networking, rather than having
that happen as a side-effect of registering GInetAddress.

https://bugzilla.gnome.org/show_bug.cgi?id=623187
2012-12-12 15:20:22 +01:00
Dan Winship
aa1418c427 win32: work around broken winsock prototypes
Re-#define a few socket functions to work around winsock's prototypes
having, eg, "int *" rather than "unsigned int *", or "char *" rather
than "void *".

(Also fix two places that mistakenly assumed guint==guint32.)

https://bugzilla.gnome.org/show_bug.cgi?id=688109
2012-11-15 14:19:06 -05:00
Dan Winship
b8c13a01b6 win32: misc warning fixes
https://bugzilla.gnome.org/show_bug.cgi?id=688109
2012-11-15 14:19:06 -05:00
Wim Taymans
c2acbc0182 gsocket: fix joining/leaving multicast groups
Initialize the structure passed to setsockopt to 0 to avoid random
errors when joining or leaving a multicast group.

https://bugzilla.gnome.org/show_bug.cgi?id=688378
2012-11-15 11:09:00 -05:00
Dan Winship
9fb3082070 Revert "Return correct value for g_socket_get_available_bytes() on Windows and OSX"
This neither compiles nor does what it's supposed to on Windows.

This reverts commit 1e598600a1.
2012-11-11 14:14:04 -05:00
Sebastian Dröge
2bba1da306 Add caching for the receiver addresses for g_socket_receive_from()
https://bugzilla.gnome.org/show_bug.cgi?id=668842
2012-11-11 17:32:38 +01:00
Sebastian Dröge
1e598600a1 Return correct value for g_socket_get_available_bytes() on Windows and OSX
https://bugzilla.gnome.org/show_bug.cgi?id=686786
2012-11-09 21:57:50 -05:00
John Ralls
b65dac802e Fix poll able streams for Darwin (and probably BSD)
Darwin's poll doesn't change revents if there are no available events, though it returns 0. Initialize the fd.revents to 0 so that the test passes.

That reveals a test failure, though, because with socket streams it takes time for an event to pass through the socket. Provide an 80-usec delay to allow time for the propagation.
2012-11-09 09:23:01 -08:00
Matthias Clasen
6bee6dbce5 Miscellaneous string fixes
Typo and punctuation fixes, and some rewording, based
on a patch by Philip Withnall, bug
https://bugzilla.gnome.org/review?bug=628193
2012-08-16 23:02:41 -04:00