New onData, onWritable overloads that mostly replace onAborted [draft]

Abierto
#1,956 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
5/5
Tiempo estimado
Más de una semana
Aptitud para principiantes
35/100
Tipo de issue
Nueva funcionalidad
Claridad
Bastante claro
Estado de actividad
Activo
Stack tecnológico
cpp

Línea de trabajo

Start by reading the existing onData, onWritable, and onAborted callback implementations and their tests; the issue does not name specific files or test paths. Check how the proposed overloads interact with existing callbacks and language bindings, then define completion by adding the overload behavior and coverage for aborts, empty request bodies, and backward compatibility.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

  • onData(chunk, isFin) simplified as onData(2) becomes onData(std::optional<HttpSocket *> res, chunk, maxRemainingBodyLength) simplified as onData(3)
  • onData(chunk, isFin) and onDataV2 are implemented as wrappers for the "base" onData(3).

When onAborted would normally be called, onData(nullopt is called as well. The wrapped old onData(2) implementation filters out those calls to remain backwards compatible.

If onData(3) is called and there is no onAborted callback, a noop callback is set, so that the "you must attach onAborted handler bla bla bla" error is silenced. If onAborted is called after, it just overwrites that either way.

This means you can use (only) onData(3) instead of onData(2) + onAborted when you receive data. And you can also use onData(3) instead of onAborted, but there is a small overhead to this: namely that onData(3) is always emitted with a ("", 0) chunk even if there is no data (for instance a GET request). So for GET requests that need to wait for DB or timers, you would still want to use onAborted (only). At least if 1 extra call is too heavy (such as for JavaScript where a call is heavy weight).

In C++, you should be able to entirely replace onAborted with only onData(3) in all cases, since a function call is negligible, esp. if you the compiler inlined everything.

onWritable(1) which is the old onWritable(offset), gets a new overload: onWritable(std::optional<HttpSocket *> res, offset) which is onWritable(2), and behaves the same as onData(3), which means for streaming out, you only need to attach to onWritable(2). Just like onData(3), the onWritable(2) gets called with nullopt when onAborted would be called.

This also means that if you attach to all 3 callbacks, and abortion triggers, you get 3 events. But any sane set-up should use either only onData(3), only onWritable(2) or only onAborted.

Lenguaje dominante
C++
Estrellas
19k
Forks
1.9k
Merge medio
3 h 59 min
PR fusionados (30 d)
1

Preparar el entorno

Este proyecto no incluye contenedor de desarrollo, Dockerfile ni guía de contribución, así que la configuración corre por tu cuenta: empieza por su README y consulta nuestra guía para la primera contribución para los pasos generales.

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de uNetworking/uWebSockets

Todos los issues de uNetworking/uWebSockets

Issues similares

Más issues de C++

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.