Start adapting ssl_client2 to datagram I/O

This commit is contained in:
Manuel Pégourié-Gonnard 2014-07-11 14:14:15 +02:00 committed by Paul Bakker
parent 67427c07b2
commit ae5050c212

View File

@ -1177,6 +1177,11 @@ send_request:
printf( " < Read from server:" );
fflush( stdout );
/*
* TLS and DTLS need different reading styles (stream vs datagram)
*/
if( opt.transport == SSL_TRANSPORT_STREAM )
{
do
{
len = sizeof( buf ) - 1;
@ -1221,6 +1226,42 @@ send_request:
}
}
while( 1 );
}
else /* Not stream, so datagram */
{
len = sizeof( buf ) - 1;
memset( buf, 0, sizeof( buf ) );
do ret = ssl_read( &ssl, buf, len );
while( ret == POLARSSL_ERR_NET_WANT_READ ||
ret == POLARSSL_ERR_NET_WANT_WRITE );
if( ret <= 0 )
{
switch( ret )
{
case POLARSSL_ERR_SSL_PEER_CLOSE_NOTIFY:
printf( " connection was closed gracefully\n" );
ret = 0;
goto close_notify;
case 0:
case POLARSSL_ERR_NET_CONN_RESET:
printf( " connection was reset by peer\n" );
ret = 0;
goto reconnect;
default:
printf( " ssl_read returned -0x%x\n", -ret );
goto exit;
}
}
len = ret;
buf[len] = '\0';
printf( " %d bytes read\n\n%s", len, (char *) buf );
ret = 0;
}
/*
* 7b. Continue doing data exchanges?