From fb266987ab3d2bfe97d4f292259eb3cd7b6172d6 Mon Sep 17 00:00:00 2001 From: sangorrin Date: Fri, 26 Oct 2007 17:46:58 +0000 Subject: [PATCH] preparing to do unix fna git-svn-id: http://www.frescor.org/private/svn/frescor/fna/trunk@819 35b4ef3e-fd22-0410-ab77-dab3279adceb --- config.mk_example | 4 +- include/frsh_fna.h | 28 ++-- rules.mk | 4 +- src/fna_configuration.c | 4 +- src_unix/unix_fna.c | 132 +++++++++++------- src_unix/unix_fna.h | 11 ++ tests/tests_rtep_fna/test_c_rtep_fna.c | 4 +- tests/tests_unix_fna/Makefile | 5 + .../test_unix_fna_send_receive.c | 120 ++++++++++++++++ tests/tests_unix_fna/test_unix_send_receive.c | 126 +++++++++++++++++ 10 files changed, 365 insertions(+), 73 deletions(-) create mode 100644 tests/tests_unix_fna/Makefile create mode 100644 tests/tests_unix_fna/test_unix_fna_send_receive.c create mode 100644 tests/tests_unix_fna/test_unix_send_receive.c diff --git a/config.mk_example b/config.mk_example index a5fee75..257e2c6 100644 --- a/config.mk_example +++ b/config.mk_example @@ -6,8 +6,8 @@ PLATFORM_PATH = $(HOME)/marte EXPORT_PATH = $(HOME)/export # enable networks with their flag (change DISABLED<->ENABLED) -RTEP_ENABLE = RTEP_FNA_ENABLED -UNIX_ENABLE = UNIX_FNA_DISABLED +RTEP_ENABLE = RTEP_FNA_DISABLED +UNIX_ENABLE = UNIX_FNA_ENABLED # the gcc to use CC = mgcc diff --git a/include/frsh_fna.h b/include/frsh_fna.h index bcf5056..4c2af91 100644 --- a/include/frsh_fna.h +++ b/include/frsh_fna.h @@ -72,7 +72,7 @@ #include /* for bool */ #include "fna_configuration.h" -#ifdef RTEP +#ifdef RTEP_FNA_ENABLED #include "rtep.h" #endif @@ -123,11 +123,10 @@ * FNA_ERR_BAD_ARGUMENT: if pointers are NULL \n * **/ -#ifdef RTEP -int frsh_rtep_map_network_address - (const frsh_resource_id_t resource_id, - const rtep_station_id_t in_address, - frsh_network_address_t *out_address); +#ifdef RTEP_FNA_ENABLED +int frsh_rtep_map_network_address(const frsh_resource_id_t resource_id, + const rtep_station_id_t in_address, + frsh_network_address_t *out_address); #endif /** @@ -150,11 +149,10 @@ int frsh_rtep_map_network_address * FNA_ERR_BAD_ARGUMENT: if pointers are NULL \n * **/ -#ifdef RTEP -int frsh_rtep_map_stream_id - (const frsh_resource_id_t resource_id, - const rtep_channel_t in_stream, - frsh_stream_id_t *out_stream); +#ifdef RTEP_FNA_ENABLED +int frsh_rtep_map_stream_id(const frsh_resource_id_t resource_id, + const rtep_channel_t in_stream, + frsh_stream_id_t *out_stream); #endif /*@}*/ @@ -196,7 +194,7 @@ int frsh_rtep_map_stream_id * FNA_ERR_REJECTED_CONTRACT : if the renegotiation fails \n * **/ -#ifdef RTEP +#ifdef RTEP_FNA_ENABLED int frsh_rtep_negotiation_messages_vres_renegotiate (const frsh_resource_id_t resource_id, const struct timespec *period); @@ -220,7 +218,7 @@ int frsh_rtep_negotiation_messages_vres_renegotiate * FNA_ERR_BAD_ARGUMENT: if pointers are NULL \n * **/ -#ifdef RTEP +#ifdef RTEP_FNA_ENABLED int frsh_rtep_negotiation_messages_vres_get_period (const frsh_resource_id_t resource_id, struct timespec *period); @@ -250,7 +248,7 @@ int frsh_rtep_negotiation_messages_vres_get_period * FNA_ERR_BAD_ARGUMENT: if pointers are NULL \n * **/ -#ifdef RTEP +#ifdef RTEP_FNA_ENABLED int frsh_rtep_service_thread_vres_renegotiate (const frsh_resource_id_t resource_id, const struct timespec *budget, @@ -276,7 +274,7 @@ int frsh_rtep_service_thread_vres_renegotiate * FNA_ERR_BAD_ARGUMENT: if pointers are NULL \n * **/ -#ifdef RTEP +#ifdef RTEP_FNA_ENABLED int frsh_rtep_service_thread_vres_get_budget_and_period (const frsh_resource_id_t resource_id, struct timespec *budget, diff --git a/rules.mk b/rules.mk index f7567a7..b5e8191 100644 --- a/rules.mk +++ b/rules.mk @@ -1,4 +1,4 @@ -.PHONY: none clean +.PHONY: none clean libfna.a none: @exec echo -e "\nPlease introduce a target, i.e: 'make test_dtm_xxx.exe'"; @@ -7,7 +7,7 @@ none: @exec echo -e "\n>> Building $@: "; @if [ -f $< ]; \ then \ - $(CC) $(CFLAGS) $< $(LDFLAGS) &> /dev/null; \ + $(CC) $(CFLAGS) $< $(LDFLAGS); \ fi; # -o $@ (fix marte mgcc) @exec echo ">> End Building $@"; diff --git a/src/fna_configuration.c b/src/fna_configuration.c index 8884178..935fd30 100644 --- a/src/fna_configuration.c +++ b/src/fna_configuration.c @@ -81,8 +81,8 @@ fna_operations_t *fna_operations[FNA_MAX_NETWORKS] = { - &rtep_fna_operations, - // &unix_fna_operations, + // &rtep_fna_operations, + &unix_fna_operations, // NULL, // resource_id 0 NULL, // resource_id 1 NULL, // resource_id 2 diff --git a/src_unix/unix_fna.c b/src_unix/unix_fna.c index 779fe21..8ffca6d 100644 --- a/src_unix/unix_fna.c +++ b/src_unix/unix_fna.c @@ -65,7 +65,7 @@ #include /* for malloc and free */ #include "unix_fna.h" /* function prototypes */ -#if 0 +#if 1 #include #define DEBUG(x,args...) printf("%s: " x, __func__ , ##args) #else @@ -76,6 +76,15 @@ // INITIALIZATION ////////////////////////////////////////////////////////////////////// +char *the_unix_stream_ids[MX_UNIX_STREAM_IDS] = { + "/tmp/stream00", + "/tmp/stream01", + "/tmp/stream02", + "/tmp/stream03", + "/tmp/stream04", + "/tmp/stream05" +}; + /** * unix_fna_init() * @@ -83,8 +92,8 @@ int unix_fna_init(const frsh_resource_id_t resource_id) { - DEBUG("starting unix fna\n"); - return 0; + DEBUG("NOT IMPLEMENTED\n"); + return 0; } /////////////////////////////////////////////////////////////////// @@ -100,7 +109,8 @@ int unix_fna_contract_negotiate(const frsh_resource_id_t resource_id, const frsh_contract_t *contract, fna_vres_id_t *vres) { - return 0; + DEBUG("NOT IMPLEMENTED\n"); + return 0; } /** @@ -112,7 +122,8 @@ int unix_fna_contract_renegotiate_sync(const frsh_resource_id_t resource_id, const fna_vres_id_t vres, const frsh_contract_t *new_contract) { - return 0; + DEBUG("NOT IMPLEMENTED\n"); + return 0; } /** @@ -126,7 +137,8 @@ int unix_fna_contract_renegotiate_async(const frsh_resource_id_t resource_id, frsh_signal_t signal_to_notify, frsh_signal_info_t signal_info) { - return 0; + DEBUG("NOT IMPLEMENTED\n"); + return 0; } /** @@ -138,7 +150,8 @@ int unix_fna_vres_get_renegotiation_status(const frsh_resource_id_t resource_id, const fna_vres_id_t vres, frsh_renegotiation_status_t *renegotiation_status) { - return 0; + DEBUG("NOT IMPLEMENTED\n"); + return 0; } /** @@ -149,7 +162,8 @@ int unix_fna_vres_get_renegotiation_status(const frsh_resource_id_t resource_id, int unix_fna_vres_destroy(const frsh_resource_id_t resource_id, const fna_vres_id_t vres) { - return 0; + DEBUG("NOT IMPLEMENTED\n"); + return 0; } /** @@ -161,7 +175,8 @@ int unix_fna_vres_get_contract(const frsh_resource_id_t resource_id, const fna_vres_id_t vres, frsh_contract_t *contract) { - return 0; + DEBUG("NOT IMPLEMENTED\n"); + return 0; } /** @@ -173,7 +188,8 @@ int unix_fna_vres_get_usage(const frsh_resource_id_t resource_id, const fna_vres_id_t vres, struct timespec *usage) { - return 0; + DEBUG("NOT IMPLEMENTED\n"); + return 0; } /** @@ -185,7 +201,8 @@ int unix_fna_vres_get_remaining_budget(const frsh_resource_id_t resource_id, const fna_vres_id_t vres, struct timespec *remaining_budget) { - return 0; + DEBUG("NOT IMPLEMENTED\n"); + return 0; } /** @@ -198,7 +215,8 @@ int unix_fna_vres_get_budget_and_period(const frsh_resource_id_t resource_id, struct timespec *budget, struct timespec *period) { - return 0; + DEBUG("NOT IMPLEMENTED\n"); + return 0; } /////////////////////////////////////////////////////////////////// @@ -214,7 +232,8 @@ int unix_fna_resource_get_capacity(const frsh_resource_id_t resource_id, const int importance, uint32_t *capacity) { - return 0; + DEBUG("NOT IMPLEMENTED\n"); + return 0; } /** @@ -226,7 +245,8 @@ int unix_fna_resource_get_total_weight(const frsh_resource_id_t resource_id, const int importance, int *total_weight) { - return 0; + DEBUG("NOT IMPLEMENTED\n"); + return 0; } /** @@ -239,7 +259,8 @@ int unix_fna_vres_decrease_capacity(const frsh_resource_id_t resource_id, const struct timespec new_budget, const struct timespec new_period) { - return 0; + DEBUG("NOT IMPLEMENTED\n"); + return 0; } /////////////////////////////////////////////////////////////////// @@ -255,7 +276,8 @@ int unix_fna_send_sync(const fna_endpoint_data_t *endpoint, const void *msg, const size_t size) { - return 0; + DEBUG("NOT IMPLEMENTED\n"); + return 0; } /** @@ -267,7 +289,8 @@ int unix_fna_send_async(const fna_endpoint_data_t *endpoint, const void *msg, const size_t size) { - return 0; + DEBUG("send async\n"); + return 0; } /** @@ -281,7 +304,8 @@ int unix_fna_receive_sync(const fna_endpoint_data_t *endpoint, size_t *received_bytes, frsh_network_address_t *from) { - return 0; + DEBUG("receive sync\n"); + return 0; } /** @@ -295,7 +319,8 @@ int unix_fna_receive_async(const fna_endpoint_data_t *endpoint, size_t *received_bytes, frsh_network_address_t *from) { - return 0; + DEBUG("NOT IMPLEMENTED\n"); + return 0; } /** @@ -308,7 +333,8 @@ int unix_fna_send_endpoint_get_status(const fna_endpoint_data_t *endpoint, frsh_endpoint_network_status_t *network_status, frsh_protocol_status_t *protocol_status) { - return 0; + DEBUG("NOT IMPLEMENTED\n"); + return 0; } /** @@ -317,7 +343,8 @@ int unix_fna_send_endpoint_get_status(const fna_endpoint_data_t *endpoint, **/ int unix_fna_receive_endpoint_created(const fna_endpoint_data_t *endpoint) { - return 0; + DEBUG("NOT IMPLEMENTED\n"); + return 0; } /** @@ -330,7 +357,8 @@ int unix_fna_receive_endpoint_get_status(const fna_endpoint_data_t *endpoint, frsh_endpoint_network_status_t *network_status, frsh_protocol_status_t *protocol_status) { - return 0; + DEBUG("NOT IMPLEMENTED\n"); + return 0; } ////////////////////////////////////////////////////////////////////// @@ -346,7 +374,8 @@ int unix_fna_network_get_max_message_size(const frsh_resource_id_t resource_id, const frsh_network_address_t destination, size_t *max_size) { - return 0; + DEBUG("NOT IMPLEMENTED\n"); + return 0; } /** @@ -358,7 +387,8 @@ int unix_fna_network_bytes_to_budget(const frsh_resource_id_t resource_id, const size_t nbytes, struct timespec *budget) { - return 0; + DEBUG("NOT IMPLEMENTED\n"); + return 0; } /** @@ -370,7 +400,8 @@ int unix_fna_network_budget_to_bytes(const frsh_resource_id_t resource_id, const struct timespec *budget, size_t *nbytes) { - return 0; + DEBUG("NOT IMPLEMENTED\n"); + return 0; } /** @@ -381,34 +412,35 @@ int unix_fna_network_budget_to_bytes(const frsh_resource_id_t resource_id, int unix_fna_network_get_min_eff_budget(const frsh_resource_id_t resource_id, struct timespec *budget) { - return 0; + DEBUG("NOT IMPLEMENTED\n"); + return 0; } // GLOBAL variable to install the network protocol in FRESCOR fna_operations_t unix_fna_operations = { - .fna_init = unix_fna_init, - .fna_contract_negotiate = unix_fna_contract_negotiate, - .fna_contract_renegotiate_sync = unix_fna_contract_renegotiate_sync, - .fna_contract_renegotiate_async = unix_fna_contract_renegotiate_async, - .fna_vres_get_renegotiation_status = unix_fna_vres_get_renegotiation_status, - .fna_vres_destroy = unix_fna_vres_destroy, - .fna_vres_get_contract = unix_fna_vres_get_contract, - .fna_vres_get_usage = unix_fna_vres_get_usage, - .fna_vres_get_remaining_budget = unix_fna_vres_get_remaining_budget, - .fna_vres_get_budget_and_period = unix_fna_vres_get_budget_and_period, - .fna_resource_get_capacity = unix_fna_resource_get_capacity, - .fna_resource_get_total_weight = unix_fna_resource_get_total_weight, - .fna_vres_decrease_capacity = unix_fna_vres_decrease_capacity, - .fna_send_sync = unix_fna_send_sync, - .fna_send_async = unix_fna_send_async, - .fna_receive_sync = unix_fna_receive_sync, - .fna_receive_async = unix_fna_receive_async, - .fna_send_endpoint_get_status = unix_fna_send_endpoint_get_status, - .fna_receive_endpoint_created = unix_fna_receive_endpoint_created, - .fna_receive_endpoint_get_status = unix_fna_receive_endpoint_get_status, - .fna_network_get_max_message_size = unix_fna_network_get_max_message_size, - .fna_network_bytes_to_budget = unix_fna_network_bytes_to_budget, - .fna_network_budget_to_bytes = unix_fna_network_budget_to_bytes, - .fna_network_get_min_eff_budget = unix_fna_network_get_min_eff_budget + .fna_init = unix_fna_init, + .fna_contract_negotiate = unix_fna_contract_negotiate, + .fna_contract_renegotiate_sync = unix_fna_contract_renegotiate_sync, + .fna_contract_renegotiate_async = unix_fna_contract_renegotiate_async, + .fna_vres_get_renegotiation_status = unix_fna_vres_get_renegotiation_status, + .fna_vres_destroy = unix_fna_vres_destroy, + .fna_vres_get_contract = unix_fna_vres_get_contract, + .fna_vres_get_usage = unix_fna_vres_get_usage, + .fna_vres_get_remaining_budget = unix_fna_vres_get_remaining_budget, + .fna_vres_get_budget_and_period = unix_fna_vres_get_budget_and_period, + .fna_resource_get_capacity = unix_fna_resource_get_capacity, + .fna_resource_get_total_weight = unix_fna_resource_get_total_weight, + .fna_vres_decrease_capacity = unix_fna_vres_decrease_capacity, + .fna_send_sync = unix_fna_send_sync, + .fna_send_async = unix_fna_send_async, + .fna_receive_sync = unix_fna_receive_sync, + .fna_receive_async = unix_fna_receive_async, + .fna_send_endpoint_get_status = unix_fna_send_endpoint_get_status, + .fna_receive_endpoint_created = unix_fna_receive_endpoint_created, + .fna_receive_endpoint_get_status = unix_fna_receive_endpoint_get_status, + .fna_network_get_max_message_size = unix_fna_network_get_max_message_size, + .fna_network_bytes_to_budget = unix_fna_network_bytes_to_budget, + .fna_network_budget_to_bytes = unix_fna_network_budget_to_bytes, + .fna_network_get_min_eff_budget = unix_fna_network_get_min_eff_budget }; diff --git a/src_unix/unix_fna.h b/src_unix/unix_fna.h index 7d890ca..07db3d7 100644 --- a/src_unix/unix_fna.h +++ b/src_unix/unix_fna.h @@ -70,4 +70,15 @@ extern fna_operations_t unix_fna_operations; +/** + * unix addresses: + * + * As we are in the same node the network address will be always 0. + * The stream_ids 0 .. MX_UNIX_STREAM_IDS-1 are statically mapped in the + * following table to UNIX pathnames. + * + **/ +#define MX_UNIX_STREAM_IDS 6 +extern char *the_unix_stream_ids[MX_UNIX_STREAM_IDS]; + #endif // _UNIX_FNA_H_ diff --git a/tests/tests_rtep_fna/test_c_rtep_fna.c b/tests/tests_rtep_fna/test_c_rtep_fna.c index 5b7ee42..c9e162d 100644 --- a/tests/tests_rtep_fna/test_c_rtep_fna.c +++ b/tests/tests_rtep_fna/test_c_rtep_fna.c @@ -71,7 +71,7 @@ #include // for timespec #include "frsh_core.h" // for frsh_contract_set_xxx -#include "frsh_core_types.h" // for FRSH_RESOURCE_ID_DEFAULT +#include "frsh_core_types.h" // for FRSH_NETWORK_ID_DEFAULT #include "frsh_distributed_types.h" // for frsh_network_address_t, frsh_stream_id_t #include "fna.h" // for fna_vres_id_t @@ -99,7 +99,7 @@ int main () printf("--------------------------------------------------\n"); printf("1.- fna_init\n"); printf("--------------------------------------------------\n"); - err = rtep_fna_operations.fna_init(FRSH_RESOURCE_ID_DEFAULT); + err = rtep_fna_operations.fna_init(FRSH_NETWORK_ID_DEFAULT); assert(err == 0); printf("--------------------------------------------------\n"); diff --git a/tests/tests_unix_fna/Makefile b/tests/tests_unix_fna/Makefile new file mode 100644 index 0000000..7d3abec --- /dev/null +++ b/tests/tests_unix_fna/Makefile @@ -0,0 +1,5 @@ +include ../../config.mk +include ../../rules.mk + +CFLAGS += -I$(FNA_PATH)/src_unix/ +LDFLAGS += -L$(FNA_PATH)/lib -lunixfna -L$(FRSH_PATH)/lib -lfrsh -L$(FOSA_PATH)/lib -lfosa_$(PLATFORM) -lm -lfna \ No newline at end of file diff --git a/tests/tests_unix_fna/test_unix_fna_send_receive.c b/tests/tests_unix_fna/test_unix_fna_send_receive.c new file mode 100644 index 0000000..7843077 --- /dev/null +++ b/tests/tests_unix_fna/test_unix_fna_send_receive.c @@ -0,0 +1,120 @@ +#include +#include /* atoi */ +#include /* sleep */ +#include +#include /* memset */ + +#include +#include /* struct sockaddr_un */ + +#include "frsh_core.h" // for frsh_contract_set_xxx +#include "frsh_core_types.h" // for FRSH_NETWORK_ID_DEFAULT +#include "frsh_distributed_types.h" // for frsh_network_address_t, frsh_stream_id_t + +#include "fna.h" // for fna_vres_id_t +#include "unix_fna.h" // for unix_fna_operations + + +void sender(void); +void receiver(void); + +int main (int argc, char **argv) +{ + int err; + + if (argc != 2) { + printf("please provide the node to execute:\n"); + printf(" $./mprogram 0 (sender)\n"); + printf(" $./mprogram 1 (receiver)\n"); + return -1; + } + + err = unix_fna_operations.fna_init(FRSH_NETWORK_ID_DEFAULT); + assert(err == 0); + + switch(atoi(argv[1])) { + case 0: + sender(); + break; + case 1: + receiver(); + break; + default: + printf("wrong node number\n"); + return -1; + } + + unlink(the_unix_stream_ids[0]); + unlink(the_unix_stream_ids[1]); + + return 0; +} + +void sender(void) +{ + int err, i; + + fna_endpoint_data_t endpoint; + frsh_stream_id_t receiver_port; + char buffer[100]; + size_t size; + + printf("I am the sender\n"); + + receiver_port = 0; /* statically configured to the_unix_stream_ids[0] */ + + endpoint.endpoint_type = FRSH_SEND_ENDPOINT_TYPE; + endpoint.vres = 0; + endpoint.is_bound = true; + endpoint.destination = 0; /* only for send_endpoints */ + endpoint.resource_id = FRSH_NETWORK_ID_DEFAULT; + endpoint.stream_id = receiver_port; + + for(i=0; i<10; i++) { + sleep(1); + size = snprintf(buffer, sizeof(buffer), "hello world %d", i); + + err = unix_fna_operations.fna_send_async(&endpoint, + buffer, + size); + assert (err == 0); + + printf("sender : sent %s\n", buffer); + } + + printf("Sender done\n"); +} + +void receiver(void) +{ + int err, i; + fna_endpoint_data_t endpoint; + frsh_network_address_t sender_addr; + frsh_stream_id_t sender_port; + char buffer[100]; + size_t received_bytes; + + printf("I am the receiver\n"); + + sender_port = 1; + + endpoint.endpoint_type = FRSH_RECEIVE_ENDPOINT_TYPE; + endpoint.is_bound = false; + endpoint.resource_id = FRSH_NETWORK_ID_DEFAULT; + endpoint.stream_id = sender_port; + + for(i=0; i<10; i++) { + err = unix_fna_operations.fna_receive_sync(&endpoint, + buffer, + 100, + &received_bytes, + &sender_addr); + assert (err == 0); + + buffer[received_bytes] = '\0'; + + printf("receiver : received %s\n", buffer); + } + + printf("Receiver done\n"); +} diff --git a/tests/tests_unix_fna/test_unix_send_receive.c b/tests/tests_unix_fna/test_unix_send_receive.c new file mode 100644 index 0000000..f09297d --- /dev/null +++ b/tests/tests_unix_fna/test_unix_send_receive.c @@ -0,0 +1,126 @@ +#include +#include /* atoi */ +#include /* sleep */ +#include +#include /* memset */ + +#include +#include /* struct sockaddr_un */ + +#define SENDER_PATH "/tmp/sender_addr" +#define RECEIVER_PATH "/tmp/receiver_addr" + +void sender(void); +void receiver(void); + +int main (int argc, char **argv) +{ + if (argc != 2) { + printf("please provide the node to execute:\n"); + printf(" $./mprogram 0 (sender)\n"); + printf(" $./mprogram 1 (receiver)\n"); + return -1; + } + + switch(atoi(argv[1])) { + case 0: + sender(); + break; + case 1: + receiver(); + break; + default: + printf("wrong node number\n"); + return -1; + } + + unlink(SENDER_PATH); + unlink(RECEIVER_PATH); + + return 0; +} + +void sender(void) +{ + int sock, err, i; + struct sockaddr_un sender_addr, receiver_addr; + char buffer[100]; + size_t size; + ssize_t sent_bytes; + + printf("I am the sender\n"); + + err = sock = socket(AF_UNIX, SOCK_DGRAM, 0); + assert(err >= 0); + + memset(&sender_addr, 0, sizeof(sender_addr)); + sender_addr.sun_family = AF_UNIX; + strcpy(sender_addr.sun_path, SENDER_PATH); + + err = bind(sock, (struct sockaddr *)&sender_addr, sizeof(sender_addr)); + assert(err >= 0); + + memset(&receiver_addr, 0, sizeof(receiver_addr)); + receiver_addr.sun_family = AF_UNIX; + strcpy(receiver_addr.sun_path, RECEIVER_PATH); + + for(i=0; i<10; i++) { + sleep(1); + size = snprintf(buffer, sizeof(buffer), "hello world %d", i); + sent_bytes = sendto(sock, + buffer, + size, + 0, + (struct sockaddr *) &receiver_addr, + sizeof(receiver_addr)); + + assert(sent_bytes >= 0); + + printf("sender : sent %s\n", buffer); + } + + close(sock); + printf("Sender done\n"); +} + +void receiver(void) +{ + int sock, err, i; + struct sockaddr_un sender_addr, receiver_addr; + char buffer[100]; + ssize_t received_bytes; + socklen_t from_len; + + printf("I am the receiver\n"); + + err = sock = socket(AF_UNIX, SOCK_DGRAM, 0); + assert(err >= 0); + + memset(&receiver_addr, 0, sizeof(receiver_addr)); + receiver_addr.sun_family = AF_UNIX; + strcpy(receiver_addr.sun_path, RECEIVER_PATH); + + err = bind(sock, (struct sockaddr *)&receiver_addr, sizeof(receiver_addr)); + assert(err >= 0); + + for(i=0; i<10; i++) { + + sleep(5); + + from_len = sizeof(sender_addr); + received_bytes = recvfrom(sock, + buffer, + sizeof(buffer), + 0, + (struct sockaddr *)&sender_addr, + &from_len); + + assert(received_bytes >= 0); + + buffer[received_bytes] = '\0'; + printf("receiver : received %s\n", buffer); + } + + close(sock); + printf("receiver done\n"); +} -- 2.39.2