"Fossies" - the Fresh Open Source Software Archive

Member "muscle/test/uploadstress.cpp" (8 Jun 2019, 2687 Bytes) of package /linux/privat/muscle7.30.zip:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. See also the last Fossies "Diffs" side-by-side code changes report for "uploadstress.cpp": 7.12_vs_7.13.

    1 /* This file is Copyright 2000-2013 Meyer Sound Laboratories Inc.  See the included LICENSE.txt file for details. */  
    2 
    3 #include <netdb.h>
    4 #include <unistd.h>
    5 #include <sys/socket.h>
    6 #include <time.h>
    7 
    8 #include "dataio/TCPSocketDataIO.h"
    9 #include "iogateway/MessageIOGateway.h"
   10 #include "reflector/StorageReflectConstants.h"
   11 #include "system/SetupSystem.h"
   12 #include "util/NetworkUtilityFunctions.h"
   13 #include "util/SocketMultiplexer.h"
   14 
   15 using namespace muscle;
   16 
   17 #define TEST(x) if ((x) != B_NO_ERROR) printf("Test failed, line %i\n",__LINE__)
   18 
   19 // This client just uploads a bunch of stuff to the server, trying to batter it down.
   20 int main(int argc, char ** argv)
   21 {
   22    CompleteSetupSystem css;
   23 
   24    const char * hostName = "localhost";
   25    int port = 0;
   26    if (argc > 1) hostName = argv[1];
   27    if (argc > 2) port = atoi(argv[2]);
   28    if (port <= 0) port = 2960;
   29 
   30    QueueGatewayMessageReceiver inQueue;
   31    SocketMultiplexer multiplexer;
   32    while(true)
   33    {
   34       uint32 bufCount=0;
   35       ConstSocketRef s = Connect(hostName, (uint16)port, "uploadstress");
   36       if (s() == NULL) return 10;
   37 
   38       MessageIOGateway gw;
   39       gw.SetDataIO(DataIORef(new TCPSocketDataIO(s, false)));
   40       while(true)
   41       {
   42          const int fd = s.GetFileDescriptor();
   43          multiplexer.RegisterSocketForReadReady(fd);
   44          multiplexer.RegisterSocketForWriteReady(fd);
   45 
   46          if (multiplexer.WaitForEvents() < 0) printf("uploadstress: WaitForEvents() failed!\n");
   47 
   48          const bool reading = multiplexer.IsSocketReadyForRead(fd);
   49          const bool writing = multiplexer.IsSocketReadyForWrite(fd);
   50 
   51          if (gw.HasBytesToOutput() == false)
   52          {
   53             char buf[128];
   54             muscleSprintf(buf, UINT32_FORMAT_SPEC, bufCount++);
   55             printf("Adding message [%s]\n", buf);
   56 
   57             MessageRef smsg = GetMessageFromPool(PR_COMMAND_SETDATA);
   58             Message data(1234);
   59             data.AddString("nerf", "boy!");
   60             smsg()->AddMessage(buf, data);
   61             gw.AddOutgoingMessage(smsg);
   62          }
   63 
   64          const bool writeError = ((writing)&&(gw.DoOutput() < 0));
   65          const bool readError  = ((reading)&&(gw.DoInput(inQueue) < 0));
   66          if ((readError)||(writeError))
   67          {
   68             printf("Connection closed, exiting.\n");
   69             break;
   70          }
   71 
   72          MessageRef incoming;
   73          while(inQueue.RemoveHead(incoming) == B_NO_ERROR)
   74          {
   75             printf("Heard message from server:-----------------------------------\n");
   76             incoming()->PrintToStream();
   77             printf("-------------------------------------------------------------\n");
   78          }
   79       }
   80    }
   81 
   82    printf("\n\nBye!\n");
   83    return 0;
   84 }