Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit5db5c2d

Browse files
committed
> Ok, where's a "system dependent hack" :)
> It seems that win9x doesn't have the "netmsg.dll" so it defaults to "normal"> FormatMessage.> I wonder if one could load wsock32.dll or winsock.dll on those systems> instead of netmsg.dll.>> Mikhail, could you please test this code on your nt4 system?> Could someone else test this code on a win98/95 system?>> It works on win2k over here.It works on win2k here too but not on win98/95 or winNT.Anyway, attached is the patch which uses Magnus's my_sock_strerrorfunction (renamed to winsock_strerror). The only difference is thatI put the code to load and unload netmsg.dll in the libpqdll.c(is this OK Magnus?).Mikhail Terekhov
1 parentf933766 commit5db5c2d

File tree

7 files changed

+90
-60
lines changed

7 files changed

+90
-60
lines changed

‎src/interfaces/libpq/fe-connect.c

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-connect.c,v 1.175 2001/08/17 15:11:15 momjian Exp $
11+
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-connect.c,v 1.176 2001/08/21 20:39:52 momjian Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -703,7 +703,7 @@ connectMakeNonblocking(PGconn *conn)
703703
{
704704
printfPQExpBuffer(&conn->errorMessage,
705705
libpq_gettext("could not set socket to non-blocking mode: %s\n"),
706-
strerror(errno));
706+
SOCK_STRERROR(SOCK_ERRNO));
707707
return0;
708708
}
709709

@@ -727,7 +727,7 @@ connectNoDelay(PGconn *conn)
727727
{
728728
printfPQExpBuffer(&conn->errorMessage,
729729
libpq_gettext("could not set socket to TCP no delay mode: %s\n"),
730-
strerror(errno));
730+
SOCK_STRERROR(SOCK_ERRNO));
731731
return0;
732732
}
733733

@@ -750,7 +750,7 @@ connectFailureMessage(PGconn *conn, int errorno)
750750
"\tIs the server running locally and accepting\n"
751751
"\tconnections on Unix domain socket \"%s\"?\n"
752752
),
753-
strerror(errorno),
753+
SOCK_STRERROR(errorno),
754754
conn->raddr.un.sun_path);
755755
else
756756
printfPQExpBuffer(&conn->errorMessage,
@@ -759,7 +759,7 @@ connectFailureMessage(PGconn *conn, int errorno)
759759
"\tIs the server running on host %s and accepting\n"
760760
"\tTCP/IP connections on port %s?\n"
761761
),
762-
strerror(errorno),
762+
SOCK_STRERROR(errorno),
763763
conn->pghost
764764
?conn->pghost
765765
: (conn->pghostaddr
@@ -882,7 +882,7 @@ connectDBStart(PGconn *conn)
882882
{
883883
printfPQExpBuffer(&conn->errorMessage,
884884
libpq_gettext("could not create socket: %s\n"),
885-
strerror(errno));
885+
SOCK_STRERROR(SOCK_ERRNO));
886886
gotoconnect_errReturn;
887887
}
888888

