Adapt ssl_{client,server}2.c to datagram write

This commit is contained in:
Manuel Pégourié-Gonnard 2014-10-13 18:38:36 +02:00 committed by Paul Bakker
parent a6fcffe516
commit 2d87e419e0
2 changed files with 55 additions and 15 deletions

View file

@ -1211,17 +1211,37 @@ send_request:
if( len >= 1 ) buf[len - 1] = '\n'; if( len >= 1 ) buf[len - 1] = '\n';
} }
if( opt.transport == SSL_TRANSPORT_STREAM )
{
for( written = 0, frags = 0; written < len; written += ret, frags++ ) for( written = 0, frags = 0; written < len; written += ret, frags++ )
{ {
while( ( ret = ssl_write( &ssl, buf + written, len - written ) ) <= 0 ) while( ( ret = ssl_write( &ssl, buf + written, len - written ) )
<= 0 )
{ {
if( ret != POLARSSL_ERR_NET_WANT_READ && ret != POLARSSL_ERR_NET_WANT_WRITE ) if( ret != POLARSSL_ERR_NET_WANT_READ &&
ret != POLARSSL_ERR_NET_WANT_WRITE )
{ {
printf( " failed\n ! ssl_write returned -0x%x\n\n", -ret ); printf( " failed\n ! ssl_write returned -0x%x\n\n", -ret );
goto exit; goto exit;
} }
} }
} }
}
else /* Not stream, so datagram */
{
do ret = ssl_write( &ssl, buf, len );
while( ret == POLARSSL_ERR_NET_WANT_READ ||
ret == POLARSSL_ERR_NET_WANT_WRITE );
if( ret < 0 )
{
printf( " failed\n ! ssl_write returned %d\n\n", ret );
goto exit;
}
frags = 1;
written = ret;
}
buf[written] = '\0'; buf[written] = '\0';
printf( " %d bytes written in %d fragments\n\n%s\n", written, frags, (char *) buf ); printf( " %d bytes written in %d fragments\n\n%s\n", written, frags, (char *) buf );

View file

@ -1915,9 +1915,12 @@ data_exchange:
len = sprintf( (char *) buf, HTTP_RESPONSE, len = sprintf( (char *) buf, HTTP_RESPONSE,
ssl_get_ciphersuite( &ssl ) ); ssl_get_ciphersuite( &ssl ) );
if( opt.transport == SSL_TRANSPORT_STREAM )
{
for( written = 0, frags = 0; written < len; written += ret, frags++ ) for( written = 0, frags = 0; written < len; written += ret, frags++ )
{ {
while( ( ret = ssl_write( &ssl, buf + written, len - written ) ) <= 0 ) while( ( ret = ssl_write( &ssl, buf + written, len - written ) )
<= 0 )
{ {
if( ret == POLARSSL_ERR_NET_CONN_RESET ) if( ret == POLARSSL_ERR_NET_CONN_RESET )
{ {
@ -1925,13 +1928,30 @@ data_exchange:
goto reset; goto reset;
} }
if( ret != POLARSSL_ERR_NET_WANT_READ && ret != POLARSSL_ERR_NET_WANT_WRITE ) if( ret != POLARSSL_ERR_NET_WANT_READ &&
ret != POLARSSL_ERR_NET_WANT_WRITE )
{ {
printf( " failed\n ! ssl_write returned %d\n\n", ret ); printf( " failed\n ! ssl_write returned %d\n\n", ret );
goto reset; goto reset;
} }
} }
} }
}
else /* Not stream, so datagram */
{
do ret = ssl_write( &ssl, buf, len );
while( ret == POLARSSL_ERR_NET_WANT_READ ||
ret == POLARSSL_ERR_NET_WANT_WRITE );
if( ret < 0 )
{
printf( " failed\n ! ssl_write returned %d\n\n", ret );
goto reset;
}
frags = 1;
written = ret;
}
buf[written] = '\0'; buf[written] = '\0';
printf( " %d bytes written in %d fragments\n\n%s\n", written, frags, (char *) buf ); printf( " %d bytes written in %d fragments\n\n%s\n", written, frags, (char *) buf );