[FFmpeg-cvslog] tcp: Allow signalling end of reading/writing

Samuel Pitoiset git at videolan.org
Wed May 23 22:01:00 CEST 2012


ffmpeg | branch: master | Samuel Pitoiset <samuel.pitoiset at gmail.com> | Mon May 21 11:24:55 2012 +0200| [4a9ca9355607053fdbcb8adcb614b08305eca88f] | committer: Martin Storsjö

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 at martin.st>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=4a9ca9355607053fdbcb8adcb614b08305eca88f
---

 libavformat/os_support.h |    6 ++++++
 libavformat/tcp.c        |   17 +++++++++++++++++
 2 files changed, 23 insertions(+)

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..37f74f6 100644
--- a/libavformat/tcp.c
+++ b/libavformat/tcp.c
@@ -182,6 +182,22 @@ 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) {
+        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;
@@ -202,6 +218,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,
 };



More information about the ffmpeg-cvslog mailing list