Ejemplo n.º 1
0
/* This function behaves exactly like read(). The only difference is
 * that it accepts the gnutls_session_t and the content_type_t of data to
 * receive (if called by the user the Content is Userdata only)
 * It is intended to receive data, under the current session.
 *
 * The gnutls_handshake_description_t was introduced to support SSL V2.0 client hellos.
 */
ssize_t
_gnutls_recv_int (gnutls_session_t session, content_type_t type,
                  gnutls_handshake_description_t htype,
                  uint8_t * data, size_t data_size, void* seq,
                  unsigned int ms)
{
  int ret;

  if ((type != GNUTLS_ALERT && type != GNUTLS_HEARTBEAT) && (data_size == 0 || data == NULL))
    return gnutls_assert_val(GNUTLS_E_INVALID_REQUEST);

  if (session->internals.read_eof != 0)
    {
      /* if we have already read an EOF
       */
      return 0;
    }
  else if (session_is_valid (session) != 0
           || session->internals.may_not_read != 0)
    {
      gnutls_assert ();
      return GNUTLS_E_INVALID_SESSION;
    }
    
  switch(session->internals.recv_state)
    {
      case RECV_STATE_DTLS_RETRANSMIT:
        ret = _dtls_retransmit(session);
        if (ret < 0)
          return gnutls_assert_val(ret);
        
        session->internals.recv_state = RECV_STATE_0;
      case RECV_STATE_0:

        _dtls_async_timer_check(session);
        /* If we have enough data in the cache do not bother receiving
         * a new packet. (in order to flush the cache)
         */ 
        ret = check_buffers (session, type, data, data_size, seq);
        if (ret != 0)
          return ret;

        ret = _gnutls_recv_in_buffers(session, type, htype, ms);
        if (ret < 0 && ret != GNUTLS_E_SESSION_EOF)
          return gnutls_assert_val(ret);

        return check_buffers (session, type, data, data_size, seq);
      default:
        return gnutls_assert_val(GNUTLS_E_INTERNAL_ERROR);
    }
}
Ejemplo n.º 2
0
/* This function behaves exactly like read(). The only difference is
 * that it accepts the gnutls_session_t and the content_type_t of data to
 * receive (if called by the user the Content is Userdata only)
 * It is intended to receive data, under the current session.
 *
 * The gnutls_handshake_description_t was introduced to support SSL V2.0 client hellos.
 */
ssize_t
_gnutls_recv_int (gnutls_session_t session, content_type_t type,
                  gnutls_handshake_description_t htype,
                  uint8_t * data, size_t data_size, void* seq)
{
  int ret;

  if (type != GNUTLS_ALERT && (data_size == 0 || data == NULL))
    {
      return GNUTLS_E_INVALID_REQUEST;
    }

  if (session->internals.read_eof != 0)
    {
      /* if we have already read an EOF
       */
      return 0;
    }
  else if (session_is_valid (session) != 0
           || session->internals.may_not_read != 0)
    {
      gnutls_assert ();
      return GNUTLS_E_INVALID_SESSION;
    }

  _dtls_async_timer_check(session);
  
  /* If we have enough data in the cache do not bother receiving
   * a new packet. (in order to flush the cache)
   */
  ret = check_buffers (session, type, data, data_size, seq);
  if (ret != 0)
    return ret;

  ret = _gnutls_recv_in_buffers(session, type, htype);
  if (ret < 0 && ret != GNUTLS_E_SESSION_EOF)
    return gnutls_assert_val(ret);

  return check_buffers (session, type, data, data_size, seq);
}