7
7
*
8
8
*
9
9
* IDENTIFICATION
10
- * $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-connect.c,v 1.69 1998/06/21 16:39:11 momjian Exp $
10
+ * $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-connect.c,v 1.70 1998/07/03 04:24:12 momjian Exp $
11
11
*
12
12
*-------------------------------------------------------------------------
13
13
*/
@@ -407,6 +407,7 @@ connectDB(PGconn *conn)
407
407
family ,
408
408
len ;
409
409
char beresp ;
410
+ int on = 1 ;
410
411
411
412
/*
412
413
* Initialize the startup packet.
@@ -456,8 +457,11 @@ connectDB(PGconn *conn)
456
457
conn -> raddr .in .sin_port = htons ((unsigned short ) (portno ));
457
458
len = sizeof (struct sockaddr_in );
458
459
}
460
+ #ifndef WIN32
459
461
else
460
462
len = UNIXSOCK_PATH (conn -> raddr .un , portno );
463
+ #endif
464
+
461
465
462
466
/* Connect to the server */
463
467
if ((conn -> sock = socket (family , SOCK_STREAM , 0 )) < 0 )
@@ -482,7 +486,11 @@ connectDB(PGconn *conn)
482
486
* We need nonblocking I/O, and we don't want delay of outgoing data.
483
487
*/
484
488
489
+ #ifndef WIN32
485
490
if (fcntl (conn -> sock , F_SETFL , O_NONBLOCK ) < 0 )
491
+ #else
492
+ if (ioctlsocket (conn -> sock ,FIONBIO , & on ) != 0 )
493
+ #endif
486
494
{
487
495
(void ) sprintf (conn -> errorMessage ,
488
496
"connectDB() -- fcntl() failed: errno=%d\n%s\n" ,
@@ -493,7 +501,6 @@ connectDB(PGconn *conn)
493
501
if (family == AF_INET )
494
502
{
495
503
struct protoent * pe ;
496
- int on = 1 ;
497
504
498
505
pe = getprotobyname ("TCP" );
499
506
if (pe == NULL )
@@ -503,11 +510,18 @@ connectDB(PGconn *conn)
503
510
goto connect_errReturn ;
504
511
}
505
512
if (setsockopt (conn -> sock , pe -> p_proto , TCP_NODELAY ,
506
- & on , sizeof (on )) < 0 )
513
+ #ifdef WIN32
514
+ (char * )
515
+ #endif
516
+ & on ,
517
+ sizeof (on )) < 0 )
507
518
{
508
519
(void ) sprintf (conn -> errorMessage ,
509
520
"connectDB() -- setsockopt failed: errno=%d\n%s\n" ,
510
521
errno , strerror (errno ));
522
+ #ifdef WIN32
523
+ printf ("Winsock error: %i\n" ,WSAGetLastError ());
524
+ #endif
511
525
goto connect_errReturn ;
512
526
}
513
527
}
@@ -666,7 +680,11 @@ connectDB(PGconn *conn)
666
680
connect_errReturn :
667
681
if (conn -> sock >= 0 )
668
682
{
683
+ #ifdef WIN32
684
+ closesocket (conn -> sock );
685
+ #else
669
686
close (conn -> sock );
687
+ #endif
670
688
conn -> sock = -1 ;
671
689
}
672
690
return CONNECTION_BAD ;
@@ -742,7 +760,11 @@ freePGconn(PGconn *conn)
742
760
return ;
743
761
PQclearAsyncResult (conn ); /* deallocate result and curTuple */
744
762
if (conn -> sock >= 0 )
745
- close (conn -> sock ); /* shouldn't happen, but... */
763
+ #ifdef WIN32
764
+ closesocket (conn -> sock );
765
+ #else
766
+ close (conn -> sock );
767
+ #endif
746
768
if (conn -> pghost )
747
769
free (conn -> pghost );
748
770
if (conn -> pgport )
@@ -783,6 +805,7 @@ closePGconn(PGconn *conn)
783
805
* If connection is already gone, that's cool. No reason for kernel
784
806
* to kill us when we try to write to it. So ignore SIGPIPE signals.
785
807
*/
808
+ #ifndef WIN32
786
809
#if defined(USE_POSIX_SIGNALS )
787
810
struct sigaction ignore_action ;
788
811
struct sigaction oldaction ;
@@ -806,13 +829,18 @@ closePGconn(PGconn *conn)
806
829
807
830
signal (SIGPIPE , oldsignal );
808
831
#endif
832
+ #endif /* Win32 uses no signals at all */
809
833
}
810
834
811
835
/*
812
836
* Close the connection, reset all transient state, flush I/O buffers.
813
837
*/
814
838
if (conn -> sock >= 0 )
839
+ #ifdef WIN32
840
+ closesocket (conn -> sock );
841
+ #else
815
842
close (conn -> sock );
843
+ #endif
816
844
conn -> sock = -1 ;
817
845
conn -> status = CONNECTION_BAD ; /* Well, not really _bad_ - just
818
846
* absent */
0 commit comments