8.2.2. test/faio/posix-1.01.02

Start felix section to test/faio/posix-1.01.02-0.flx[1 /1 ]
     1: #line 801 "./lpsrc/flx_faio.pak"
     2: #import <flx.flxh>
     3: include "flx_faio_posix";
     4: open Faio_posix;
     5: 
     6: header "typedef struct { char dat[8]; } tstbuf;";
     7: ctypes tstbuf;
     8: proc dprint: tstbuf = 'printf("%.8s", $1.dat);';
     9: fun get_data: tstbuf -> address = "$1.dat";
    10: fun get_data: charp -> address = "$1";
    11: 
    12: // try to send some data down a socket
    13: var port = 0;   // let mk_listener choose the port
    14: var &listener: socket_t <- mk_listener(&port, 1);
    15: 
    16: // not printing in thread to make output repeatable in
    17: // the face of scheduler changes.
    18: spawn_fthread{
    19:   {
    20:     var c: socket_t;
    21:     connect(&c, c"127.0.0.1", port);
    22: 
    23:     var len = 8;
    24:     var eof: bool;
    25:     async_write(c, &len, get_data((c"faio2you")), &eof);
    26:     shutdown(c, 1);  // no further writes (wakes reader)
    27: 
    28:     var b: tstbuf;
    29:     async_read(c, &len, b.data, &eof);
    30:     print "connector read "; dprint b; endl;
    31:     System::exit 0;
    32:   };
    33: };
    34: 
    35: var s: socket_t;
    36: accept (&s, listener);  // async!
    37: var b: tstbuf;
    38: var len = 16;           // ask for more than there is and rely on shutdown
    39: var eof: bool;
    40: async_read(s, &len, b.data, &eof);
    41: print "acceptor read "; print len; print " bytes: "; dprint b; endl;
    42: async_write(s, &len, get_data((c"thanks!!")), &eof);
End felix section to test/faio/posix-1.01.02-0.flx[1]
Start data section to test/faio/posix-1.01.02-0.expect[1 /1 ]
     1: acceptor read 8 bytes: faio2you
     2: connector read thanks!!
End data section to test/faio/posix-1.01.02-0.expect[1]