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.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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
};
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.