@@ -914,7 +914,7 @@ connectDBStart(PGconn *conn)
914914
*/
915915
if (connect(conn->sock,&conn->raddr.sa,conn->raddr_len)<0)
916916
{
917-
if (errno==EINPROGRESS||errno==EWOULDBLOCK||errno==0)
917+
if (SOCK_ERRNO==EINPROGRESS||SOCK_ERRNO==EWOULDBLOCK||SOCK_ERRNO==0)
918918
{
919919
/*
920920
* This is fine - we're in non-blocking mode, and the
@@ -925,7 +925,7 @@ connectDBStart(PGconn *conn)
925925
else
926926
{
927927
/* Something's gone wrong */
928-
connectFailureMessage(conn,errno);
928+
connectFailureMessage(conn,SOCK_ERRNO);
929929
gotoconnect_errReturn;
930930
}
931931
}
@@ -945,15 +945,15 @@ connectDBStart(PGconn *conn)
945945
{
946946
printfPQExpBuffer(&conn->errorMessage,
947947
libpq_gettext("could not send SSL negotiation packet: %s\n"),
948-
strerror(errno));
948+
SOCK_STRERROR(SOCK_ERRNO));
949949
gotoconnect_errReturn;
950950
}
951951
/* Now receive the postmasters response */
952952
if (recv(conn->sock,&SSLok,1,0)!=1)
953953
{
954954
printfPQExpBuffer(&conn->errorMessage,
955955
libpq_gettext("could not receive server response to SSL negotiation packet: %s\n"),
956-
strerror(errno));
956+
SOCK_STRERROR(SOCK_ERRNO));
957957
gotoconnect_errReturn;
958958
}
959959
if (SSLok=='S')
@@ -1203,7 +1203,7 @@ PQconnectPoll(PGconn *conn)
12031203
{
12041204
printfPQExpBuffer(&conn->errorMessage,
12051205
libpq_gettext("could not get socket error status: %s\n"),
1206-
strerror(errno));
1206+
SOCK_STRERROR(SOCK_ERRNO));
12071207
gotoerror_return;
12081208
}
12091209
elseif (optval!=0)
@@ -1223,7 +1223,7 @@ PQconnectPoll(PGconn *conn)
12231223
{
12241224
printfPQExpBuffer(&conn->errorMessage,
12251225
libpq_gettext("could not get client address from socket: %s\n"),
1226-
strerror(errno));
1226+
SOCK_STRERROR(SOCK_ERRNO));
12271227
gotoerror_return;
12281228
}
12291229

@@ -1262,7 +1262,7 @@ PQconnectPoll(PGconn *conn)
12621262
{
12631263
printfPQExpBuffer(&conn->errorMessage,
12641264
libpq_gettext("could not send startup packet: %s\n"),
1265-
strerror(errno));
1265+
SOCK_STRERROR(SOCK_ERRNO));
12661266
gotoerror_return;
12671267
}
12681268

@@ -2097,7 +2097,7 @@ PQresetPoll(PGconn *conn)
20972097
int
20982098
PQrequestCancel(PGconn*conn)
20992099
{
2100-
intsave_errno=errno;
2100+
intsave_errno=SOCK_ERRNO;
21012101
inttmpsock=-1;
21022102
struct
21032103
{
@@ -2169,7 +2169,7 @@ PQrequestCancel(PGconn *conn)
21692169
return TRUE;
21702170

21712171
cancel_errReturn:
2172-
strcat(conn->errorMessage.data,strerror(errno));
2172+
strcat(conn->errorMessage.data,SOCK_STRERROR(SOCK_ERRNO));
21732173
strcat(conn->errorMessage.data,"\n");
21742174
conn->errorMessage.len=strlen(conn->errorMessage.data);
21752175
if (tmpsock >=0)

‎src/interfaces/libpq/fe-exec.c

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-exec.c,v 1.107 2001/08/17 15:11:15 momjian Exp $
11+
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-exec.c,v 1.108 2001/08/21 20:39:53 momjian Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -2038,10 +2038,6 @@ PQoidStatus(const PGresult *res)
20382038
returnbuf;
20392039
}
20402040

2041-
#ifdefWIN32/* need to get at normal errno here */
2042-
#undef errno
2043-
#endif
2044-
20452041
/*
20462042
PQoidValue -
20472043
a perhaps preferable form of the above which just returns
@@ -2056,7 +2052,11 @@ PQoidValue(const PGresult *res)
20562052
if (!res|| !res->cmdStatus||strncmp(res->cmdStatus,"INSERT ",7)!=0)
20572053
returnInvalidOid;
20582054

2055+
#ifdefWIN32
2056+
SetLastError(0);
2057+
#else
20592058
errno=0;
2059+
#endif
20602060
result=strtoul(res->cmdStatus+7,&endptr,10);
20612061

20622062
if (!endptr|| (*endptr!=' '&&*endptr!='\0')||errno==ERANGE)
@@ -2065,9 +2065,6 @@ PQoidValue(const PGresult *res)
20652065
return (Oid)result;
20662066
}
20672067

2068-
#ifdefWIN32/* back to socket errno */
2069-
#defineerrno WSAGetLastError()
2070-
#endif
20712068

20722069
/*
20732070
PQcmdTuples -

‎src/interfaces/libpq/fe-lobj.c

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-lobj.c,v 1.37 2001/08/17 15:11:15 momjian Exp $
11+
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-lobj.c,v 1.38 2001/08/21 20:39:54 momjian Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -30,12 +30,6 @@
3030

3131
#include"libpq/libpq-fs.h"/* must come after sys/stat.h */
3232

33-
34-
#ifdefWIN32/* need to use normal errno in this file */
35-
#undef errno
36-
#endif
37-
38-
3933
#defineLO_BUFSIZE 8192
4034

4135
staticintlo_initialize(PGconn*conn);

‎src/interfaces/libpq/fe-misc.c

Lines changed: 43 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
*
2626
*
2727
* IDENTIFICATION
28-
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-misc.c,v 1.53 2001/08/17 15:11:15 momjian Exp $
28+
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-misc.c,v 1.54 2001/08/21 20:39:54 momjian Exp $
2929
*
3030
*-------------------------------------------------------------------------
3131
*/
@@ -347,13 +347,13 @@ pqReadReady(PGconn *conn)
347347
if (select(conn->sock+1,&input_mask, (fd_set*)NULL, (fd_set*)NULL,
348348
&timeout)<0)
349349
{
350-
if (errno==EINTR)
350+
if (SOCK_ERRNO==EINTR)
351351
/* Interrupted system call - we'll just try again */
352352
gotoretry;
353353

354354
printfPQExpBuffer(&conn->errorMessage,
355355
libpq_gettext("select() failed: %s\n"),
356-
strerror(errno));
356+
SOCK_STRERROR(SOCK_ERRNO));
357357
return-1;
358358
}
359359

