From 32d545e0a4686e919319bf472725ea0162b72720 Mon Sep 17 00:00:00 2001 From: Samuel Pitoiset Date: Mon, 21 May 2012 11:24:54 +0200 Subject: avio: Add a function for signalling end of reading/writing MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Martin Storsjö --- libavformat/avio.c | 7 +++++++ libavformat/url.h | 13 +++++++++++++ 2 files changed, 20 insertions(+) (limited to 'libavformat') diff --git a/libavformat/avio.c b/libavformat/avio.c index ba25abea38..371500e8a6 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 AVERROR(EINVAL); + return h->prot->url_shutdown(h, flags); +} + int ff_check_interrupt(AVIOInterruptCB *cb) { int ret; diff --git a/libavformat/url.h b/libavformat/url.h index bf8b6ed6e7..0f0de7881c 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; @@ -200,6 +201,18 @@ int64_t ffurl_size(URLContext *h); */ int ffurl_get_file_handle(URLContext *h); +/** + * Signal the URLContext that we are done reading or writing the stream. + * + * @param h pointer to the resource + * @param flags flags which control how the resource indicated by url + * is to be shutdown + * + * @return a negative value if an error condition occurred, 0 + * otherwise + */ +int ffurl_shutdown(URLContext *h, int flags); + /** * Register the URLProtocol protocol. * -- cgit v1.2.3 From 4a9ca9355607053fdbcb8adcb614b08305eca88f Mon Sep 17 00:00:00 2001 From: Samuel Pitoiset Date: Mon, 21 May 2012 11:24:55 +0200 Subject: tcp: Allow signalling end of reading/writing MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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ö --- libavformat/os_support.h | 6 ++++++ libavformat/tcp.c | 17 +++++++++++++++++ 2 files changed, 23 insertions(+) (limited to 'libavformat') diff --git a/libavformat/os_support.h b/libavformat/os_support.h index 20c6d73738..1088c6c31c 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 0ed11f321f..37f74f6e2f 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, }; -- cgit v1.2.3 From ba354a8cc091039662e50f1a5a194f5b589056f6 Mon Sep 17 00:00:00 2001 From: Samuel Pitoiset Date: Mon, 21 May 2012 11:26:40 +0200 Subject: http: Add http_shutdown() for ending writing of posts MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Martin Storsjö --- libavformat/http.c | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) (limited to 'libavformat') diff --git a/libavformat/http.c b/libavformat/http.c index ea7c693b34..124f533a1f 100644 --- a/libavformat/http.c +++ b/libavformat/http.c @@ -51,6 +51,7 @@ typedef struct { char *headers; int willclose; /**< Set if the server correctly handles Connection: close and will close the connection after feeding us the content. */ int chunked_post; + int end_chunked_post; /**< A flag which indicates if the end of chunked encoding has been sent. */ } HTTPContext; #define OFFSET(x) offsetof(HTTPContext, x) @@ -415,6 +416,7 @@ static int http_connect(URLContext *h, const char *path, const char *local_path, s->off = 0; s->filesize = -1; s->willclose = 0; + s->end_chunked_post = 0; if (post) { /* Pretend that it did work. We didn't read any header yet, since * we've still to send the POST data, but the code calling this @@ -512,16 +514,30 @@ static int http_write(URLContext *h, const uint8_t *buf, int size) return size; } -static int http_close(URLContext *h) +static int http_shutdown(URLContext *h, int flags) { int ret = 0; char footer[] = "0\r\n\r\n"; HTTPContext *s = h->priv_data; /* signal end of chunked encoding if used */ - if ((h->flags & AVIO_FLAG_WRITE) && s->chunked_post) { + if ((flags & AVIO_FLAG_WRITE) && s->chunked_post) { ret = ffurl_write(s->hd, footer, sizeof(footer) - 1); ret = ret > 0 ? 0 : ret; + s->end_chunked_post = 1; + } + + return ret; +} + +static int http_close(URLContext *h) +{ + int ret = 0; + HTTPContext *s = h->priv_data; + + if (!s->end_chunked_post) { + /* Close the write direction by sending the end of chunked encoding. */ + ret = http_shutdown(h, h->flags); } if (s->hd) @@ -581,6 +597,7 @@ URLProtocol ff_http_protocol = { .url_seek = http_seek, .url_close = http_close, .url_get_file_handle = http_get_file_handle, + .url_shutdown = http_shutdown, .priv_data_size = sizeof(HTTPContext), .priv_data_class = &http_context_class, .flags = URL_PROTOCOL_FLAG_NETWORK, -- cgit v1.2.3 From e5773d8bc372a88b28452efa5fc87711f673bd28 Mon Sep 17 00:00:00 2001 From: Samuel Pitoiset Date: Mon, 21 May 2012 11:27:10 +0200 Subject: http: Add support for reading http POST reply headers MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Martin Storsjö --- libavformat/http.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'libavformat') diff --git a/libavformat/http.c b/libavformat/http.c index 124f533a1f..f978dc17af 100644 --- a/libavformat/http.c +++ b/libavformat/http.c @@ -52,6 +52,7 @@ typedef struct { int willclose; /**< Set if the server correctly handles Connection: close and will close the connection after feeding us the content. */ int chunked_post; int end_chunked_post; /**< A flag which indicates if the end of chunked encoding has been sent. */ + int end_header; /**< A flag which indicates we have finished to read POST reply. */ } HTTPContext; #define OFFSET(x) offsetof(HTTPContext, x) @@ -249,8 +250,10 @@ static int process_line(URLContext *h, char *line, int line_count, char *tag, *p, *end; /* end of header */ - if (line[0] == '\0') + if (line[0] == '\0') { + s->end_header = 1; return 0; + } p = line; if (line_count == 0) { @@ -462,6 +465,17 @@ static int http_buf_read(URLContext *h, uint8_t *buf, int size) static int http_read(URLContext *h, uint8_t *buf, int size) { HTTPContext *s = h->priv_data; + int err, new_location; + + if (s->end_chunked_post) { + if (!s->end_header) { + err = http_read_header(h, &new_location); + if (err < 0) + return err; + } + + return http_buf_read(h, buf, size); + } if (s->chunksize >= 0) { if (!s->chunksize) { -- cgit v1.2.3 From 3f9d6e423978f5e905def374e9c2e9166e3ebb2c Mon Sep 17 00:00:00 2001 From: Dave Yeo Date: Wed, 23 May 2012 13:34:13 -0700 Subject: os_support: Define SHUT_RD, SHUT_WR and SHUT_RDWR on OS/2 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Martin Storsjö --- libavformat/os_support.h | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'libavformat') diff --git a/libavformat/os_support.h b/libavformat/os_support.h index 1088c6c31c..3db20a9aa8 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(__OS2__) +#define SHUT_RD 0 +#define SHUT_WR 1 +#define SHUT_RDWR 2 +#endif + #if defined(_WIN32) #define SHUT_RD SD_RECEIVE #define SHUT_WR SD_SEND -- cgit v1.2.3