Changeset a81d679


Ignore:
Timestamp:
2010-03-21T15:56:59Z (15 years ago)
Author:
Wilmer van der Gaast <wilmer@…>
Branches:
master
Children:
767a148
Parents:
4ed9c8c
Message:

Fixed jabber_bs_peek() to deal with incomplete packets as well.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • protocols/jabber/s5bytestream.c

    r4ed9c8c ra81d679  
    4646
    4747        gint connect_timeout;
     48       
     49        char peek_buf[64];
     50        int peek_buf_len;
    4851};
    4952
     
    150153        int fd = bt->tf->fd;
    151154
    152         ASSERTSOCKOP( ret = recv( fd, buffer, buflen, MSG_PEEK ), "MSG_PEEK'ing" );
     155        if( buflen > sizeof( bt->peek_buf ) )
     156                return jabber_bs_abort( bt, "BUG: %d > sizeof(peek_buf)", buflen );
     157
     158        ASSERTSOCKOP( ret = recv( fd, bt->peek_buf + bt->peek_buf_len,
     159                buflen - bt->peek_buf_len, 0 ), "recv() on SOCKS5 connection" );
    153160
    154161        if( ret == 0 )
    155162                return jabber_bs_abort( bt, "Remote end closed connection" );
    156                
    157         if( ret < buflen )
    158                 return ret;
    159 
    160         ASSERTSOCKOP( ret = recv( fd, buffer, buflen, 0 ), "Dequeuing after MSG_PEEK" );
    161 
    162         if( ret != buflen )
    163                 return jabber_bs_abort( bt, "recv returned less than previous recv with MSG_PEEK" );
    164        
    165         return ret;
     163       
     164        bt->peek_buf_len += ret;
     165        memcpy( buffer, bt->peek_buf, bt->peek_buf_len );
     166       
     167        if( bt->peek_buf_len == buflen )
     168        {
     169                /* If we have everything the caller wanted, reset the peek buffer. */
     170                bt->peek_buf_len = 0;
     171                return buflen;
     172        }
     173        else
     174                return bt->peek_buf_len;
    166175}
    167176
     
    560569
    561570        bt->tf->watch_in = 0;
     571        /* MUST always return FALSE! */
    562572        return FALSE;
    563573}
     
    10121022                imcb_file_canceled( tf->ft, error );
    10131023
     1024        /* MUST always return FALSE! */
    10141025        return FALSE;
    10151026}
Note: See TracChangeset for help on using the changeset viewer.