Log In
New Account
  
 
Home My Page Project Tree Code Snippets Project Openings NUTSS
 
 
Summary Tracker Lists CVS Files
 

CVS | Administration

Annotation of libnutss/examples/slinkapp.c, revision 1.1.1.1

1.1       saikat      1: #include <stdio.h>
                      2: #include <stdlib.h>
                      3: #include <string.h>
                      4: #ifndef WIN32
                      5: #include <poll.h>
                      6: #include <sys/socket.h>
                      7: #endif
                      8: #include <pthread.h>
                      9: #include "nutss.h"
                     10: #include "swaplinks.h"
                     11:
                     12: #ifdef WIN32
                     13: #define sleep(sec) Sleep((sec)*1000)
                     14: #define snprintf   _snprintf
                     15: #endif
                     16:
                     17: int num;
                     18: int q, r;
                     19: FILE *f = NULL;
                     20:
                     21: void *recvthread(void *arg) {
                     22:     swaplinks_p swp = (swaplinks_p)arg;
                     23:     struct sockaddr_ns peer;
                     24:     socklen_t len = sizeof(peer);
                     25:     char tmp[256];
                     26:
                     27:     for (;;) {
                     28:         if (swaplinks_recvfrom(swp, tmp, sizeof(tmp), 0, &peer, &len) > 0) {
                     29:             if (f) fprintf(f, "node-%d RCVD %s\n", num, tmp);
                     30:             if (!strncmp(tmp, "REQUEST", 7)) {
                     31:                 snprintf(tmp, sizeof(tmp), "RESPONSE Response %d from node-%d", r++, num);
                     32:                 swaplinks_sendto(swp, tmp, strlen(tmp)+1, 0, &peer, sizeof(peer));
                     33:                 if (f) fprintf(f, "node-%d SENT %s\n", num, tmp);
                     34:             }
                     35:         }
                     36:     }
                     37: }
                     38:
                     39: int main(int argc, char **argv) {
                     40:     struct sockaddr_ns reg;
                     41:       swaplinks_p swp;
                     42:     char tmp[256];
                     43:     int i = -1;
                     44:     pthread_t tid;
                     45:     struct timespec ts;
                     46:
                     47:     if (argc < 2) {
                     48:         printf("Usage:\n  slinkapp num\n");
                     49:         exit(1);
                     50:     }
                     51:
                     52:     num = atoi(argv[1]);
                     53:
                     54:     if (argc > 2)
                     55:         i = atoi(argv[2]);
                     56:
                     57:     snprintf(tmp, sizeof(tmp), "test%d", num);
                     58:     nutss_config_set(NUTSS_CONFIG_USERNAME, tmp, strlen(tmp));
                     59:     nutss_config_set(NUTSS_CONFIG_PROXYUSERNAME, tmp, strlen(tmp));
                     60:     nutss_config_set(NUTSS_CONFIG_PROXYPASSWORD, tmp, strlen(tmp));
                     61:     strncpy(tmp, "nutss.net", sizeof(tmp));
                     62:     nutss_config_set(NUTSS_CONFIG_DOMAINNAME, tmp, strlen(tmp));
                     63:     strncpy(tmp, "sip.nutss.net:5060", sizeof(tmp));
                     64:     nutss_config_set(NUTSS_CONFIG_SIGPROXY, tmp, strlen(tmp));
                     65:
                     66:     sprintf(tmp, "output/output_node%d.txt", num);
                     67:     f = fopen(tmp,"w");
                     68:     if (f == NULL) {
                     69:         f = stderr;
                     70:     }
                     71:
                     72:     memset(&reg, 0, sizeof(reg));
                     73:     reg.family = AF_NUTSS;
                     74:     strncpy(reg.user, "ths1", sizeof(reg.user));
                     75:     strncpy(reg.domain, "nutss.net", sizeof(reg.domain));
                     76:     strncpy(reg.service, "swaplinksd", sizeof(reg.service));
                     77:
                     78:     swaplinks_init();
                     79:     swp = swaplinks("cloud9", &reg);
                     80:
                     81:     pthread_create(&tid, NULL, recvthread, swp);
                     82:
                     83:     while (i-- != 0) {
                     84:         snprintf(tmp, sizeof(tmp), "REQUEST Query %d from node-%d", q++, num);
                     85:         if (swaplinks_sendtoany(swp, tmp, strlen(tmp)+1, 0) != -1) {
                     86:             if (f) {
                     87:                 fprintf(f, "node-%d SENT %s\n", num, tmp);
                     88:                 fflush(f);
                     89:             }
                     90:         } else q--;
                     91:         sleep(3);
                     92:     }
                     93:
                     94:     return 0;
                     95: }

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>
 

GForge.cis.cornell.edu is brought to you by

Cornell Computing and Information Science


Powered By GForge Collaborative Development Environment