26 #include <sys/errno.h>
29 #define UNUSED(v) ((void) v) // compiler warning mitigation
32 pthread_t EVcallbackThread;
34 int readThreadInitialized = FALSE;
36 void X3D_initialize(
char *hostname) {
37 struct sockaddr_in serv_addr;
38 struct hostent *server;
42 WORD wVersionRequested;
53 wVersionRequested = MAKEWORD( 2, 2 );
55 err = WSAStartup( wVersionRequested, &wsaData );
59 int socket_error = WSAGetLastError();
66 case WSAVERNOTSUPPORTED:
87 while ((_X3D_FreeWRL_FD = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
92 int socket_error = WSAGetLastError();
96 case (WSANOTINITIALISED):
102 case (WSAEAFNOSUPPORT):
105 case (WSAEINPROGRESS):
114 case (WSAEPROTONOSUPPORT):
117 case (WSAEPROTOTYPE):
120 case (WSAESOCKTNOSUPPORT):
131 if (loopCount >= 10000) {
132 X3D_error(
"ERROR opening socket");
139 if (strlen(hostname) == 0) hostname =
"localhost";
141 server = gethostbyname(hostname);
142 if (server == NULL) {
143 fprintf(stderr,
"ERROR, no such host :%s:\n",hostname);
148 bzero((
char *) &serv_addr,
sizeof(serv_addr));
149 serv_addr.sin_family = AF_INET;
150 bcopy((
char *)server->h_addr,
151 (
char *)&serv_addr.sin_addr.s_addr,
154 serv_addr.sin_port = htons(EAIBASESOCKET);
159 while ((constat = connect(_X3D_FreeWRL_FD,(
struct sockaddr *) &serv_addr,
sizeof(serv_addr))) < 0) {
162 if (loopCount >= 10000) {
163 X3D_error(
"ERROR connecting to socket - FreeWRL not there?");
170 iret1 = pthread_create( &readThread, NULL, freewrlReadThread, NULL);
171 iret2 = pthread_create( &EVcallbackThread, NULL, freewrlEVcallbackThread, NULL);
176 iret2 = pthread_create(&swigThread, NULL, freewrlSwigThread, NULL);
186 void X3D_shutdown() {
187 _X3D_makeShortCommand(STOPFREEWRL);
190 closesocket(_X3D_FreeWRL_FD);