Adapt ssl_{client,server}2.c to datagram write
This commit is contained in:
parent
a6fcffe516
commit
2d87e419e0
2 changed files with 55 additions and 15 deletions
|
@ -1211,17 +1211,37 @@ send_request:
|
||||||
if( len >= 1 ) buf[len - 1] = '\n';
|
if( len >= 1 ) buf[len - 1] = '\n';
|
||||||
}
|
}
|
||||||
|
|
||||||
for( written = 0, frags = 0; written < len; written += ret, frags++ )
|
if( opt.transport == SSL_TRANSPORT_STREAM )
|
||||||
{
|
{
|
||||||
while( ( ret = ssl_write( &ssl, buf + written, len - written ) ) <= 0 )
|
for( written = 0, frags = 0; written < len; written += ret, frags++ )
|
||||||
{
|
{
|
||||||
if( ret != POLARSSL_ERR_NET_WANT_READ && ret != POLARSSL_ERR_NET_WANT_WRITE )
|
while( ( ret = ssl_write( &ssl, buf + written, len - written ) )
|
||||||
|
<= 0 )
|
||||||
{
|
{
|
||||||
printf( " failed\n ! ssl_write returned -0x%x\n\n", -ret );
|
if( ret != POLARSSL_ERR_NET_WANT_READ &&
|
||||||
goto exit;
|
ret != POLARSSL_ERR_NET_WANT_WRITE )
|
||||||
|
{
|
||||||
|
printf( " failed\n ! ssl_write returned -0x%x\n\n", -ret );
|
||||||
|
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 );
|
||||||
|
|
|
@ -1915,23 +1915,43 @@ data_exchange:
|
||||||
len = sprintf( (char *) buf, HTTP_RESPONSE,
|
len = sprintf( (char *) buf, HTTP_RESPONSE,
|
||||||
ssl_get_ciphersuite( &ssl ) );
|
ssl_get_ciphersuite( &ssl ) );
|
||||||
|
|
||||||
for( written = 0, frags = 0; written < len; written += ret, frags++ )
|
if( opt.transport == SSL_TRANSPORT_STREAM )
|
||||||
{
|
{
|
||||||
while( ( ret = ssl_write( &ssl, buf + written, len - written ) ) <= 0 )
|
for( written = 0, frags = 0; written < len; written += ret, frags++ )
|
||||||
{
|
{
|
||||||
if( ret == POLARSSL_ERR_NET_CONN_RESET )
|
while( ( ret = ssl_write( &ssl, buf + written, len - written ) )
|
||||||
|
<= 0 )
|
||||||
{
|
{
|
||||||
printf( " failed\n ! peer closed the connection\n\n" );
|
if( ret == POLARSSL_ERR_NET_CONN_RESET )
|
||||||
goto reset;
|
{
|
||||||
}
|
printf( " failed\n ! peer closed the connection\n\n" );
|
||||||
|
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 );
|
{
|
||||||
goto reset;
|
printf( " failed\n ! ssl_write returned %d\n\n", ret );
|
||||||
|
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 );
|
||||||
|
|
Loading…
Reference in a new issue