--- /dev/null
+/**
+ * \file distributed.c
+ *
+ * This a test application that:
+ * - creates vres without negotiation
+ * - creates send and receive endpoint
+ * - binds that endpoint to vres
+ * - in cycle (NUM loops) sends messages in separate thread and
+ * prints send time
+ * - receives messages in separate receiver thread
+ * - destroys vres
+ *
+ */
+#include "frsh.h"
+
+#include <errno.h>
+#include <stdio.h>
+#include <pthread.h>
+
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+
+#define NUM 20
+#define PORT 65111
+#define PROTO FRSH_NETPF_FWP
+
+int exit_flag = 0;
+
+void* sender()
+{
+ frsh_send_endpoint_t sepoint;
+ frsh_vres_id_t vres;
+ frsh_send_endpoint_protocol_info_t send_pinfo;
+ char msg1[10];
+ int count;
+ /*struct timespec sendtime;*/
+
+ send_pinfo.body = NULL;
+ if (frsh_send_endpoint_create(PROTO, inet_addr("127.0.0.1"), PORT,
+ send_pinfo, &sepoint)< 0) {
+ return NULL;
+ }
+
+ /* Contract negotiation */
+
+ printf("Send endpoint created\n");
+ frsh_send_endpoint_bind(vres, sepoint);
+ printf("Send endpoint bounded\n");
+
+ sleep(2);
+ //for (count = 0; count < NUM; count++) {
+ //fwp_set_rt_prio(90);
+
+ count = 0;
+ while (count < NUM){
+ count++;
+ sprintf(msg1,"msg%d",count);
+ frsh_send_async(sepoint, msg1, sizeof(msg1));
+
+ printf("sent\n");
+ /*clock_gettime(CLOCK_MONOTONIC, &sendtime);
+ FWP_DEBUG("Sent %d: sec = %ld nsec = %ld \n", count,
+ sendtime.tv_sec, sendtime.tv_nsec);
+ usleep(1000);*/
+ }
+
+ while (!(exit_flag)) {
+ sleep(1);
+ }
+
+ return NULL;
+}
+
+void* receiver()
+{
+ size_t len;
+ char buffer[30];
+ frsh_receive_endpoint_t repoint;
+ int count;
+ struct timespec recvtime;
+ frsh_network_address_t from;
+ frsh_receive_endpoint_protocol_info_t recv_pinfo;
+ frsh_endpoint_queueing_info_t qinfo;
+
+ recv_pinfo.body = NULL;
+ /* local_addr should be handled when creating socket */
+ if (frsh_receive_endpoint_create(PROTO, PORT, qinfo, recv_pinfo,
+ &repoint) < 0){
+ return NULL;
+ }
+ printf("Receive endpoint created\n");
+
+ for (count = 1; count <= NUM; count++) {
+
+ if ((frsh_receive_sync(repoint, buffer, sizeof(buffer), &len,
+ &from))){
+ perror("Error while receiving data");
+ return NULL;
+ }
+ else printf("Received - %s\n", buffer);
+
+ clock_gettime(CLOCK_MONOTONIC, &recvtime);
+ printf("Received %d: sec = %ld nsec = %ld \n", count,
+ recvtime.tv_sec, recvtime.tv_nsec);
+ }
+
+ exit_flag = 1;
+
+ return NULL;
+}
+
+int main()
+{
+ pthread_attr_t thattr;
+ pthread_t thread;
+
+ printf("Start\n");
+ if (frsh_distributed_init()) {
+ fprintf(stderr,"FRSH distributed modul initialization failed.\n");
+ }
+
+ pthread_attr_init(&thattr);
+ pthread_create(&thread, &thattr, sender, NULL);
+ pthread_create(&thread, &thattr, receiver, NULL);
+ pthread_join(thread, (void**) NULL);
+
+ printf("Test PASSED!\n");
+ return 0;
+}