Explorar el Código

Fix network callbacks

Ensure no side effect persists when errors have been triggered.
feature/data-structs
TheoryOfNekomata hace 2 años
padre
commit
b545368deb
Se han modificado 3 ficheros con 60 adiciones y 49 borrados
  1. +19
    -26
      src/packages/game/IZ_app.c
  2. +28
    -5
      src/packages/game/output/output.test.c
  3. +13
    -18
      src/packages/server/IZ_app.c

+ 19
- 26
src/packages/game/IZ_app.c Ver fichero

@@ -218,19 +218,22 @@ void IZ_WSClientAttemptConnect(struct lws_sorted_usec_list *sul) {
}

IZ_ProcedureResult IZ_WSClientProtocolInitialize(struct lws* wsi, void* in) {
IZ_WSClientVHostData* vhd_instance = (IZ_WSClientVHostData*) lws_protocol_vh_priv_get(
lws_get_vhost(wsi),
lws_get_protocol(wsi)
);
const struct lws_protocols* protocols = lws_get_protocol(wsi);
struct lws_vhost* vhost = lws_get_vhost(wsi);
IZ_WSClientVHostData* vhd_instance = (IZ_WSClientVHostData*) lws_protocol_vh_priv_get(vhost,protocols);
IZ_WSClientVHostData** vhd = &vhd_instance;
*vhd = lws_protocol_vh_priv_zalloc(
lws_get_vhost(wsi),
lws_get_protocol(wsi),
sizeof(IZ_WSClientVHostData)
*vhd = lws_protocol_vh_priv_zalloc(vhost, protocols, sizeof(IZ_WSClientVHostData));
(*vhd)->ring = lws_ring_create(
sizeof(IZ_WebsocketMessage),
RING_COUNT,
IZ_WebsocketDestroyMessage
);
if (!(*vhd)->ring) {
return -1;
}
(*vhd)->context = lws_get_context(wsi);
(*vhd)->protocol = lws_get_protocol(wsi);
(*vhd)->vhost = lws_get_vhost(wsi);
(*vhd)->protocol = protocols;
(*vhd)->vhost = vhost;
(*vhd)->port = (u16*) lws_pvo_search(
(const struct lws_protocol_vhost_options *)in,
"port"
@@ -247,14 +250,6 @@ IZ_ProcedureResult IZ_WSClientProtocolInitialize(struct lws* wsi, void* in) {
(const struct lws_protocol_vhost_options *)in,
"app"
)->value;
(*vhd)->ring = lws_ring_create(
sizeof(IZ_WebsocketMessage),
RING_COUNT,
IZ_WebsocketDestroyMessage
);
if (!(*vhd)->ring) {
return -1;
}
IZ_WSClientAttemptConnect(&(*vhd)->sul);
return 0;
}
@@ -273,12 +268,11 @@ void IZ_WSClientProtocolTeardown(struct lws* wsi) {
}

void IZ_WSClientConnectionError(struct lws* wsi, void* in) {
lwsl_err("CLIENT_CONNECTION_ERROR: %s\n", in ? (char *)in : "(null)");
IZ_WSClientVHostData* vhd = (IZ_WSClientVHostData*) lws_protocol_vh_priv_get(
lws_get_vhost(wsi),
lws_get_protocol(wsi)
);

lwsl_err("CLIENT_CONNECTION_ERROR: %s\n", in ? (char *)in : "(null)");
IZ_App* app = (IZ_App*) vhd->app;
app->net_state.ws.connection = NULL;
vhd->client_wsi = NULL;
@@ -292,17 +286,17 @@ void IZ_WSClientConnectionError(struct lws* wsi, void* in) {
}

IZ_ProcedureResult IZ_WSClientOnOpen(struct lws* wsi, IZ_WSClientSessionData* pss) {
pss->ring = lws_ring_create(sizeof(IZ_WebsocketMessage), RING_COUNT,IZ_WebsocketDestroyMessage);
if (!pss->ring) {
return -1;
}

IZ_WSClientVHostData* vhd = (IZ_WSClientVHostData*) lws_protocol_vh_priv_get(
lws_get_vhost(wsi),
lws_get_protocol(wsi)
);

IZ_App* app = (IZ_App*) vhd->app;
app->net_state.ws.connection = wsi;
pss->ring = lws_ring_create(sizeof(IZ_WebsocketMessage), RING_COUNT,IZ_WebsocketDestroyMessage);
if (!pss->ring) {
return -1;
}
pss->tail = 0;
return 0;
}
@@ -312,7 +306,6 @@ void IZ_WSClientOnClose(struct lws* wsi) {
lws_get_vhost(wsi),
lws_get_protocol(wsi)
);

IZ_App* app = (IZ_App*) vhd->app;
app->net_state.ws.connection = NULL;
vhd->client_wsi = NULL;


+ 28
- 5
src/packages/game/output/output.test.c Ver fichero

@@ -3,25 +3,48 @@
#include "../../../__mocks__/SDL_render.mock.h"
#include "IZ_video.h"

const char* IZ_ConfigGetCommandlineOption(u8 argc, const char* argv[], const char* val) {
size_t n = strlen(val);
int c = argc;

while (--c > 0) {

if (!strncmp(argv[c], val, n)) {
if (!*(argv[c] + n) && c < argc - 1) {
/* coverity treats unchecked argv as "tainted" */
if (!argv[c + 1] || strlen(argv[c + 1]) > 1024)
return NULL;
return argv[c + 1];
}

if (argv[c][n] == '=')
return &argv[c][n + 1];
return argv[c] + n;
}
}

return NULL;
}

spec("output") {
describe("video") {
describe("SaveConfig") {
static IZ_VideoConfig config;
static IZ_VideoState state;

after_each() {
mock_reset(ini_putl);
}

before_each() {
config.width = 1337;
config.height = 420;
config.max_fps = 69;
state.config.width = 1337;
state.config.height = 420;
state.config.max_fps = 69;
}

it("calls save method") {
mock_set_expected_calls(ini_putl, 3);

IZ_VideoSaveConfig(&config, "config-game.ini");
IZ_VideoSaveConfig(&state, "config-game.ini");

check(
mock_get_expected_calls(ini_putl) == mock_get_actual_calls(ini_putl),


+ 13
- 18
src/packages/server/IZ_app.c Ver fichero

@@ -162,19 +162,22 @@ void IZ_WSServerCullLaggingClients(IZ_WSServerVHostData *vhd) {
/* destroys the message when everyone has had a copy of it */

IZ_ProcedureResult IZ_WSServerProtocolInitialize(struct lws* wsi, void* in) {
IZ_WSServerVHostData* vhd_instance = (IZ_WSServerVHostData*) lws_protocol_vh_priv_get(
lws_get_vhost(wsi),
lws_get_protocol(wsi)
);
const struct lws_protocols* protocols = lws_get_protocol(wsi);
struct lws_vhost* vhost = lws_get_vhost(wsi);
IZ_WSServerVHostData* vhd_instance = (IZ_WSServerVHostData*) lws_protocol_vh_priv_get(vhost, protocols);
IZ_WSServerVHostData** vhd = &vhd_instance;
*vhd = lws_protocol_vh_priv_zalloc(
lws_get_vhost(wsi),
lws_get_protocol(wsi),
sizeof(IZ_WSServerVHostData)
*vhd = lws_protocol_vh_priv_zalloc(vhost, protocols, sizeof(IZ_WSServerVHostData));
(*vhd)->ring = lws_ring_create(
sizeof(IZ_WebsocketMessage),
RING_COUNT,
IZ_WebsocketDestroyMessage
);
if (!(*vhd)->ring) {
return -1;
}
(*vhd)->context = lws_get_context(wsi);
(*vhd)->protocol = lws_get_protocol(wsi);
(*vhd)->vhost = lws_get_vhost(wsi);
(*vhd)->protocol = protocols;
(*vhd)->vhost = vhost;
(*vhd)->port = (u16*) lws_pvo_search(
(const struct lws_protocol_vhost_options *)in,
"port"
@@ -183,14 +186,6 @@ IZ_ProcedureResult IZ_WSServerProtocolInitialize(struct lws* wsi, void* in) {
(const struct lws_protocol_vhost_options *)in,
"app"
)->value;
(*vhd)->ring = lws_ring_create(
sizeof(IZ_WebsocketMessage),
RING_COUNT,
IZ_WebsocketDestroyMessage
);
if (!(*vhd)->ring) {
return -1;
}
return 0;
}



Cargando…
Cancelar
Guardar