On Sun, 20 May 2012, Samuel Pitoiset wrote:
---
libavformat/avio.c | 7 +++++++
libavformat/os_support.h | 6 ++++++
libavformat/tcp.c | 19 +++++++++++++++++++
libavformat/url.h | 9 +++++++++
4 files changed, 41 insertions(+)
I think I'd rather have this patch split in two - one that adds the
generic new function to URLProtocol/avio.c, another one that adds support
for it in tcp.
When adding it in tcp, you could also mention in the commit message that
this particular function isn't needed at the moment, but is added for
consistency to explain how the function is supposed to be used.
Also, if you change the code according to another comment I have below,
the commit messages can be something like this:
avio: Add a function for signalling end of reading/writing
and
tcp: Allow signalling end of reading/writing
That is, the tcp patch isn't a behaviour change (if you apply my comment
below), only an extra feature.
diff --git a/libavformat/avio.c b/libavformat/avio.c
index ba25abe..beb0b03 100644
--- a/libavformat/avio.c
+++ b/libavformat/avio.c
@@ -345,6 +345,13 @@ int ffurl_get_file_handle(URLContext *h)
return h->prot->url_get_file_handle(h);
}
+int ffurl_shutdown(URLContext *h, int flags)
+{
+ if (!h->prot->url_shutdown)
+ return -1;
+ return h->prot->url_shutdown(h, flags);
+}
+
int ff_check_interrupt(AVIOInterruptCB *cb)
{
int ret;
diff --git a/libavformat/os_support.h b/libavformat/os_support.h
index 20c6d73..1088c6c 100644
--- a/libavformat/os_support.h
+++ b/libavformat/os_support.h
@@ -45,6 +45,12 @@ static inline int is_dos_path(const char *path)
return 0;
}
+#if defined(_WIN32)
+#define SHUT_RD SD_RECEIVE
+#define SHUT_WR SD_SEND
+#define SHUT_RDWR SD_BOTH
+#endif
+
#if defined(_WIN32) && !defined(__MINGW32CE__)
int ff_win32_open(const char *filename, int oflag, int pmode);
#define open ff_win32_open
diff --git a/libavformat/tcp.c b/libavformat/tcp.c
index 0ed11f3..d5f7962 100644
--- a/libavformat/tcp.c
+++ b/libavformat/tcp.c
@@ -182,9 +182,27 @@ static int tcp_write(URLContext *h, const uint8_t *buf,
int size)
return ret < 0 ? ff_neterrno() : ret;
}
+static int tcp_shutdown(URLContext *h, int flags)
+{
+ TCPContext *s = h->priv_data;
+ int how;
+
+ if (flags & AVIO_FLAG_WRITE && flags & AVIO_FLAG_READ) {
Another way of checking if two flags are set is
if (flags & (flag1 | flag2) == flag1 | flag2)
although your version might actually be shorter in this case.
+ how = SHUT_RDWR;
+ } else if (flags & AVIO_FLAG_WRITE) {
+ how = SHUT_WR;
+ } else {
+ how = SHUT_RD;
+ }
+
+ return shutdown(s->fd, how);
+}
+
static int tcp_close(URLContext *h)
{
TCPContext *s = h->priv_data;
+
+ tcp_shutdown(h, h->flags);
This isn't necessary - there's no need to shutdown the socket just before
closing it.
closesocket(s->fd);
return 0;
}
@@ -202,6 +220,7 @@ URLProtocol ff_tcp_protocol = {
.url_write = tcp_write,
.url_close = tcp_close,
.url_get_file_handle = tcp_get_file_handle,
+ .url_shutdown = tcp_shutdown,
.priv_data_size = sizeof(TCPContext),
.flags = URL_PROTOCOL_FLAG_NETWORK,
};
diff --git a/libavformat/url.h b/libavformat/url.h
index bf8b6ed..c275727 100644
--- a/libavformat/url.h
+++ b/libavformat/url.h
@@ -81,6 +81,7 @@ typedef struct URLProtocol {
int64_t (*url_read_seek)(URLContext *h, int stream_index,
int64_t timestamp, int flags);
int (*url_get_file_handle)(URLContext *h);
+ int (*url_shutdown)(URLContext *h, int flags);
int priv_data_size;
const AVClass *priv_data_class;
int flags;
@@ -201,6 +202,14 @@ int64_t ffurl_size(URLContext *h);
int ffurl_get_file_handle(URLContext *h);
/**
+ * Shutdown the resource accessed by the URLContext h.
+ *
I'd rather write this as
"Signal the URLContext that we are done reading or writing the stream."
+ * @return a negative value if an error condition occurred, 0
+ * otherwise
+ */
Add @params for both params here, and explain what the flags do.
+int ffurl_shutdown(URLContext *h, int flags);
+
+/**
* Register the URLProtocol protocol.
*
* @param size the size of the URLProtocol struct referenced
--
1.7.10.2
_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel
// Martin
_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel