Adapt ssl_server2 to datagram-style read

This commit is contained in:
Manuel Pégourié-Gonnard 2014-10-06 18:11:43 +02:00 committed by Paul Bakker
parent 46fb942046
commit cce220d6aa

View file

@ -1748,6 +1748,11 @@ data_exchange:
printf( " < Read from client:" );
fflush( stdout );
/*
* TLS and DTLS need different reading styles (stream vs datagram)
*/
if( opt.transport == SSL_TRANSPORT_STREAM )
{
do
{
int terminated = 0;
@ -1839,6 +1844,42 @@ data_exchange:
}
}
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 = POLARSSL_ERR_NET_CONN_RESET;
goto reset;
default:
printf( " ssl_read returned -0x%x\n", -ret );
goto reset;
}
}
len = ret;
buf[len] = '\0';
printf( " %d bytes read\n\n%s", len, (char *) buf );
ret = 0;
}
/*
* 7a. Request renegotiation while client is waiting for input from us.