comparison nnchat.c @ 91:acfc4b4bc180

Create network initialization functions in libnnchat and move Win32/WinSock code there.
author Matti Hamalainen <ccr@tnsp.org>
date Thu, 07 May 2009 00:04:37 +0300
parents 1e0bf7b4fd41
children 638f88374e3e
comparison
equal deleted inserted replaced
90:1e0bf7b4fd41 91:acfc4b4bc180
561 struct hostent *tmpHost; 561 struct hostent *tmpHost;
562 BOOL argsOK, isError = FALSE, 562 BOOL argsOK, isError = FALSE,
563 exitProg = FALSE, 563 exitProg = FALSE,
564 colorSet = FALSE, 564 colorSet = FALSE,
565 cursesInit = FALSE, 565 cursesInit = FALSE,
566 #if __WIN32
567 networkInit = FALSE, 566 networkInit = FALSE,
568 #endif
569 insertMode = TRUE; 567 insertMode = TRUE;
570 struct timeval tv; 568 struct timeval tv;
571 fd_set sockfds; 569 fd_set sockfds;
572 char *tmpStr; 570 char *tmpStr;
573 nn_editbuf_t *editBuf = newBuf(SET_BUFSIZE); 571 nn_editbuf_t *editBuf = newBuf(SET_BUFSIZE);
604 THERR("Could not open logfile for appending!\n"); 602 THERR("Could not open logfile for appending!\n");
605 return -9; 603 return -9;
606 } 604 }
607 } 605 }
608 606
609 #ifdef __WIN32 607 if (!initNetwork()) {
610 { 608 THERR("Could not initialize network subsystem.\n");
611 /* Initialize WinSock, if needed */ 609 goto err_exit;
612 WSADATA wsaData; 610 } else
613 int err = WSAStartup(0x0101, &wsaData);
614 if (err != 0) {
615 THERR("Could not initialize WinSock DLL: %d\n", err);
616 goto err_exit;
617 }
618 networkInit = TRUE; 611 networkInit = TRUE;
619 }
620 #endif
621 612
622 /* Okay ... */ 613 /* Okay ... */
623 THMSG(1, "Trying to resolve host '%s' ...\n", optServer); 614 THMSG(1, "Trying to resolve host '%s' ...\n", optServer);
624 tmpHost = gethostbyname(optServer); 615 tmpHost = gethostbyname(optServer);
625 if (tmpHost == NULL) { 616 if (tmpHost == NULL) {
979 970
980 th_free(optUserName2); 971 th_free(optUserName2);
981 972
982 closeConnection(tmpSocket); 973 closeConnection(tmpSocket);
983 974
984 #ifdef __WIN32
985 if (networkInit) 975 if (networkInit)
986 WSACleanup(); 976 closeNetwork();
987 #endif
988 977
989 THMSG(1, "Connection terminated.\n"); 978 THMSG(1, "Connection terminated.\n");
990 979
991 if (optLogFile) { 980 if (optLogFile) {
992 THMSG(1, "Closing logfile.\n"); 981 THMSG(1, "Closing logfile.\n");