Changeset 1388d30 for lib


Ignore:
Timestamp:
2012-11-11T17:57:20Z (12 years ago)
Author:
Wilmer van der Gaast <wilmer@…>
Branches:
master
Children:
2fb1262
Parents:
62f6b45
Message:

Mostly finished HTTP streaming support: Shrink the buffer and add a
http_close().

Location:
lib
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • lib/http_client.c

    r62f6b45 r1388d30  
    568568void http_flush_bytes( struct http_request *req, size_t len )
    569569{
    570         if( len > 0 && len <= req->body_size )
    571         {
    572                 req->reply_body += len;
    573                 req->body_size -= len;
    574         }
     570        if( len <= 0 || len > req->body_size || !( req->flags & HTTPC_STREAMING ) )
     571                return;
     572       
     573        req->reply_body += len;
     574        req->body_size -= len;
     575       
     576        if( req->reply_body - req->sbuf >= 512 )
     577        {
     578                printf( "Wasting %ld bytes, cleaning up stream buffer\n", req->reply_body - req->sbuf );
     579                char *new = g_memdup( req->reply_body, req->body_size + 1 );
     580                g_free( req->sbuf );
     581                req->reply_body = req->sbuf = new;
     582                req->sblen = req->body_size;
     583        }
     584}
     585
     586void http_close( struct http_request *req )
     587{
     588        if( !req )
     589                return;
     590       
     591        if( req->ssl )
     592                ssl_disconnect( req->ssl );
     593        else
     594                closesocket( req->fd );
     595       
     596        http_free( req );
    575597}
    576598
  • lib/http_client.h

    r62f6b45 r1388d30  
    8989/* For streaming connections only; flushes len bytes at the start of the buffer. */
    9090void http_flush_bytes( struct http_request *req, size_t len );
     91void http_close( struct http_request *req );
Note: See TracChangeset for help on using the changeset viewer.