Thread: Finding maximum queue length

  1. #1
    Registered User crepincdotcom's Avatar
    Join Date
    Oct 2003
    Posts
    94

    Question Finding maximum queue length

    Hey all,

    Basically this hacked up version of a tcp/ip tutorial is supposed to make as many connections as possible, then report how many it was able to make. This will tell you how many active TCP connections can exist.

    But it doesn't work.

    Basically when I run it agaisnt linux or solaris boxes, I get 188 as the result, and it just sits their afterwards. Now, I know that the number should be a lot higher than 188, and also that the numbers are different for solaris and linux.

    Here's the code:

    Code:
    #include <stdio.h>      /* for printf() and fprintf() */
    #include <sys/socket.h> /* for socket(), connect(), send(), and recv() */
    #include <arpa/inet.h>  /* for sockaddr_in and inet_addr() */
    #include <stdlib.h>     /* for atoi() and exit() */
    #include <string.h>     /* for memset() */
    #include <unistd.h>     /* for close() */
    
    #define MAXCONN 1024   /* Max number of connections */
    
    int main(int argc, char *argv[])
    {
        int sock[MAXCONN];                  /* Socket descriptor */
        struct sockaddr_in echoServAddr;    /* Echo server address */
        unsigned short echoServPort;        /* Echo server port */
        char *servIP;                       /* Server IP address (dotted quad) */
        char *echoString;                   /* String to send to echo server */
        int i=0,s=0,numconn;
    
        if (argc < 2)    /* Test for correct number of arguments */
        {
           fprintf(stderr, "Usage: %s <IP> <Port>\n",
                   argv[0]);
           exit(1);
        }
    
        servIP = argv[1];             /* First arg: server IP address (dotted quad) */
        echoServPort = atoi(argv[2]); /* Use given port, if any */
    
        /* Create a reliable, stream socket using TCP */
        printf("Creating %d sockets for the test...",MAXCONN);
        i=0;
        while (i<MAXCONN) {
            if ((sock[i] = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0)
                s=1;
            i++;
        }
        printf("Done.\n");
        printf("Currently opening connection number:\n");
        /* Construct the server address structure */
        memset(&echoServAddr, 0, sizeof(echoServAddr));     /* Zero out structure */
        echoServAddr.sin_family      = AF_INET;             /* Internet address family */
        echoServAddr.sin_addr.s_addr = inet_addr(servIP);   /* Server IP address */
        echoServAddr.sin_port        = htons(echoServPort); /* Server port */
    
        /* Establish the connection to the echo server */
        s=0;
        i=0;
        while (s!=1) {
    	if (connect(sock[i], (struct sockaddr *) &echoServAddr, sizeof(echoServAddr)) < 0)
                s=1;
    	printf("\b\b\b%d",i);
    	i++;
    	if (i>MAXCONN) {
    	    printf("\nReached max number of connections. Recompile? ;-)\n");
    	    s=1;
    	}
    	sleep(0.2);
        }
        close(sock[0]); //havent gotten around to closing them all, but i will
        exit(0);
    }
    Ideas?
    Last edited by crepincdotcom; 08-04-2004 at 12:19 PM. Reason: Fixed formatting
    -Jack C
    jack {at} crepinc.com
    http://www.crepinc.com

  2. #2
    Registered User
    Join Date
    Nov 2001
    Posts
    1,348
    Do you mean that the program has different results depending on the platform it connects to?

    Kuphryn

  3. #3
    Registered User crepincdotcom's Avatar
    Join Date
    Oct 2003
    Posts
    94
    No, what I mean is that i SHOULD be different for different OS's. It's always in the thousands. Problem is, like I said, it hangs at 188 connections. Which isn't right. Did you happen to run the code, and get the same thing?

    thanks
    -Jack C
    jack {at} crepinc.com
    http://www.crepinc.com

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Strange string behavior
    By jcafaro10 in forum C Programming
    Replies: 2
    Last Post: 04-07-2009, 07:38 PM
  2. Help with FIFO QUEUE
    By jackfraust in forum C++ Programming
    Replies: 23
    Last Post: 04-03-2009, 08:17 AM
  3. HELP!!!!emergency Problem~expert please help
    By unknowppl in forum C++ Programming
    Replies: 9
    Last Post: 08-21-2008, 06:41 PM
  4. help with queues
    By Unregistered in forum C Programming
    Replies: 3
    Last Post: 05-21-2002, 09:09 PM
  5. help with queues
    By Unregistered in forum C Programming
    Replies: 3
    Last Post: 05-21-2002, 11:39 AM