multiple nak strings

This is a discussion on multiple nak strings within the C++ Programming forums, part of the General Programming Boards category; Good Day!! I am creating a program to send and receive input from a telnet session in C/C++. I create ...

  1. #1
    Registered User
    Join Date
    Oct 2001
    Posts
    18

    Question multiple nak strings

    Good Day!!

    I am creating a program to send and receive input from a telnet session in C/C++.
    I create the pipes, can send and receive and look for an "ack" string and "nak" string ok.
    Now I want to look for multiple naks strings coming in from the input pipe. Any suggestions ??
    Here is my function to send and receive one
    ack and one nak string. I want to expand the nak to more that one nak string.

    Code:
    int SendReceive(const char *cmd, const char *ack, const char *nak, int timeout, int printonly)
    {
            int ai, ni, r;
            char c;
            char cmd1[MAXINPUT];
    
            r = 0;
    
            if (cmd && strlen(cmd))
            {
                    if (printonly)
                    {
                            if (cmd[0] == '\020')
                                    cout << "^P" << cmd + 1; // NB: true ^P turns on printing on DOS
                            else cout << cmd;
                            return -1;
    
                    }cout << cmd << endl; //Uncomment this line to see traffic
                    write(fdwr, cmd, strlen(cmd)); // June 07,2004
            }
    
            if (ack != NULL)
            {
                    alarm(timeout);
                    alarmed = 0;
                    ai = 0;
                    ni = 0;
                    while (!alarmed)
                    {
                            if (read(fdrd, &c, 1) < 0)
                            {
                                    if (errno == EINTR) continue;
                                    if (errno == EAGAIN) continue;
                                    break;
                            }
                            if (ack[ai] == c) ai++;
                            else ai = 0;
                            if (ack[ai] == '\0')
                            {
                                    r = -1;
                                    break;
                            }
                            if (nak)
                            {
                                    if (nak[ni] == c) ni++;
                                    else ni = 0;
                                    if (nak[ni] == '\0'){cout << "break2" << endl; break;}
                            }
                    }
                    if (alarmed)
    
                            syslog(LOG_INFO, "Timeout while waiting for command response.");
    
                    else if (nak && nak[ni] == '\0')
                            syslog(LOG_INFO, "Negative command response.");
    
                    else if (!r)
                            syslog(LOG_INFO, "Unspecified error while waiting for command response.");
    
    
                  unalarm();
            }
    
            else r = -1;
    
            return r;
    
    }
    Thanks and have a great day
    Last edited by bhorrobi; 08-09-2004 at 08:19 AM.

  2. #2
    Registered User
    Join Date
    Nov 2001
    Posts
    1,348
    Modify this line:

    if (nak[ni] == '\0'){cout << "break2" << endl; break;}

    Kuphryn

  3. #3
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,452
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Reading Multiple Multi-Part Strings From a Text File
    By bengreenwood in forum C++ Programming
    Replies: 2
    Last Post: 06-02-2009, 10:43 AM
  2. Splittig a string into multiple strings
    By Evenstevens in forum C Programming
    Replies: 7
    Last Post: 04-09-2009, 12:38 PM
  3. Replies: 2
    Last Post: 02-23-2004, 05:34 AM
  4. bubble sorting multiple strings
    By jibbles in forum C Programming
    Replies: 10
    Last Post: 10-11-2003, 11:48 PM
  5. Multiple Strings
    By Unregistered in forum C++ Programming
    Replies: 5
    Last Post: 08-15-2002, 11:41 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21