close Warning: Can't synchronize with repository "(default)" ("(default)" is not readable or not a Git repository.). Look in the Trac log for more information.

Changes between Version 1 and Version 2 of Proto/cModules/d0NetworkServiceAPI/a0DesignUsage


Ignore:
Timestamp:
Nov 30, 2014, 5:14:09 AM (9 years ago)
Author:
wontoniii
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • Proto/cModules/d0NetworkServiceAPI/a0DesignUsage

    v1 v2  
    1818
    1919{{{#!c
    20   #include <stdio.h>
    21   #include <stdlib.h>
    22   #include <mfapi.h>
     20#include <stdio.h>
     21#include <stdlib.h>
     22#include <mfapi.h>
    2323
    24   int main(int argc, char *argv[]) {
    25     struct Handle handle;
    26     //Choosing GUIDs 1 and 2 as reference
    27     int mine = 1, other = 2, sent = 0, received = 0, size = 65*1024;
    28    
    29     //Buffer to send and receive messages; I don't care about the content
    30     u_char buf[size];
    31    
    32     //Requesting basic transport. Listening for GUID mine
    33     ret = mfopen(&handle, "basic\0", NULL, mine);
    34     if(ret) {
    35         fprintf(stderr, "receiver: mfopen error\n");
    36         return (EXIT_FAILURE);
    37     }
    38    
    39     //Send message to other. No additional services requested
    40     sent = mfsend(&handle, buf, size, other, NULL);
    41     if (sent < 0) {
    42         fprintf (stderr,"mfsendmsg error\n");
    43         return EXIT_FAILURE;
    44     }
    45    
    46     //Wait to receive new message
    47     received = mfrecv_blk(&handle, buf, size, NULL, 0);
    48     if (received < 0) {
    49         fprintf (stderr,"mfrecv_blk error\n");
    50         return EXIT_FAILURE;
    51     }
    52    
    53     printf("Intended to send %d bytes, sent %d bytes, received %d bytes\n", size, sent, received);
     24int main(int argc, char *argv[]) {
     25        struct Handle handle;
     26        //Choosing GUIDs 1 and 2 as reference
     27        int mine = 1, other = 2, sent = 0, received = 0, size = 65*1024;
    5428
    55     mfclose(&handle);
    56     return EXIT_SUCCESS;
    57   }
     29        //Buffer to send and receive messages; I don't care about the content
     30        u_char buf[size];
     31
     32        //Requesting basic transport. Listening for GUID mine
     33        ret = mfopen(&handle, "basic\0", NULL, mine);
     34        if(ret) {
     35                fprintf(stderr, "receiver: mfopen error\n");
     36                return (EXIT_FAILURE);
     37        }
     38
     39        //Send message to other. No additional services requested
     40        sent = mfsend(&handle, buf, size, other, NULL);
     41        if (sent < 0) {
     42                fprintf (stderr,"mfsendmsg error\n");
     43                return EXIT_FAILURE;
     44        }
     45
     46        //Wait to receive new message
     47        received = mfrecv_blk(&handle, buf, size, NULL, 0);
     48        if (received < 0) {
     49                fprintf (stderr,"mfrecv_blk error\n");
     50                return EXIT_FAILURE;
     51        }
     52
     53        printf("Intended to send %d bytes, sent %d bytes, received %d bytes\n", size, sent, received);
     54
     55        mfclose(&handle);
     56        return EXIT_SUCCESS;
     57}
    5858}}}