Re: [PATCH 1/1] tidbits: net-udp: solicit new client for server mode
Hannes Diethelm <[email protected]>
| Newsgroups | dev.linux.lists.xenomai |
|---|---|
| Message-ID | <[email protected]> |
Am 01.06.26 um 11:10 schrieb Philippe Gerum: > Philippe Gerum <[email protected]> writes: > >> Hannes Diethelm <[email protected]> writes: >> >>> This fixes random EINPROGRESS at init or during runtime. >>> >>> Also correct whitespaces and make stdout more consistent. >>> >>> Signed-off-by: Hannes Diethelm <[email protected]> >>> --- >>> tidbits/oob-net-udp.c | 58 +++++++++++++++++++++++++++++++++++++------ >>> 1 file changed, 50 insertions(+), 8 deletions(-) >>> >>> diff --git a/tidbits/oob-net-udp.c b/tidbits/oob-net-udp.c >>> index 11b8459..7af834f 100644 >>> --- a/tidbits/oob-net-udp.c >>> +++ b/tidbits/oob-net-udp.c >>> @@ -50,12 +50,12 @@ static void usage(void) >>> } >>> >>> static void print_addr(char* text, struct sockaddr_in *addr){ >>> - char ip_str[INET_ADDRSTRLEN+1]; >>> - inet_ntop(AF_INET, &(addr->sin_addr), ip_str, sizeof(ip_str)); >>> - evl_printf("%s--------\n", text); >>> - evl_printf("IP-Address: %s\n", ip_str); >>> - evl_printf("Port: %d\n", ntohs(addr->sin_port)); >>> - evl_printf("Family: %d\n", addr->sin_family); >>> + char ip_str[INET_ADDRSTRLEN+1]; >>> + inet_ntop(AF_INET, &(addr->sin_addr), ip_str, sizeof(ip_str)); >>> + evl_printf("== %s\n", text); >>> + evl_printf(" ip-address: %s\n", ip_str); >>> + evl_printf(" port: %d\n", ntohs(addr->sin_port)); >>> + evl_printf(" family: %d\n", addr->sin_family); >>> } >>> >>> static void sender(int s, const char *text, int mcount, >>> @@ -226,6 +226,8 @@ static void client(int s, const char *text, int mcount, >>> free(tbuf); >>> } >>> >>> +#define SERVER_ADDR_LIST_SIZE 64 >>> + >>> static void server(int s, const char *text, int mcount, >>> struct sockaddr_in *addr, int iter) >>> { >>> @@ -236,6 +238,9 @@ static void server(int s, const char *text, int mcount, >>> ssize_t ret; >>> char *tbuf; >>> char rbuf[16384]; >>> + in_addr_t addr_list[SERVER_ADDR_LIST_SIZE]={}; >> ^ missing whitespaces >>> + size_t addr_list_fill=0; >>> + bool solicit_done; >>> >>> tlen = (strlen(text) + 1) * mcount; >>> tbuf = malloc(tlen); >>> @@ -276,6 +281,39 @@ static void server(int s, const char *text, int mcount, >>> evl_printf(" (TRUNCATED)"); >>> evl_printf(": %.*s\n", (int)ret, rbuf); >>> >>> + /* >>> + * We need to call evl_net_solicit for each new >>> + * client once before sending data. This will break >>> + * realtime for the first response. >>> + * If this is not done and the ARP address is not >>> + * yet in cache or garbage-collected, oob_sendmsg >>> + * will return EINPROGRESS on start or during runtime. >>> + */ >> >> We can happily send redundant solicit requests to the core, no need to >> filter out cached addresses, evl_net_solicit() will do the right thing. >> > > Except that doing so would always demote the caller to the in-band > stage, which may not be what you want. The fact that we'd need to > maintain a cache in apps in order to figure out whether solicitation > should be done shows a shortcoming in the core, users should not have to > do this dance. > > We should have an oob call for probing the route+arp caches with > ipv4. I'll look into this asap. > Yes, this is the reason I do it this way and print out a message if this happens. I think server mode with multiple clients in real time is not something you can just easily do without careful considerations what happens when multiple clients send a message at the same time or TDMA behind. My intent in this example is mostly to show that it is possible. A real application would need one of these options: - A thread only for solicitation so the main thread doesn't get blocked - evl_net_solicit() with a flag like MSG_DONTWAIT and then poll in the main loop if the client is ready - Know the clients in advance - A warm up phase during clients can connect - ... However, a way for probing and reading the arp would shurely help. It would also be nice to have an "evl net" command to list the entry's. I tried the normal arp command but it doesn't behave nicely with evl. No hurry from my side, I have linuxcnc already running well with evl oob networking, I only need client mode and i know the IP in advance, so all good there. Sorry about the whitespace issues, switching between projects... I sent a patch v2. Feel free to merge this already and I can create a separate patch when probing ARP is here or wait and I create a patch v3.