From: edwards AT panasync DOT canuck DOT ca (Colten Edwards) Subject: a problem I've been having. 9 Jul 1997 16:11:23 -0700 Sender: mail AT cygnus DOT com Approved: cygnus DOT gnu-win32 AT cygnus DOT com Distribution: cygnus Message-ID: Reply-To: edwac AT sk DOT sympatic DOT ca Original-To: Cygnus Gcc tools MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Original-Sender: owner-gnu-win32 AT cygnus DOT com I've been porting my program BitchX (irc chat client) to win95/nt with the Cygnus tools. I've run into a few gotcha's but other than that everything seems to work. 1. it seems than when I have a full screen program running and switch to another window, everything in the background'd window halts. This of course cause my irc client to "ping" out from the server. 2. we use a protocol called DCC which allows us to transfer files between clients. in order todo so we use sockets but I've found that on most Win95 systems and some NT systems we get an error extern struct hostent *resolv (const char *stuff) { struct hostent *hep; if ((hep = lookup_host(stuff)) == NULL) hep = lookup_ip(stuff); return hep; } extern struct hostent *lookup_host (const char *host) { struct hostent *hep; #ifdef WINNT sleep(1); alarm(2); #else alarm(1); #endif hep = gethostbyname(host); alarm(0); return hep; } gethostbyname() fails and the clients cannot connect. This only happens in some cases and not all which makes the problem very hard to find and debug. (it doesn't occur on my system which is NT4+sp3). I added the sleep(1) after somebody on the list suggested a workaround for this problem. 3. mixing cygwin functions and windows functions sometimes causes odd effects. For example I need to create a server that sits in the background watching a certain port number. On connect we need to send some information to the open port and then disconnect until the next time around. (It's for ident'd a user on port 113). The first attempt at this resulted in a working identd server, but it wasn't quite what I wanted. Then I discovered CreateThread() which would allow me todo exactly what I wanted. ie start a thread that run's constantly looking at port 113 for connects. Unfortunately what's happening is the thread runs, and then exits the entire client. Here's the code that I'm using to create the thread and the thread itself. int identd_socket_read; void start_identd(void) { DWORD threadid; HANDLE ret; int sock; unsigned short port = 113; if ((sock = connect_by_number(NULL, &port, SERVICE_SERVER, PROTOCOL_TCP, 1)) > -1) { identd_socket_read = sock; if (!(ret = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)identd_thread, NULL, 0, &threadid))) put_it("CreateThread returned NULL in identd"); CloseHandle(ret); } } DWORD WINAPI identd_thread(void) { char buffer[BIG_BUFFER_SIZE+1]; fd_set identd; int lport = 0, rport = 0; int identd_socket_write; char *bufptr; struct sockaddr_in remaddr; int sra = sizeof(struct sockaddr_in); while (1) { FD_ZERO(&identd); FD_SET(identd_socket_read, &identd); if ((identd_socket_write = accept(identd_socket_read, (struct sockaddr *) &remaddr, &sra)) > -1) { FD_ZERO(&identd); FD_SET(identd_socket_write, &identd); switch(select(identd_socket_write+1, &identd, NULL, NULL, NULL)) { default: bufptr = buffer; *bufptr = 0; FD_CLR(identd_socket_write, &identd); if ((read(identd_socket_write, buffer, sizeof(buffer)-1)) <= 0) break;; if (sscanf(bufptr, "%d , %d", &lport, &rport) != 2 || lport < 1 || lport >65535 || rport < 1 || rport >65535) break; sprintf(buffer, "%hu , %hu : USERID : UNIX : %s\r\n", lport, rport, username); write(identd_socket_write, buffer, strlen(buffer)); case -1: close(identd_socket_write); identd_socket_write = -1; case 0: break; } } sleep(1); } fprintf(stderr, "identd returned %d\n", WSAGetLastError()); abort(); } 4. The console code basically needs tobe re-written from scratch. I bypassed it entirely when I found it would not do some of the things I needed it todo. ie handle ansi color properly, cursor movement, clear screen etc. I do realize that the NT console is limited in some respects to what it can do, but it isn't that limited. Colten Edwards panasync AT efnet - For help on using this list (especially unsubscribing), send a message to "gnu-win32-request AT cygnus DOT com" with one line of text: "help".