w3mvDTimeoutTestDriver

**************************************************************************

* w3mvDTimeoutTestDriver: Drive the w3mvdTimeoutTest

**************************************************************************

* [00] 02Apr01 jr  Initial creation

cfunction socket.builtin

include wbp w3include

include dm,bp,includes sysid.inc

include dm,bp,unix.h socket.h

include dm,bp,unix.h fcntl.h

include dm,bp,unix.h errno.h

include dm,bp,unix.h signal.h

* Open a socket to FCSS, send the message to run the test program

* Read the results which should be a timeout message

* Read the results again which should contain the data

CRNL = char(13):char(10)

NULL = char(0)

 

CRT "Enter the host name (q=quit, default=localhost): ":; input host

if host = "" then host = "localhost"

if host = "q" then stop

CRT "Enter the port to use (q=quit, default=6886): ":; input port

if port = "" then port = 6886

if port = "q" then stop

CRT "Starting ":host:" ":port

trigger.msg = "<OMNIS>001000000029200300@@@0000000016w3mvdtimeouttest01300@@@0000000008wTimeout01900@@@0000000006submit02000@@@0000000007evClick01100@@@0000000007w3omnis01200@@@0000000001201100@@@0000000009list.col101100@@@0000000009list.col201100@@@0000000020w3TriggerParam.pUser01200@@@0000000009userParam"

sock = 0

if not(num(port)) or port = "" or port < 1 or port > 65535 then

   CRT "Port must be a number between 0 and 65536"

   stop

end

if host = "" then

   CRT "Host must be specified"

   stop

end

CRT "Creating socket"

sock = %socket(AF$INET, SOCK$STREAM, 0)

if sock  < 0 then

   CRT 'Unable to open socket (errno=':system(41):')...'

   stop

end

CRT "Connecting"

res = %connect( sock + 0, AF$INET, host, port +0 )

if res < 0 then

   CRT "Unable to connect (errno=":system(41):")"

   %closesocket(sock + 0)

   stop

end

CRT @(-1):

for times = 1 to 10

    CRT "Pass ":times

    buffer = space(10000)

    buffer = trigger.msg

    buffer.size = len(buffer)

    CRT "  Writing"

    omnis.message = trigger.msg;  gosub display.message

    written = %send(sock + 0, buffer, buffer.size, 0)

    if written<0 then

       CRT "Write failed (errno=":system(41):")"

       %closesocket(sock + 0)

       stop

    end

    remaining    = ""                     ;* extra bytes from next msg

    for cnt = 1 to 2

        buffer.size = 10000

        buffer   = space(buffer.size)           

        results  = ""

        total    = 0

        expected = 0

        done     = 0

*       check for left over message which may be the entire message

        if remaining # "" then

           results = remaining

           total    = len(results)          ;* # bytes read so far

           remaining= ""

           if total >= 20 then expected = results[11,10] + 0

           if total >= expected then done = 1

        end

        CRT "  Read ":cnt

        loop

        until done do

           red = %recv( sock + 0, buffer , buffer.size, 0)

           if red <0 then

              CRT "Read failed (errno=":system(41):")"

              %closesocket(sock + 0)

              stop

           end

           if red > 0 then  

              results := buffer[1,red]

              total   += red   

              if total >= 20 then expected = results[11,10] + 0

              if expected > 5000 then

                 CRT "Possible error, expected to big"

                 done = 1

              end

              if expected > 0 and total >= expected then done = 1

              if total > expected and expected > 0 then                 

*                the message can contain the end of this message

*                and the start of the next

                 remaining = results[expected+1, 99999999]

                 results   = results[1,expected]

                 total = expected

                 done  = 1

              end

             CRT "    Read ":red:" bytes of ":expected:" total ":total

              

           end else

              done = 1

              CRT "    Nothing read"

           end

        repeat

        omnis.message = results;  gosub display.message

    next i

next times

%closesocket(sock + 0)

stop

display.message:              * displays an Omnis protocol message

                              * in: omnis.message

   temp = ""                 ;* formatted message

   call w3mvdDecode(omnis.message, temp)

   lines = dcount(temp, @am)

   for i = 1 to lines

       CRT "    ":temp<i>

   next i

return