diff options
-rw-r--r-- | lib/http_client.c | 28 | ||||
-rw-r--r-- | lib/http_client.h | 1 | ||||
-rw-r--r-- | protocols/twitter/twitter.c | 1 |
3 files changed, 27 insertions, 3 deletions
diff --git a/lib/http_client.c b/lib/http_client.c index acbf230c..5fc7731f 100644 --- a/lib/http_client.c +++ b/lib/http_client.c @@ -567,13 +567,35 @@ static gboolean http_handle_headers( struct http_request *req ) void http_flush_bytes( struct http_request *req, size_t len ) { - if( len > 0 && len <= req->body_size ) + if( len <= 0 || len > req->body_size || !( req->flags & HTTPC_STREAMING ) ) + return; + + req->reply_body += len; + req->body_size -= len; + + if( req->reply_body - req->sbuf >= 512 ) { - req->reply_body += len; - req->body_size -= len; + printf( "Wasting %ld bytes, cleaning up stream buffer\n", req->reply_body - req->sbuf ); + char *new = g_memdup( req->reply_body, req->body_size + 1 ); + g_free( req->sbuf ); + req->reply_body = req->sbuf = new; + req->sblen = req->body_size; } } +void http_close( struct http_request *req ) +{ + if( !req ) + return; + + if( req->ssl ) + ssl_disconnect( req->ssl ); + else + closesocket( req->fd ); + + http_free( req ); +} + static void http_free( struct http_request *req ) { g_free( req->request ); diff --git a/lib/http_client.h b/lib/http_client.h index fddc5158..38175b70 100644 --- a/lib/http_client.h +++ b/lib/http_client.h @@ -88,3 +88,4 @@ struct http_request *http_dorequest_url( char *url_string, http_input_function f /* For streaming connections only; flushes len bytes at the start of the buffer. */ void http_flush_bytes( struct http_request *req, size_t len ); +void http_close( struct http_request *req ); diff --git a/protocols/twitter/twitter.c b/protocols/twitter/twitter.c index ea440a15..f538f885 100644 --- a/protocols/twitter/twitter.c +++ b/protocols/twitter/twitter.c @@ -373,6 +373,7 @@ static void twitter_logout(struct im_connection *ic) imcb_chat_free(td->timeline_gc); if (td) { + http_close(td->stream); oauth_info_free(td->oauth_info); g_free(td->user); g_free(td->prefix); |