Commit Graph

92 Commits

Author SHA1 Message Date
Rémi Denis-Courmont 6ee1cb5740 libavformat: use MSG_NOSIGNAL when applicable
If the remote end of a connection oriented socket hangs up, generating
an EPIPE error is preferable over an unhandled SIGPIPE signal.

Signed-off-by: Martin Storsjö <martin@martin.st>
2014-08-25 10:49:14 +03:00
Martin Storsjö a6a4596e12 tcp: Explicitly convert a pointer to a boolean integer
This fixes warnings about making integers from pointers without
a cast, and avoids the theoretical case where the lower 32 bits of
the pointer would all be zero where the implicit cast wouldn't give
the right result.

Signed-off-by: Martin Storsjö <martin@martin.st>
2013-09-09 23:57:04 +03:00
Martin Storsjö abe5268c33 tcp: Use a different log message and level if there's more addresses to try
This lowers the level of warnings printed if trying to connect
to a host name that provides both v6 and v4 addresses but the
service only is available on the v4 address (often occurring for
'localhost', with servers that aren't v6-aware).

Signed-off-by: Martin Storsjö <martin@martin.st>
2013-08-06 10:39:39 +03:00
Luca Barbato bb9378251a network: Use SOCK_CLOEXEC when available 2013-08-05 16:13:36 +02:00
Luca Barbato 9835abb6d6 network: uniform ff_listen_bind and ff_listen_connect
Document the functions and have both use a millisecond timeout and
check for interrupt.
2013-06-04 14:56:52 +02:00
Luca Barbato f849a77e67 network: factor out connect-listening code
Introduce ff_listen_connect, to be shared with the other
non-tcp network protocols.
2013-06-01 15:29:53 +02:00
Luca Barbato 28306e6d62 network: factor out bind-listening code
Introduce ff_listen_bind, to be shared with the other non-tcp
network protocols.
2013-06-01 15:29:53 +02:00
Jordi Ortiz f9a9a14862 tcp: add port missing error message
Without this patch a user a bit absent-minded may not notice that
the connection doesn't work because the port is missing.

Signed-off-by: Martin Storsjö <martin@martin.st>
2012-07-25 20:30:39 +03:00
Jordi Ortiz 5427df0186 tcp: add initial timeout limit for incoming connections
Signed-off-by: Martin Storsjö <martin@martin.st>
2012-07-09 17:30:19 +03:00
Jordi Ortiz ef882e464a tcp: Pass NULL as hostname to getaddrinfo if the string is empty
This gives you the proper v4 or v6 version of the "any address",
allowing receiving connections on any address on the machine.

Signed-off-by: Martin Storsjö <martin@martin.st>
2012-06-27 14:04:02 +03:00
Jordi Ortiz 58f3e09ee4 tcp: Set AI_PASSIVE when the socket will be used for listening
Signed-off-by: Martin Storsjö <martin@martin.st>
2012-06-27 14:04:02 +03:00
Martin Storsjö 39dba5aa1b network: Include unistd.h from network.h
This heaader is required for close() for sockets in network
code. For winsock, the equivalent function is defined in the
winsock2.h header.

This avoids having the HAVE_UNISTD_H in all files dealing with
raw sockets.

Signed-off-by: Martin Storsjö <martin@martin.st>
2012-06-26 17:22:21 +03:00
Mans Rullgard 6501dcfb5e Remove unnecessary inclusions of [sys/]time.h
Signed-off-by: Mans Rullgard <mans@mansr.com>
2012-06-20 11:46:46 +01:00
Martin Storsjö bb6c1abb0e tcp: Check the return value from getsockopt
Make sure we actually have an error code in ret, in case
getsockopt failed.

Signed-off-by: Martin Storsjö <martin@martin.st>
2012-06-19 20:25:07 +03:00
Martin Storsjö a840cdda6c network: Use av_strerror for getting error messages
Also use ff_neterrno() instead of errno directly (which doesn't work
on windows), for getting the error code.

Signed-off-by: Martin Storsjö <martin@martin.st>
2012-06-19 20:24:55 +03:00
Jordi Ortiz a7cc78cb11 tcp: Check the listen call
Signed-off-by: Martin Storsjö <martin@martin.st>
2012-06-17 13:22:36 +03:00
Martin Storsjö b7c3772be8 tcp: Try enabling SO_REUSEADDR when listening
Signed-off-by: Martin Storsjö <martin@martin.st>
2012-06-01 01:56:22 +03:00
Martin Storsjö 641f4a885f tcp: Check the return values from bind and accept
Signed-off-by: Martin Storsjö <martin@martin.st>
2012-06-01 01:56:21 +03:00
Samuel Pitoiset 4a9ca93556 tcp: Allow signalling end of reading/writing
tcp_shutdown() isn't needed at the moment, but is added for
consistency to explain how the function is supposed to be used.

Signed-off-by: Martin Storsjö <martin@martin.st>
2012-05-22 23:16:42 +03:00
Diego Biurrun a92be9b856 Replace memset(0) by zero initializations.
Also remove one pointless zero initialization in rangecoder.c.
2012-03-28 09:38:33 +02:00
Martin Storsjö 32b83aeec1 avio: Add an URLProtocol flag for indicating that a protocol uses network
This definition is in two files, since the definitions will move
to the private header at the next bump.

Signed-off-by: Martin Storsjö <martin@martin.st>
2012-01-05 23:56:52 +02:00
Martin Storsjö 7e58050590 proto: Use .priv_data_size to allocate the private context
This simplifies the open functions by avoiding one function
call that needs error checking, reducing the amount of
extra bulk code.

Signed-off-by: Martin Storsjö <martin@martin.st>
2011-12-01 13:47:26 +02:00
Martin Storsjö 9957cdbfd5 avformat: Use ff_check_interrupt 2011-11-13 13:08:13 +01:00
Luca Barbato ebb6b27ad9 tcp: make connect() timeout properly
The connect() timeout can take minutes, gets misreported as EIO and
isn't interruptible.
2011-05-27 09:42:14 +02:00
Martin Storsjö c60112f268 libavformat: Make protocols pass URLContext as log context where available
Since the libavformat major bump, URLContext contains an AVClass,
making it a usable log context.

Signed-off-by: Martin Storsjö <martin@martin.st>
2011-04-20 14:59:45 +03:00
Anton Khirnov f35ff97f2e lavf: use designated initializers for all protocols
This is more readable and makes it easier to reorder URLProtocol
members.
2011-04-08 11:08:26 +02:00
Anton Khirnov 5cec897105 avio: move extern url_interrupt_cb declaration from avio.h to url.h 2011-04-07 18:11:24 +02:00
Anton Khirnov f87b1b373a avio: AVIO_ prefixes for URL_ open flags. 2011-04-07 18:07:16 +02:00
Luca Barbato 3d42d4937b proto: introduce listen option in tcp
This way is possible to have simple micro-server act like

ffmpeg -i file.nut -vcodec copy -acodec copy -f nut tcp://foo:1234?listen
2011-04-07 02:54:30 +02:00
Luca Barbato ebba2b3e2a proto: factor ff_network_wait_fd and use it on udp
Support the URL_FLAG_NONBLOCK semantic and uniform the protocol.
The quick retry loop is already part of retry_transfer_wrapper.

The polling routine is common to the network protocols:
udp, tcp and, once merged, sctp.
2011-04-07 02:53:55 +02:00
Mans Rullgard 2912e87a6c Replace FFmpeg with Libav in licence headers
Signed-off-by: Mans Rullgard <mans@mansr.com>
2011-03-19 13:33:20 +00:00
Nicolas George c76374c6db Use AVERROR_EXIT with url_interrupt_cb.
Functions interrupted by url_interrupt_cb should not be restarted.
Therefore using AVERROR(EINTR) was wrong, as it did not allow to distinguish
when the underlying system call was interrupted and actually needed to be
restarted.

This fixes roundup issues 2657 and 2659 (ffplay not exiting for streamed
content).

Signed-off-by: Nicolas George <nicolas.george@normalesup.org>
Signed-off-by: Ronald S. Bultje <rsbultje@gmail.com>
2011-03-15 08:09:19 -04:00
Martin Storsjö 28c4741a66 libavformat: Remove FF_NETERRNO()
Map EAGAIN and EINTR from ff_neterrno to the normal AVERROR()
error codes. Provide fallback definitions of other errno.h network
errors, mapping them to the corresponding winsock errors.

This eases catching these error codes in common code, without having
to distinguish between FF_NETERRNO(EAGAIN) and AVERROR(EAGAIN).

This fixes roundup issue 2614, unbreaking blocking network IO on
windows.

Signed-off-by: Ronald S. Bultje <rsbultje@gmail.com>
2011-02-23 07:21:31 -05:00
Nicolas George ad3cffb68f Non-blocking protocol: TCP
Signed-off-by: Nicolas George <nicolas.george@normalesup.org>
Signed-off-by: Ronald S. Bultje <rsbultje@gmail.com>
2011-02-05 20:31:38 -05:00
Nicolas George 51b317d2e9 TCP: factor the poll() call
Signed-off-by: Nicolas George <nicolas.george@normalesup.org>
Signed-off-by: Ronald S. Bultje <rsbultje@gmail.com>
2011-02-03 20:58:32 -05:00
Luca Barbato a8475bbdb6 os: replace select with poll
Select has limitations on the fd values it could accept and silently
breaks when it is reached.
2011-01-28 15:45:19 +01:00
Diego Elio Pettenò c6610a216e Prefix all _demuxer, _muxer, _protocol from libavformat and libavdevice.
This also lists the objects from those two libraries as internal (by adding
the ff_ prefix) so that they can then be hidden via linker scripts.
2011-01-26 22:10:09 +00:00
Thomas Guillem 1aa58c6405 tcp: Check url_interrupt_cb if connect was interrupted by a signal
This makes it possible to abort a blocking connect call.

Patch by Thomas Guillem, thomas dot guillem at gmail

Originally committed as revision 26014 to svn://svn.ffmpeg.org/ffmpeg/trunk
2010-12-14 23:03:05 +00:00
Ronald S. Bultje 37e9cc4ec7 Remove two instances of AVERROR(ff_neterrno()), because ff_neterrno() itself
already does AVERROR().

Originally committed as revision 25671 to svn://svn.ffmpeg.org/ffmpeg/trunk
2010-11-04 13:53:16 +00:00
Martin Storsjö b416267622 tcp: Check both wfds and efds when waiting for the result from connect
On windows, a connection failure doesn't trigger wfds as it does on unix.

This fixes issue 2237, based on code by yeyingxian.

Originally committed as revision 25154 to svn://svn.ffmpeg.org/ffmpeg/trunk
2010-09-21 20:17:34 +00:00
Ronald S. Bultje 63638a3c4a Print error messages in case of connection failure or name resolution failure
in tcp.c.

Originally committed as revision 24796 to svn://svn.ffmpeg.org/ffmpeg/trunk
2010-08-14 20:34:51 +00:00
Måns Rullgård f3bfe388b5 Make ff_url_split() public
ff_url_split() is retained as an alias, as it was used by ffserver,
to avoid breaking ABI compatibility with it.

Originally committed as revision 23822 to svn://svn.ffmpeg.org/ffmpeg/trunk
2010-06-27 14:16:46 +00:00
Martin Storsjö 27241cbffe Declare the url_write buffer parameter as const
Originally committed as revision 23401 to svn://svn.ffmpeg.org/ffmpeg/trunk
2010-06-01 07:46:23 +00:00
Martin Storsjö cae9a15c98 Don't report EINTR from select as an error, retry select instead
Originally committed as revision 22694 to svn://svn.ffmpeg.org/ffmpeg/trunk
2010-03-26 16:04:38 +00:00
Aurelien Jacobs e4a9e3cc7c move ff_url_split() and ff_url_join() declarations to internal.h
those functions are not part of the public API

Originally committed as revision 22534 to svn://svn.ffmpeg.org/ffmpeg/trunk
2010-03-14 23:59:48 +00:00
Martin Storsjö c5c6e67c28 Rename url_split to ff_url_split
Since this function isn't in the public API, it should have an ff_ prefix.

Originally committed as revision 22321 to svn://svn.ffmpeg.org/ffmpeg/trunk
2010-03-08 09:03:25 +00:00
Martin Storsjö 814c56413d Don't explicitly initialize networking in the tcp and udp protocols
Networking is always initialized when opening protocols.

Originally committed as revision 22227 to svn://svn.ffmpeg.org/ffmpeg/trunk
2010-03-05 22:38:48 +00:00
Ronald S. Bultje 88248b76af Fix BSD compile (PF_UNSPEC is not a standard define, AF_UNSPEC is).
Originally committed as revision 21490 to svn://svn.ffmpeg.org/ffmpeg/trunk
2010-01-27 22:31:13 +00:00
Martin Storsjö fdcdd5396e Use getaddrinfo() instead of resolve_host(). Patch by Martin Storsjö
<$firstname()$firstname,st>.

Originally committed as revision 21147 to svn://svn.ffmpeg.org/ffmpeg/trunk
2010-01-11 17:32:40 +00:00
Martin Storsjö 73c1326809 Use ff_neterrno instead of errno in tcp.c.
If ff_neterrno() is checked instead of errno, that's probably what should be
used in the return value.
As a sideeffect, this gives better compatibility with Windows (CE), where
network errors aren't visible in errno.)
patch by Martin Storsjö, martin martin st

Originally committed as revision 19433 to svn://svn.ffmpeg.org/ffmpeg/trunk
2009-07-15 05:52:49 +00:00