net: Group events into struct
This commit is contained in:
parent
85d4af0266
commit
467f09e952
|
@ -68,9 +68,12 @@ static int on_connect(struct join_menu *const m)
|
|||
.common =
|
||||
{
|
||||
.domain = d,
|
||||
.on_connected = on_connected,
|
||||
.on_disconnected = on_disconnected,
|
||||
.arg = m
|
||||
.ev =
|
||||
{
|
||||
.connected = on_connected,
|
||||
.disconnected = on_disconnected,
|
||||
.arg = m
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -15,9 +15,13 @@ union net_connect
|
|||
struct net_connect_common
|
||||
{
|
||||
enum net_domain domain;
|
||||
void (*on_connected)(void *arg);
|
||||
void (*on_disconnected)(void *arg);
|
||||
void *arg;
|
||||
|
||||
struct net_connect_ev
|
||||
{
|
||||
void (*connected)(void *arg);
|
||||
void (*disconnected)(void *arg);
|
||||
void *arg;
|
||||
} ev;
|
||||
} common;
|
||||
|
||||
struct net_connect_ipv4
|
||||
|
|
|
@ -9,9 +9,7 @@ struct net_socket_domain
|
|||
{
|
||||
ENetHost *host;
|
||||
ENetPeer *peers;
|
||||
void (*on_connected)(void *arg);
|
||||
void (*on_disconnected)(void *arg);
|
||||
void *arg;
|
||||
struct net_connect_ev ev;
|
||||
};
|
||||
|
||||
enum
|
||||
|
@ -27,9 +25,7 @@ struct net_socket_domain *net_connect_ipv4(const union net_connect *const c)
|
|||
if (!s)
|
||||
goto failure;
|
||||
|
||||
s->on_connected = c->common.on_connected;
|
||||
s->on_disconnected = c->common.on_disconnected;
|
||||
s->arg = c->common.arg;
|
||||
s->ev = c->common.ev;
|
||||
s->host = enet_host_create(NULL, 1, MAX_CHANNELS, 0, 0);
|
||||
|
||||
if (!s->host)
|
||||
|
@ -96,14 +92,16 @@ int net_update_ipv4(struct net_socket_domain *const s)
|
|||
switch (ev.type)
|
||||
{
|
||||
case ENET_EVENT_TYPE_CONNECT:
|
||||
if (s->on_connected)
|
||||
s->on_connected(s->arg);
|
||||
if (s->ev.connected)
|
||||
s->ev.connected(s->ev.arg);
|
||||
|
||||
break;
|
||||
|
||||
case ENET_EVENT_TYPE_DISCONNECT:
|
||||
if (s->on_disconnected)
|
||||
s->on_disconnected(s->arg);
|
||||
if (s->ev.disconnected)
|
||||
s->ev.disconnected(s->ev.arg);
|
||||
|
||||
break;
|
||||
|
||||
case ENET_EVENT_TYPE_RECEIVE:
|
||||
break;
|
||||
|
|
Loading…
Reference in New Issue