rpc support
parent
d5496d4ddb
commit
4969ab42d9
|
@ -2111,6 +2111,8 @@ NETWORK_EVENT_CONNECT,
|
||||||
NETWORK_EVENT_DISCONNECT,
|
NETWORK_EVENT_DISCONNECT,
|
||||||
NETWORK_EVENT_RECEIVE,
|
NETWORK_EVENT_RECEIVE,
|
||||||
NETWORK_EVENT_DISCONNECT_TIMEOUT,
|
NETWORK_EVENT_DISCONNECT_TIMEOUT,
|
||||||
|
NETWORK_EVENT_RPC = 10,
|
||||||
|
NETWORK_EVENT_RPC_RESP,
|
||||||
};
|
};
|
||||||
int network_event(const char *msg, int *errcode, char **errstr);
|
int network_event(const char *msg, int *errcode, char **errstr);
|
||||||
enum { NETWORK_RANK = 0 };
|
enum { NETWORK_RANK = 0 };
|
||||||
|
|
|
@ -15934,6 +15934,10 @@ enum {
|
||||||
NETWORK_EVENT_DISCONNECT,
|
NETWORK_EVENT_DISCONNECT,
|
||||||
NETWORK_EVENT_RECEIVE,
|
NETWORK_EVENT_RECEIVE,
|
||||||
NETWORK_EVENT_DISCONNECT_TIMEOUT,
|
NETWORK_EVENT_DISCONNECT_TIMEOUT,
|
||||||
|
|
||||||
|
/* offset from internal networking events */
|
||||||
|
NETWORK_EVENT_RPC = 10,
|
||||||
|
NETWORK_EVENT_RPC_RESP,
|
||||||
};
|
};
|
||||||
|
|
||||||
/* errcode and errstr are optional arguments, pass NULL to ignore them,
|
/* errcode and errstr are optional arguments, pass NULL to ignore them,
|
||||||
|
@ -338942,7 +338946,7 @@ void* network_buffer(void *ptr, unsigned sz, uint64_t flags, int64_t rank) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static
|
static
|
||||||
int enet_event_to_netsync(ENetEventType ev) {
|
int enet_event_to_netsync(int ev) {
|
||||||
switch (ev) {
|
switch (ev) {
|
||||||
case ENET_EVENT_TYPE_CONNECT: return NETWORK_EVENT_CONNECT;
|
case ENET_EVENT_TYPE_CONNECT: return NETWORK_EVENT_CONNECT;
|
||||||
case ENET_EVENT_TYPE_DISCONNECT: return NETWORK_EVENT_DISCONNECT;
|
case ENET_EVENT_TYPE_DISCONNECT: return NETWORK_EVENT_DISCONNECT;
|
||||||
|
@ -338950,7 +338954,8 @@ int enet_event_to_netsync(ENetEventType ev) {
|
||||||
case ENET_EVENT_TYPE_DISCONNECT_TIMEOUT: return NETWORK_EVENT_DISCONNECT_TIMEOUT;
|
case ENET_EVENT_TYPE_DISCONNECT_TIMEOUT: return NETWORK_EVENT_DISCONNECT_TIMEOUT;
|
||||||
}
|
}
|
||||||
|
|
||||||
return -1;
|
/* passthrough for our own events */
|
||||||
|
return ev;
|
||||||
}
|
}
|
||||||
|
|
||||||
char** network_sync(unsigned timeout_ms) {
|
char** network_sync(unsigned timeout_ms) {
|
||||||
|
@ -339080,19 +339085,21 @@ char** network_sync(unsigned timeout_ms) {
|
||||||
}
|
}
|
||||||
} break;
|
} break;
|
||||||
case MSG_RPC: {
|
case MSG_RPC: {
|
||||||
|
event.type = NETWORK_EVENT_RPC;
|
||||||
unsigned id = *(uint32_t*)ptr; ptr += 4;
|
unsigned id = *(uint32_t*)ptr; ptr += 4;
|
||||||
char *cmdline = ptr;
|
char *cmdline = ptr;
|
||||||
char *resp = rpc(id, cmdline);
|
char *resp = rpc(id, cmdline);
|
||||||
char *resp_msg = MALLOC(strlen(resp) + 5);
|
char *resp_msg = MALLOC(strlen(resp) + 6);
|
||||||
*(uint32_t*)&resp_msg[0] = MSG_RPC_RESP;
|
*(uint32_t*)&resp_msg[0] = MSG_RPC_RESP;
|
||||||
memcpy(&resp_msg[4], resp, strlen(resp)+1);
|
memcpy(&resp_msg[4], resp, strlen(resp)+1);
|
||||||
ENetPacket *packet = enet_packet_create(resp_msg, strlen(resp) + 4, ENET_PACKET_FLAG_RELIABLE);
|
ENetPacket *packet = enet_packet_create(resp_msg, strlen(resp) + 5, ENET_PACKET_FLAG_RELIABLE);
|
||||||
enet_peer_send(event.peer, 0, packet);
|
enet_peer_send(event.peer, 0, packet);
|
||||||
|
msg = stringf("%d %s", 0, va("req:%s res:%s", cmdline, resp));
|
||||||
FREE(resp_msg);
|
FREE(resp_msg);
|
||||||
} break;
|
} break;
|
||||||
case MSG_RPC_RESP: {
|
case MSG_RPC_RESP: {
|
||||||
// @todo: react on response?
|
event.type = NETWORK_EVENT_RPC_RESP;
|
||||||
msg = ptr;
|
msg = stringf("%d %s", 0, va("%s", ptr));
|
||||||
} break;
|
} break;
|
||||||
default:
|
default:
|
||||||
// PRINTF("!Receiving unk %d sz %d from peer ::%s:%u\n", mid, sz, ip, event.peer->address.port);
|
// PRINTF("!Receiving unk %d sz %d from peer ::%s:%u\n", mid, sz, ip, event.peer->address.port);
|
||||||
|
@ -339149,7 +339156,7 @@ void network_rpc(const char *signature, void *function) {
|
||||||
|
|
||||||
void network_rpc_send_to(int64_t rank, unsigned id, const char *cmdline) {
|
void network_rpc_send_to(int64_t rank, unsigned id, const char *cmdline) {
|
||||||
assert(network_get(NETWORK_RANK) == 0); /* must be a host */
|
assert(network_get(NETWORK_RANK) == 0); /* must be a host */
|
||||||
unsigned sz = strlen(cmdline) + 8;
|
unsigned sz = strlen(cmdline) + 9;
|
||||||
char *msg = MALLOC(sz);
|
char *msg = MALLOC(sz);
|
||||||
*(uint32_t*)&msg[0] = MSG_RPC;
|
*(uint32_t*)&msg[0] = MSG_RPC;
|
||||||
*(uint32_t*)&msg[4] = id;
|
*(uint32_t*)&msg[4] = id;
|
||||||
|
@ -339159,7 +339166,7 @@ void network_rpc_send_to(int64_t rank, unsigned id, const char *cmdline) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void network_rpc_send(unsigned id, const char *cmdline) {
|
void network_rpc_send(unsigned id, const char *cmdline) {
|
||||||
unsigned sz = strlen(cmdline) + 8;
|
unsigned sz = strlen(cmdline) + 9;
|
||||||
char *msg = MALLOC(sz);
|
char *msg = MALLOC(sz);
|
||||||
*(uint32_t*)&msg[0] = MSG_RPC;
|
*(uint32_t*)&msg[0] = MSG_RPC;
|
||||||
*(uint32_t*)&msg[4] = id;
|
*(uint32_t*)&msg[4] = id;
|
||||||
|
|
|
@ -485,7 +485,7 @@ void* network_buffer(void *ptr, unsigned sz, uint64_t flags, int64_t rank) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static
|
static
|
||||||
int enet_event_to_netsync(ENetEventType ev) {
|
int enet_event_to_netsync(int ev) {
|
||||||
switch (ev) {
|
switch (ev) {
|
||||||
case ENET_EVENT_TYPE_CONNECT: return NETWORK_EVENT_CONNECT;
|
case ENET_EVENT_TYPE_CONNECT: return NETWORK_EVENT_CONNECT;
|
||||||
case ENET_EVENT_TYPE_DISCONNECT: return NETWORK_EVENT_DISCONNECT;
|
case ENET_EVENT_TYPE_DISCONNECT: return NETWORK_EVENT_DISCONNECT;
|
||||||
|
@ -493,7 +493,8 @@ int enet_event_to_netsync(ENetEventType ev) {
|
||||||
case ENET_EVENT_TYPE_DISCONNECT_TIMEOUT: return NETWORK_EVENT_DISCONNECT_TIMEOUT;
|
case ENET_EVENT_TYPE_DISCONNECT_TIMEOUT: return NETWORK_EVENT_DISCONNECT_TIMEOUT;
|
||||||
}
|
}
|
||||||
|
|
||||||
return -1;
|
/* passthrough for our own events */
|
||||||
|
return ev;
|
||||||
}
|
}
|
||||||
|
|
||||||
char** network_sync(unsigned timeout_ms) {
|
char** network_sync(unsigned timeout_ms) {
|
||||||
|
@ -623,19 +624,21 @@ char** network_sync(unsigned timeout_ms) {
|
||||||
}
|
}
|
||||||
} break;
|
} break;
|
||||||
case MSG_RPC: {
|
case MSG_RPC: {
|
||||||
|
event.type = NETWORK_EVENT_RPC;
|
||||||
unsigned id = *(uint32_t*)ptr; ptr += 4;
|
unsigned id = *(uint32_t*)ptr; ptr += 4;
|
||||||
char *cmdline = ptr;
|
char *cmdline = ptr;
|
||||||
char *resp = rpc(id, cmdline);
|
char *resp = rpc(id, cmdline);
|
||||||
char *resp_msg = MALLOC(strlen(resp) + 5);
|
char *resp_msg = MALLOC(strlen(resp) + 6);
|
||||||
*(uint32_t*)&resp_msg[0] = MSG_RPC_RESP;
|
*(uint32_t*)&resp_msg[0] = MSG_RPC_RESP;
|
||||||
memcpy(&resp_msg[4], resp, strlen(resp)+1);
|
memcpy(&resp_msg[4], resp, strlen(resp)+1);
|
||||||
ENetPacket *packet = enet_packet_create(resp_msg, strlen(resp) + 4, ENET_PACKET_FLAG_RELIABLE);
|
ENetPacket *packet = enet_packet_create(resp_msg, strlen(resp) + 5, ENET_PACKET_FLAG_RELIABLE);
|
||||||
enet_peer_send(event.peer, 0, packet);
|
enet_peer_send(event.peer, 0, packet);
|
||||||
|
msg = stringf("%d %s", 0, va("req:%s res:%s", cmdline, resp));
|
||||||
FREE(resp_msg);
|
FREE(resp_msg);
|
||||||
} break;
|
} break;
|
||||||
case MSG_RPC_RESP: {
|
case MSG_RPC_RESP: {
|
||||||
// @todo: react on response?
|
event.type = NETWORK_EVENT_RPC_RESP;
|
||||||
msg = ptr;
|
msg = stringf("%d %s", 0, va("%s", ptr));
|
||||||
} break;
|
} break;
|
||||||
default:
|
default:
|
||||||
// PRINTF("!Receiving unk %d sz %d from peer ::%s:%u\n", mid, sz, ip, event.peer->address.port);
|
// PRINTF("!Receiving unk %d sz %d from peer ::%s:%u\n", mid, sz, ip, event.peer->address.port);
|
||||||
|
@ -692,7 +695,7 @@ void network_rpc(const char *signature, void *function) {
|
||||||
|
|
||||||
void network_rpc_send_to(int64_t rank, unsigned id, const char *cmdline) {
|
void network_rpc_send_to(int64_t rank, unsigned id, const char *cmdline) {
|
||||||
assert(network_get(NETWORK_RANK) == 0); /* must be a host */
|
assert(network_get(NETWORK_RANK) == 0); /* must be a host */
|
||||||
unsigned sz = strlen(cmdline) + 8;
|
unsigned sz = strlen(cmdline) + 9;
|
||||||
char *msg = MALLOC(sz);
|
char *msg = MALLOC(sz);
|
||||||
*(uint32_t*)&msg[0] = MSG_RPC;
|
*(uint32_t*)&msg[0] = MSG_RPC;
|
||||||
*(uint32_t*)&msg[4] = id;
|
*(uint32_t*)&msg[4] = id;
|
||||||
|
@ -702,7 +705,7 @@ void network_rpc_send_to(int64_t rank, unsigned id, const char *cmdline) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void network_rpc_send(unsigned id, const char *cmdline) {
|
void network_rpc_send(unsigned id, const char *cmdline) {
|
||||||
unsigned sz = strlen(cmdline) + 8;
|
unsigned sz = strlen(cmdline) + 9;
|
||||||
char *msg = MALLOC(sz);
|
char *msg = MALLOC(sz);
|
||||||
*(uint32_t*)&msg[0] = MSG_RPC;
|
*(uint32_t*)&msg[0] = MSG_RPC;
|
||||||
*(uint32_t*)&msg[4] = id;
|
*(uint32_t*)&msg[4] = id;
|
||||||
|
|
|
@ -31,6 +31,10 @@ enum {
|
||||||
NETWORK_EVENT_DISCONNECT,
|
NETWORK_EVENT_DISCONNECT,
|
||||||
NETWORK_EVENT_RECEIVE,
|
NETWORK_EVENT_RECEIVE,
|
||||||
NETWORK_EVENT_DISCONNECT_TIMEOUT,
|
NETWORK_EVENT_DISCONNECT_TIMEOUT,
|
||||||
|
|
||||||
|
/* offset from internal networking events */
|
||||||
|
NETWORK_EVENT_RPC = 10,
|
||||||
|
NETWORK_EVENT_RPC_RESP,
|
||||||
};
|
};
|
||||||
|
|
||||||
/* errcode and errstr are optional arguments, pass NULL to ignore them,
|
/* errcode and errstr are optional arguments, pass NULL to ignore them,
|
||||||
|
|
19
engine/v4k.c
19
engine/v4k.c
|
@ -9962,7 +9962,7 @@ void* network_buffer(void *ptr, unsigned sz, uint64_t flags, int64_t rank) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static
|
static
|
||||||
int enet_event_to_netsync(ENetEventType ev) {
|
int enet_event_to_netsync(int ev) {
|
||||||
switch (ev) {
|
switch (ev) {
|
||||||
case ENET_EVENT_TYPE_CONNECT: return NETWORK_EVENT_CONNECT;
|
case ENET_EVENT_TYPE_CONNECT: return NETWORK_EVENT_CONNECT;
|
||||||
case ENET_EVENT_TYPE_DISCONNECT: return NETWORK_EVENT_DISCONNECT;
|
case ENET_EVENT_TYPE_DISCONNECT: return NETWORK_EVENT_DISCONNECT;
|
||||||
|
@ -9970,7 +9970,8 @@ int enet_event_to_netsync(ENetEventType ev) {
|
||||||
case ENET_EVENT_TYPE_DISCONNECT_TIMEOUT: return NETWORK_EVENT_DISCONNECT_TIMEOUT;
|
case ENET_EVENT_TYPE_DISCONNECT_TIMEOUT: return NETWORK_EVENT_DISCONNECT_TIMEOUT;
|
||||||
}
|
}
|
||||||
|
|
||||||
return -1;
|
/* passthrough for our own events */
|
||||||
|
return ev;
|
||||||
}
|
}
|
||||||
|
|
||||||
char** network_sync(unsigned timeout_ms) {
|
char** network_sync(unsigned timeout_ms) {
|
||||||
|
@ -10100,19 +10101,21 @@ char** network_sync(unsigned timeout_ms) {
|
||||||
}
|
}
|
||||||
} break;
|
} break;
|
||||||
case MSG_RPC: {
|
case MSG_RPC: {
|
||||||
|
event.type = NETWORK_EVENT_RPC;
|
||||||
unsigned id = *(uint32_t*)ptr; ptr += 4;
|
unsigned id = *(uint32_t*)ptr; ptr += 4;
|
||||||
char *cmdline = ptr;
|
char *cmdline = ptr;
|
||||||
char *resp = rpc(id, cmdline);
|
char *resp = rpc(id, cmdline);
|
||||||
char *resp_msg = MALLOC(strlen(resp) + 5);
|
char *resp_msg = MALLOC(strlen(resp) + 6);
|
||||||
*(uint32_t*)&resp_msg[0] = MSG_RPC_RESP;
|
*(uint32_t*)&resp_msg[0] = MSG_RPC_RESP;
|
||||||
memcpy(&resp_msg[4], resp, strlen(resp)+1);
|
memcpy(&resp_msg[4], resp, strlen(resp)+1);
|
||||||
ENetPacket *packet = enet_packet_create(resp_msg, strlen(resp) + 4, ENET_PACKET_FLAG_RELIABLE);
|
ENetPacket *packet = enet_packet_create(resp_msg, strlen(resp) + 5, ENET_PACKET_FLAG_RELIABLE);
|
||||||
enet_peer_send(event.peer, 0, packet);
|
enet_peer_send(event.peer, 0, packet);
|
||||||
|
msg = stringf("%d %s", 0, va("req:%s res:%s", cmdline, resp));
|
||||||
FREE(resp_msg);
|
FREE(resp_msg);
|
||||||
} break;
|
} break;
|
||||||
case MSG_RPC_RESP: {
|
case MSG_RPC_RESP: {
|
||||||
// @todo: react on response?
|
event.type = NETWORK_EVENT_RPC_RESP;
|
||||||
msg = ptr;
|
msg = stringf("%d %s", 0, va("%s", ptr));
|
||||||
} break;
|
} break;
|
||||||
default:
|
default:
|
||||||
// PRINTF("!Receiving unk %d sz %d from peer ::%s:%u\n", mid, sz, ip, event.peer->address.port);
|
// PRINTF("!Receiving unk %d sz %d from peer ::%s:%u\n", mid, sz, ip, event.peer->address.port);
|
||||||
|
@ -10169,7 +10172,7 @@ void network_rpc(const char *signature, void *function) {
|
||||||
|
|
||||||
void network_rpc_send_to(int64_t rank, unsigned id, const char *cmdline) {
|
void network_rpc_send_to(int64_t rank, unsigned id, const char *cmdline) {
|
||||||
assert(network_get(NETWORK_RANK) == 0); /* must be a host */
|
assert(network_get(NETWORK_RANK) == 0); /* must be a host */
|
||||||
unsigned sz = strlen(cmdline) + 8;
|
unsigned sz = strlen(cmdline) + 9;
|
||||||
char *msg = MALLOC(sz);
|
char *msg = MALLOC(sz);
|
||||||
*(uint32_t*)&msg[0] = MSG_RPC;
|
*(uint32_t*)&msg[0] = MSG_RPC;
|
||||||
*(uint32_t*)&msg[4] = id;
|
*(uint32_t*)&msg[4] = id;
|
||||||
|
@ -10179,7 +10182,7 @@ void network_rpc_send_to(int64_t rank, unsigned id, const char *cmdline) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void network_rpc_send(unsigned id, const char *cmdline) {
|
void network_rpc_send(unsigned id, const char *cmdline) {
|
||||||
unsigned sz = strlen(cmdline) + 8;
|
unsigned sz = strlen(cmdline) + 9;
|
||||||
char *msg = MALLOC(sz);
|
char *msg = MALLOC(sz);
|
||||||
*(uint32_t*)&msg[0] = MSG_RPC;
|
*(uint32_t*)&msg[0] = MSG_RPC;
|
||||||
*(uint32_t*)&msg[4] = id;
|
*(uint32_t*)&msg[4] = id;
|
||||||
|
|
|
@ -2017,6 +2017,10 @@ enum {
|
||||||
NETWORK_EVENT_DISCONNECT,
|
NETWORK_EVENT_DISCONNECT,
|
||||||
NETWORK_EVENT_RECEIVE,
|
NETWORK_EVENT_RECEIVE,
|
||||||
NETWORK_EVENT_DISCONNECT_TIMEOUT,
|
NETWORK_EVENT_DISCONNECT_TIMEOUT,
|
||||||
|
|
||||||
|
/* offset from internal networking events */
|
||||||
|
NETWORK_EVENT_RPC = 10,
|
||||||
|
NETWORK_EVENT_RPC_RESP,
|
||||||
};
|
};
|
||||||
|
|
||||||
/* errcode and errstr are optional arguments, pass NULL to ignore them,
|
/* errcode and errstr are optional arguments, pass NULL to ignore them,
|
||||||
|
|
|
@ -596,7 +596,7 @@ details > summary::-webkit-details-marker {
|
||||||
|Version: | 2023.7 |
|
|Version: | 2023.7 |
|
||||||
|:--------------|:------------|
|
|:--------------|:------------|
|
||||||
|Branch: | main |
|
|Branch: | main |
|
||||||
|Commit: | 53 |
|
|Commit: | 54 |
|
||||||
<!--| Documentation last modified | { {LAST_MODIFIED} } |-->
|
<!--| Documentation last modified | { {LAST_MODIFIED} } |-->
|
||||||
|
|
||||||
# [V·4·K 2023.7 ](https://dev.v4.games/zaklaus/v4k)
|
# [V·4·K 2023.7 ](https://dev.v4.games/zaklaus/v4k)
|
||||||
|
@ -6557,7 +6557,9 @@ enum {
|
||||||
NETWORK_EVENT_CONNECT,
|
NETWORK_EVENT_CONNECT,
|
||||||
NETWORK_EVENT_DISCONNECT,
|
NETWORK_EVENT_DISCONNECT,
|
||||||
NETWORK_EVENT_RECEIVE,
|
NETWORK_EVENT_RECEIVE,
|
||||||
NETWORK_EVENT_DISCONNECT_TIMEOUT
|
NETWORK_EVENT_DISCONNECT_TIMEOUT,
|
||||||
|
NETWORK_EVENT_RPC = 10,
|
||||||
|
NETWORK_EVENT_RPC_RESP
|
||||||
};
|
};
|
||||||
~~~~~~
|
~~~~~~
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue