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 30 and Version 31 of Internal/SystemPrototyping/Projects/MobilityStack


Ignore:
Timestamp:
Dec 18, 2013, 10:02:31 PM (10 years ago)
Author:
wontoniii
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • Internal/SystemPrototyping/Projects/MobilityStack

    v30 v31  
    230230For any additional information on this two tools please refer to their web pages.
    231231
     232=== 3.4 Usage Example ===
     233The following code snippet shows a very simple C program used to send a message to another destination and receive the following reply.
     234 {{{
     235#!div style="font-size: 100%"
     236  {{{#!C
     237  #include <stdio.h>
     238  #include <stdlib.h>
     239  #include <mfapi.h>
     240
     241  int main(int argc, char *argv[]) {
     242        struct Handle handle;
     243        int mine = 1, other = 2, sent = 0, received = 0, size = 65*1024;
     244       
     245        //Buffer to send and receive messages; I don't care about the content
     246        u_char buf[size];
     247       
     248        //Requesting basic transport. Listening for GUID mine
     249        ret = mfopen(&handle, "basic\0", NULL, mine);
     250        if(ret) {
     251                fprintf(stderr, "receiver: mfopen error\n");
     252                return (EXIT_FAILURE);
     253        }
     254       
     255        //Send message to other. No additional services requested
     256        sent = mfsend(&handle, buf, size, other, NULL);
     257        if (sent < 0) {
     258                fprintf (stderr,"mfsendmsg error\n");
     259                return EXIT_FAILURE;
     260        }
     261       
     262        //Wait to receive new message
     263        received = mfrecv_blk(&handle, buf, size, NULL, 0);
     264        if (received < 0) {
     265                fprintf (stderr,"mfrecv_blk error\n");
     266                return EXIT_FAILURE;
     267        }
     268       
     269        printf("Intended to send %d bytes, sent %d bytes, received %d bytes\n", size, sent, received);
     270
     271        mfclose(&handle);
     272        return EXIT_SUCCESS;
     273  }
     274
     275  }}}
     276}}}
     277
    232278== 4. Performance ==
    233279