Menu

Wrong order crashes program

Help
2001-05-02
2001-05-09
  • Anders Backman

    Anders Backman - 2001-05-02

    Setting up a TCPSocket before a UDPTransmit crashes my program under
    Windows2000Patch2.

    The other way around, setting up a UDPTransmit BEFORE a TCPSocket works

    My fault, or?

    #include <cc++/socket.h>
    class udpTransmit : public UDPTransmit {
    public:
      udpTransmit(  ) : UDPTransmit( ) {};
      udpTransmit( const InetAddress& host, tpport_t port ) : UDPTransmit( host, port) {};
      sockerror_t  Connect (const InetHostAddress &host, tpport_t port) {
        return UDPTransmit::Connect(host, port);
      }
    };

    class tcpSocket : public TCPSocket {

    protected:
        bool OnAccept(const InetHostAddress &ia, tpport_t port){

        cerr << "accepting from: " << ia.getHostname() << ":" << port <<endl;
        return true;
      }

    public:
      tcpSocket(const InetAddress &ia, tpport_t port) :
          TCPSocket(ia, port)
      {
        setException(THROW_OBJECT);
      };
    };

    void main( void )
    {
    #if 0
      // This order works.
      udpTransmit *udp = new udpTransmit;
      tcpSocket *tcp = new tcpSocket(InetHostAddress("localhost"), 4001);
    #else

      // This dont
      {
        tcpSocket *tcp = new tcpSocket(InetHostAddress("localhost"), 4001);
        udpTransmit *udp = new udpTransmit;
      }

    #endif
    };

     
    • David Sugar

      David Sugar - 2001-05-09

      This is an odd problem.  The thing to check for is if the init_wsa class ever gets called, and if it is constructed before your classes.  It is normally defined as a global object and should be invoked before any socket code is started, but if you are opening sockets in your own constructors with global variables, it is possible they do get called before wsa_init.  A slog in the wsa_init and in a few other constructors could help verify if this is occuring.

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.