@@ -381,13 +381,13 @@ pqWriteReady(PGconn *conn)
381381
if (select(conn->sock+1, (fd_set*)NULL,&input_mask, (fd_set*)NULL,
382382
&timeout)<0)
383383
{
384-
if (errno==EINTR)
384+
if (SOCK_ERRNO==EINTR)
385385
/* Interrupted system call - we'll just try again */
386386
gotoretry;
387387

388388
printfPQExpBuffer(&conn->errorMessage,
389389
libpq_gettext("select() failed: %s\n"),
390-
strerror(errno));
390+
SOCK_STRERROR(SOCK_ERRNO));
391391
return-1;
392392
}
393393
returnFD_ISSET(conn->sock,&input_mask) ?1 :0;
@@ -467,25 +467,25 @@ pqReadData(PGconn *conn)
467467
conn->inBufSize-conn->inEnd,0);
468468
if (nread<0)
469469
{
470-
if (errno==EINTR)
470+
if (SOCK_ERRNO==EINTR)
471471
gototryAgain;
472472
/* Some systems return EAGAIN/EWOULDBLOCK for no data */
473473
#ifdefEAGAIN
474-
if (errno==EAGAIN)
474+
if (SOCK_ERRNO==EAGAIN)
475475
returnsomeread;
476476
#endif
477477
#if defined(EWOULDBLOCK)&& (!defined(EAGAIN)|| (EWOULDBLOCK!=EAGAIN))
478-
if (errno==EWOULDBLOCK)
478+
if (SOCK_ERRNO==EWOULDBLOCK)
479479
returnsomeread;
480480
#endif
481481
/* We might get ECONNRESET here if using TCP and backend died */
482482
#ifdefECONNRESET
483-
if (errno==ECONNRESET)
483+
if (SOCK_ERRNO==ECONNRESET)
484484
gotodefinitelyFailed;
485485
#endif
486486
printfPQExpBuffer(&conn->errorMessage,
487487
libpq_gettext("could not receive data from server: %s\n"),
488-
strerror(errno));
488+
SOCK_STRERROR(SOCK_ERRNO));
489489
return-1;
490490
}
491491
if (nread>0)
@@ -553,25 +553,25 @@ pqReadData(PGconn *conn)
553553
conn->inBufSize-conn->inEnd,0);
554554
if (nread<0)
555555
{
556-
if (errno==EINTR)
556+
if (SOCK_ERRNO==EINTR)
557557
gototryAgain2;
558558
/* Some systems return EAGAIN/EWOULDBLOCK for no data */
559559
#ifdefEAGAIN
560-
if (errno==EAGAIN)
560+
if (SOCK_ERRNO==EAGAIN)
561561
return0;
562562
#endif
563563
#if defined(EWOULDBLOCK)&& (!defined(EAGAIN)|| (EWOULDBLOCK!=EAGAIN))
564-
if (errno==EWOULDBLOCK)
564+
if (SOCK_ERRNO==EWOULDBLOCK)
565565
return0;
566566
#endif
567567
/* We might get ECONNRESET here if using TCP and backend died */
568568
#ifdefECONNRESET
569-
if (errno==ECONNRESET)
569+
if (SOCK_ERRNO==ECONNRESET)
570570
gotodefinitelyFailed;
571571
#endif
572572
printfPQExpBuffer(&conn->errorMessage,
573573
libpq_gettext("could not receive data from server: %s\n"),
574-
strerror(errno));
574+
SOCK_STRERROR(SOCK_ERRNO));
575575
return-1;
576576
}
577577
if (nread>0)
@@ -653,7 +653,7 @@ pqFlush(PGconn *conn)
653653
* EPIPE or ECONNRESET, assume we've lost the backend
654654
* connection permanently.
655655
*/
656-
switch (errno)
656+
switch (SOCK_ERRNO)
657657
{
658658
#ifdefEAGAIN
659659
caseEAGAIN:
@@ -689,7 +689,7 @@ pqFlush(PGconn *conn)
689689
default:
690690
printfPQExpBuffer(&conn->errorMessage,
691691
libpq_gettext("could not send data to server: %s\n"),
692-
strerror(errno));
692+
SOCK_STRERROR(SOCK_ERRNO));
693693
/* We don't assume it's a fatal error... */
694694
returnEOF;
695695
}
@@ -772,11 +772,11 @@ pqWait(int forRead, int forWrite, PGconn *conn)
772772
if (select(conn->sock+1,&input_mask,&output_mask,&except_mask,
773773
(structtimeval*)NULL)<0)
774774
{
775-
if (errno==EINTR)
775+
if (SOCK_ERRNO==EINTR)
776776
gotoretry;
777777
printfPQExpBuffer(&conn->errorMessage,
778778
libpq_gettext("select() failed: %s\n"),
779-
strerror(errno));
779+
SOCK_STRERROR(SOCK_ERRNO));
780780
returnEOF;
781781
}
782782
}
@@ -851,3 +851,27 @@ libpq_gettext(const char *msgid)
851851
returndgettext("libpq",msgid);
852852
}
853853
#endif/* ENABLE_NLS */
854+
855+
#ifdefWIN32
856+
/*
857+
* strerror replacement for windows:
858+
*/
859+
constchar*
860+
winsock_strerror(DWORDeno)
861+
{
862+
if (!FormatMessage(
863+
FORMAT_MESSAGE_IGNORE_INSERTS |
864+
FORMAT_MESSAGE_FROM_SYSTEM |/* always consider system table */
865+
((netmsgModule!=NULL) ?FORMAT_MESSAGE_FROM_HMODULE :0),
866+
netmsgModule,/* module to get message from (NULL == system) */
867+
eno,
868+
MAKELANGID(LANG_NEUTRAL,SUBLANG_DEFAULT),
869+
winsock_strerror_buf,sizeof(winsock_strerror_buf)-1,
870+
NULL
871+
)){
872+
sprintf(winsock_strerror_buf,"Unknown socket error(%u)",eno);
873+
}
874+
winsock_strerror_buf[sizeof(winsock_strerror_buf)-1]='\0';
875+
returnwinsock_strerror_buf;
876+
}
877+
#endif

‎src/interfaces/libpq/libpq-fe.h

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* $Id: libpq-fe.h,v 1.71 2001/03/22 04:01:27 momjian Exp $
10+
* $Id: libpq-fe.h,v 1.72 2001/08/21 20:39:54 momjian Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -21,10 +21,21 @@ extern"C"
2121
#endif
2222

2323
#include<stdio.h>
24+
25+
#ifdefWIN32
26+
#defineSOCK_ERRNO (WSAGetLastError ())
27+
#defineSOCK_STRERROR winsock_strerror
28+
#else
29+
#defineSOCK_ERRNO errno
30+
#defineSOCK_STRERROR strerror
31+
#endif
32+
33+
2434
/* postgres_ext.h defines the backend's externally visible types,
2535
* such as Oid.
2636
*/
2737
#include"postgres_ext.h"
38+
2839
#ifdefUSE_SSL
2940
#include<openssl/ssl.h>
3041
#endif

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp