bug-commoncpp
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

request for changes in the examples tcp.cpp, ...


From: Georg Soffel
Subject: request for changes in the examples tcp.cpp, ...
Date: Tue, 8 Apr 2003 16:55:28 +0200

Hello,

at the end of the tcp.cpp example is the following code:

        catch(Socket *socket)
        {
                tpport_t port;
                InetAddress saddr = (InetAddress)socket->getPeer(&port);
                cerr << "socket error " << saddr << ":" << port << endl;
                cout << "error number " << socket->getErrorNumber() <<
endl;
                if(socket->getErrorNumber() == Socket::errResourceFailure)
                {
                        cerr << "bind failed; no resources" << endl;
                        exit(-1);
                }
                if(socket->getErrorNumber() == Socket::errBindingFailed)
                {
                        cerr << "bind failed; port busy" << endl;
                        exit(-1);
                }
        }

This is probably not what is wanted.
By calling the function  socket->getPeer(&port) the error number of the
socket
is set to errSuccess and the two if statements will never be executed.
Something like:

        catch(Socket *socket)
        {
                cout << "error number " << socket->getErrorNumber() <<
endl;
                if(socket->getErrorNumber() == Socket::errResourceFailure)
                {
                        cerr << "bind failed; no resources" << endl;
                }
                if(socket->getErrorNumber() == Socket::errBindingFailed)
                {
                        cerr << "bind failed; port busy" << endl;
                }
                tpport_t port;
                InetAddress saddr = (InetAddress)socket->getPeer(&port);
                cerr << "socket error " << saddr << ":" << port << endl;
                exit(-1);
        }

is probably better. This problem occurs in other examples as well.
Furthermore I think some hints on

        InetAddress addr;
        addr = "255.255.255.255";
        cout << "testing addr: " << addr << ":" << 4096 << endl;
        addr = "127.0.0.1";
        cout << "binding for: " << addr << ":" << 4096 << endl;

might be helpfull to other users. Like:

        InetAddress addr;
        addr = "255.255.255.255";
        cout << "testing addr: " << addr << ":" << 4096 << endl; // FIXME:
Comment on what is tested here
        addr = "127.0.0.1"; // INADDR_LOOPBACK for access from the local
host only or
        //addr = "0.0.0.0"  // INADDR_ANY for access from any host
        cout << "binding for: " << addr << ":" << 4096 << endl;

Hope your are not disturbed from these minor problems.

Regards
Georg Soffel

Marconi Communications GmbH    Phone: +49 (7191) 13    2155
Postfach: 1920                                       Fax:       +49 (7191)
13 6 2155
D-71509 Backnang
mailto:address@hidden
Germany











reply via email to

[Prev in Thread] Current Thread [Next in Thread]