WIN32 Non Blocking

Started by Darko Prenosilabout 25 years ago15 messagesbugspatches
Jump to latest
#1Darko Prenosil
darko_prenosil@yahoo.com
bugs

Hi ,Bruce !
There is diff for fe-connect.c.
Diff was made with options -cr as You asked.
I must say that this is the first time I ever use diff, so I do not know if
if it is ok.

I did not check if all of non-blocking functions are working,
but I checked PQsetnonblocking,PQisnonblocking,
PQsendQuery, PQgetResult and few others.
I think that

*** ./fe-connect.c Tue Jun 12 20:03:04 2001
--- ./fe-connect1.c Fri Jun 29 05:25:18 2001
***************
*** 189,195 ****
  static void defaultNoticeProcessor(void *arg, const char *message);
  static int parseServiceInfo(PQconninfoOption *options,
       PQExpBuffer errorMessage);
!
  /* ----------------
   *  Connecting to a Database
--- 189,195 ----
  static void defaultNoticeProcessor(void *arg, const char *message);
  static int parseServiceInfo(PQconninfoOption *options,
       PQExpBuffer errorMessage);
! static char FLastError[200];

/* ----------------
* Connecting to a Database
***************
*** 240,249 ****
PQconnectdb(const char *conninfo)
{
PGconn *conn = PQconnectStart(conninfo);
-
if (conn && conn->status != CONNECTION_BAD)
(void) connectDBComplete(conn);
-
return conn;
}

--- 240,247 ----
***************
*** 291,296 ****
--- 289,295 ----
   {
    conn->status = CONNECTION_BAD;
    /* errorMessage is already set */
+   sprintf( FLastError, "PQconnectStart-Invalid Connection Info");
    return conn;
   }

***************
*** 516,523 ****
conn->require_ssl = 0;
#endif

!  if (error)
    conn->status = CONNECTION_BAD;
   else
   {
    if (connectDBStart(conn))
--- 515,524 ----
    conn->require_ssl = 0;
  #endif
!  if (error){
    conn->status = CONNECTION_BAD;
+   sprintf( FLastError, "Failed to set DBLogin");
+  }
   else
   {
    if (connectDBStart(conn))
***************
*** 709,717 ****
   if   (fcntl(conn->sock, F_SETFL, O_NONBLOCK) < 0)
  #endif
   {
    printfPQExpBuffer(&conn->errorMessage,
!      "connectMakeNonblocking -- fcntl() failed: errno=%d\n%s\n",
!         errno, strerror(errno));
    return 0;
   }
--- 710,724 ----
   if   (fcntl(conn->sock, F_SETFL, O_NONBLOCK) < 0)
  #endif
   {
+  #ifdef WIN32
+   sprintf( FLastError, "connectMakeNonblocking -- fcntl() failed:
errno=%d\n%s\n",
+   WSAGetLastError());
+  #else
    printfPQExpBuffer(&conn->errorMessage,
!      "connectMakeNonblocking -- fcntl() failed: errno=%d\n%s\n",
!      errno, strerror(errno));
!  #endif
!
    return 0;
   }
***************
*** 788,794 ****
  {
   int   portno,
      family;
-
  #ifdef USE_SSL
   StartupPacket np;   /* Used to negotiate SSL connection */
   char  SSLok;
--- 795,800 ----
***************
*** 932,943 ****
    * Thus, we have make arrangements for all eventualities.
    * ----------
    */
   if (connect(conn->sock, &conn->raddr.sa, conn->raddr_len) < 0)
   {
- #ifndef WIN32
    if (errno == EINPROGRESS || errno == 0)
  #else
!   if (WSAGetLastError() == WSAEINPROGRESS)
  #endif
    {
--- 938,952 ----
    * Thus, we have make arrangements for all eventualities.
    * ----------
    */
+
+ #ifndef WIN32
   if (connect(conn->sock, &conn->raddr.sa, conn->raddr_len) < 0)
   {
    if (errno == EINPROGRESS || errno == 0)
  #else
!  if (connect(conn->sock, &conn->raddr.sa, conn->raddr_len) != 0)
!  {
!   if (WSAGetLastError() == WSAEINPROGRESS || WSAGetLastError() ==
WSAEWOULDBLOCK)
  #endif
    {
***************
*** 1056,1061 ****
--- 1065,1071 ----
   conn->status = CONNECTION_BAD;

return 0;
+
}

***************
*** 1095,1100 ****
--- 1105,1111 ----
      if (pqWait(1, 0, conn))
      {
       conn->status = CONNECTION_BAD;
+      sprintf(FLastError,conn->errorMessage.data);
       return 0;
      }
      break;
***************
*** 1103,1108 ****
--- 1114,1120 ----
      if (pqWait(0, 1, conn))
      {
       conn->status = CONNECTION_BAD;
+      sprintf(FLastError,conn->errorMessage.data);
       return 0;
      }
      break;
***************
*** 1110,1115 ****
--- 1122,1128 ----
     default:
      /* Just in case we failed to set it in PQconnectPoll */
      conn->status = CONNECTION_BAD;
+     sprintf(FLastError,conn->errorMessage.data);
      return 0;
    }

***************
*** 1208,1222 ****
{
ACCEPT_TYPE_ARG3 laddrlen;

- #ifndef WIN32
-     int   optval;
-
- #else
-     char  optval;
-
- #endif
-     ACCEPT_TYPE_ARG3 optlen = sizeof(optval);
-
      /*
       * Write ready, since we've made it here, so the
       * connection has been made.
--- 1221,1226 ----
***************
*** 1226,1235 ****
       * Now check (using getsockopt) that there is not an error
       * state waiting for us on the socket.
       */
      if (getsockopt(conn->sock, SOL_SOCKET, SO_ERROR,
!           (char *) &optval, &optlen) == -1)
!     {
       printfPQExpBuffer(&conn->errorMessage,
            "PQconnectPoll() -- getsockopt() failed: "
             "errno=%d\n%s\n",
--- 1230,1241 ----
       * Now check (using getsockopt) that there is not an error
       * state waiting for us on the socket.
       */
+ #ifndef WIN32
+     int   optval;
+     ACCEPT_TYPE_ARG3 optlen = sizeof(optval);
      if (getsockopt(conn->sock, SOL_SOCKET, SO_ERROR,
!           (char *) &optval, &optlen) == -1){
       printfPQExpBuffer(&conn->errorMessage,
            "PQconnectPoll() -- getsockopt() failed: "
             "errno=%d\n%s\n",
***************
*** 1247,1252 ****
--- 1253,1272 ----
       connectFailureMessage(conn, "PQconnectPoll()", optval);
       goto error_return;
      }
+ #else
+     char far  optval[8];
+     ACCEPT_TYPE_ARG3 optlen = sizeof(optval);
+
+     int OptResult=getsockopt(conn->sock, SOL_SOCKET, SO_ERROR,optval,
&optlen);
+     if (OptResult==SOCKET_ERROR){
+      printfPQExpBuffer(&conn->errorMessage,
+           "PQconnectPoll() -- getsockopt() failed: "
+            "errno=%i\n",
+            WSAGetLastError());
+      connectFailureMessage(conn, "PQconnectPoll()", OptResult);
+      goto error_return;
+     }
+ #endif
      /* Fill in the client address */
      laddrlen = sizeof(conn->laddr);
***************
*** 1929,1934 ****
--- 1949,1955 ----
  #endif
   if (conn->sock >= 0)
  #ifdef WIN32
+   //WSACleanup();
    closesocket(conn->sock);
  #else
    close(conn->sock);
***************
*** 2699,2706 ****
  char *
  PQerrorMessage(const PGconn *conn)
  {
   if (!conn)
!   return "PQerrorMessage: conn pointer is NULL\n";
   return conn->errorMessage.data;
  }
--- 2720,2732 ----
  char *
  PQerrorMessage(const PGconn *conn)
  {
+  //char  ErrBuffer[200];
   if (!conn)
!   #ifdef WIN32
!    return FLastError;
!   #else
!    return "PQerrorMessage: conn pointer is NULL\n";
!   #endif

return conn->errorMessage.data;
}

#2Denis A. Doroshenko
d.doroshenko@omnitel.net
In reply to: Darko Prenosil (#1)
bugs
Re: WIN32 Non Blocking

Ugh... statically alocated buffer and sprintf()s with data of variable
length; usage of data as format string... hell, i'm happy this is code
for win32, although it scares me greatly. will it go as it is to PGSQL?
:-0

On Tue, Jul 17, 2001 at 12:12:48AM +0200, Darko Prenosil wrote:

Hi ,Bruce !
There is diff for fe-connect.c.
Diff was made with options -cr as You asked.
I must say that this is the first time I ever use diff, so I do not know if
if it is ok.

I did not check if all of non-blocking functions are working,
but I checked PQsetnonblocking,PQisnonblocking,
PQsendQuery, PQgetResult and few others.
I think that

*** ./fe-connect.c Tue Jun 12 20:03:04 2001
--- ./fe-connect1.c Fri Jun 29 05:25:18 2001
***************
*** 189,195 ****
static void defaultNoticeProcessor(void *arg, const char *message);
static int parseServiceInfo(PQconninfoOption *options,
PQExpBuffer errorMessage);
!
/* ----------------
*  Connecting to a Database
--- 189,195 ----
static void defaultNoticeProcessor(void *arg, const char *message);
static int parseServiceInfo(PQconninfoOption *options,
PQExpBuffer errorMessage);
! static char FLastError[200];

/* ----------------
* Connecting to a Database
***************
*** 240,249 ****
PQconnectdb(const char *conninfo)
{
PGconn *conn = PQconnectStart(conninfo);
-
if (conn && conn->status != CONNECTION_BAD)
(void) connectDBComplete(conn);
-
return conn;
}

--- 240,247 ----
***************
*** 291,296 ****
--- 289,295 ----
{
conn->status = CONNECTION_BAD;
/* errorMessage is already set */
+   sprintf( FLastError, "PQconnectStart-Invalid Connection Info");
return conn;
}

***************
*** 516,523 ****
conn->require_ssl = 0;
#endif

!  if (error)
conn->status = CONNECTION_BAD;
else
{
if (connectDBStart(conn))
--- 515,524 ----
conn->require_ssl = 0;
#endif
!  if (error){
conn->status = CONNECTION_BAD;
+   sprintf( FLastError, "Failed to set DBLogin");
+  }
else
{
if (connectDBStart(conn))
***************
*** 709,717 ****
if   (fcntl(conn->sock, F_SETFL, O_NONBLOCK) < 0)
#endif
{
printfPQExpBuffer(&conn->errorMessage,
!      "connectMakeNonblocking -- fcntl() failed: errno=%d\n%s\n",
!         errno, strerror(errno));
return 0;
}
--- 710,724 ----
if   (fcntl(conn->sock, F_SETFL, O_NONBLOCK) < 0)
#endif
{
+  #ifdef WIN32
+   sprintf( FLastError, "connectMakeNonblocking -- fcntl() failed:
errno=%d\n%s\n",
+   WSAGetLastError());
+  #else
printfPQExpBuffer(&conn->errorMessage,
!      "connectMakeNonblocking -- fcntl() failed: errno=%d\n%s\n",
!      errno, strerror(errno));
!  #endif
!
return 0;
}
***************
*** 788,794 ****
{
int   portno,
family;
-
#ifdef USE_SSL
StartupPacket np;   /* Used to negotiate SSL connection */
char  SSLok;
--- 795,800 ----
***************
*** 932,943 ****
* Thus, we have make arrangements for all eventualities.
* ----------
*/
if (connect(conn->sock, &conn->raddr.sa, conn->raddr_len) < 0)
{
- #ifndef WIN32
if (errno == EINPROGRESS || errno == 0)
#else
!   if (WSAGetLastError() == WSAEINPROGRESS)
#endif
{
--- 938,952 ----
* Thus, we have make arrangements for all eventualities.
* ----------
*/
+
+ #ifndef WIN32
if (connect(conn->sock, &conn->raddr.sa, conn->raddr_len) < 0)
{
if (errno == EINPROGRESS || errno == 0)
#else
!  if (connect(conn->sock, &conn->raddr.sa, conn->raddr_len) != 0)
!  {
!   if (WSAGetLastError() == WSAEINPROGRESS || WSAGetLastError() ==
WSAEWOULDBLOCK)
#endif
{
***************
*** 1056,1061 ****
--- 1065,1071 ----
conn->status = CONNECTION_BAD;

return 0;
+
}

***************
*** 1095,1100 ****
--- 1105,1111 ----
if (pqWait(1, 0, conn))
{
conn->status = CONNECTION_BAD;
+      sprintf(FLastError,conn->errorMessage.data);
return 0;
}
break;
***************
*** 1103,1108 ****
--- 1114,1120 ----
if (pqWait(0, 1, conn))
{
conn->status = CONNECTION_BAD;
+      sprintf(FLastError,conn->errorMessage.data);
return 0;
}
break;
***************
*** 1110,1115 ****
--- 1122,1128 ----
default:
/* Just in case we failed to set it in PQconnectPoll */
conn->status = CONNECTION_BAD;
+     sprintf(FLastError,conn->errorMessage.data);
return 0;
}

***************
*** 1208,1222 ****
{
ACCEPT_TYPE_ARG3 laddrlen;

- #ifndef WIN32
-     int   optval;
-
- #else
-     char  optval;
-
- #endif
-     ACCEPT_TYPE_ARG3 optlen = sizeof(optval);
-
/*
* Write ready, since we've made it here, so the
* connection has been made.
--- 1221,1226 ----
***************
*** 1226,1235 ****
* Now check (using getsockopt) that there is not an error
* state waiting for us on the socket.
*/
if (getsockopt(conn->sock, SOL_SOCKET, SO_ERROR,
!           (char *) &optval, &optlen) == -1)
!     {
printfPQExpBuffer(&conn->errorMessage,
"PQconnectPoll() -- getsockopt() failed: "
"errno=%d\n%s\n",
--- 1230,1241 ----
* Now check (using getsockopt) that there is not an error
* state waiting for us on the socket.
*/
+ #ifndef WIN32
+     int   optval;
+     ACCEPT_TYPE_ARG3 optlen = sizeof(optval);
if (getsockopt(conn->sock, SOL_SOCKET, SO_ERROR,
!           (char *) &optval, &optlen) == -1){
printfPQExpBuffer(&conn->errorMessage,
"PQconnectPoll() -- getsockopt() failed: "
"errno=%d\n%s\n",
***************
*** 1247,1252 ****
--- 1253,1272 ----
connectFailureMessage(conn, "PQconnectPoll()", optval);
goto error_return;
}
+ #else
+     char far  optval[8];
+     ACCEPT_TYPE_ARG3 optlen = sizeof(optval);
+
+     int OptResult=getsockopt(conn->sock, SOL_SOCKET, SO_ERROR,optval,
&optlen);
+     if (OptResult==SOCKET_ERROR){
+      printfPQExpBuffer(&conn->errorMessage,
+           "PQconnectPoll() -- getsockopt() failed: "
+            "errno=%i\n",
+            WSAGetLastError());
+      connectFailureMessage(conn, "PQconnectPoll()", OptResult);
+      goto error_return;
+     }
+ #endif
/* Fill in the client address */
laddrlen = sizeof(conn->laddr);
***************
*** 1929,1934 ****
--- 1949,1955 ----
#endif
if (conn->sock >= 0)
#ifdef WIN32
+   //WSACleanup();
closesocket(conn->sock);
#else
close(conn->sock);
***************
*** 2699,2706 ****
char *
PQerrorMessage(const PGconn *conn)
{
if (!conn)
!   return "PQerrorMessage: conn pointer is NULL\n";
return conn->errorMessage.data;
}
--- 2720,2732 ----
char *
PQerrorMessage(const PGconn *conn)
{
+  //char  ErrBuffer[200];
if (!conn)
!   #ifdef WIN32
!    return FLastError;
!   #else
!    return "PQerrorMessage: conn pointer is NULL\n";
!   #endif

return conn->errorMessage.data;
}

---------------------------(end of broadcast)---------------------------
TIP 3: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to majordomo@postgresql.org so that your
message can get through to the mailing list cleanly

--
Denis A. Doroshenko [GPRS engineer] .-. _|_ |
[Omnitel Ltd., T.Sevcenkos st. 25, Vilnius, Lithuania] | | _ _ _ .| _ |
[Phone: +370 9863486 E-mail: d.doroshenko@omnitel.net] |_|| | || |||(/_|_

#3Bruce Momjian
bruce@momjian.us
In reply to: Darko Prenosil (#1)
bugs
Re: WIN32 Non Blocking

I just got a new Win32 libpq patch. Please see it at:

http://candle.pha.pa.us/cgi-bin/pgpatches

How does your match with that one? I haven't applied it yet.

Hi ,Bruce !
There is diff for fe-connect.c.
Diff was made with options -cr as You asked.
I must say that this is the first time I ever use diff, so I do not know if
if it is ok.

I did not check if all of non-blocking functions are working,
but I checked PQsetnonblocking,PQisnonblocking,
PQsendQuery, PQgetResult and few others.
I think that

*** ./fe-connect.c Tue Jun 12 20:03:04 2001
--- ./fe-connect1.c Fri Jun 29 05:25:18 2001
***************
*** 189,195 ****
static void defaultNoticeProcessor(void *arg, const char *message);
static int parseServiceInfo(PQconninfoOption *options,
PQExpBuffer errorMessage);
!
/* ----------------
*  Connecting to a Database
--- 189,195 ----
static void defaultNoticeProcessor(void *arg, const char *message);
static int parseServiceInfo(PQconninfoOption *options,
PQExpBuffer errorMessage);
! static char FLastError[200];

/* ----------------
* Connecting to a Database
***************
*** 240,249 ****
PQconnectdb(const char *conninfo)
{
PGconn *conn = PQconnectStart(conninfo);
-
if (conn && conn->status != CONNECTION_BAD)
(void) connectDBComplete(conn);
-
return conn;
}

--- 240,247 ----
***************
*** 291,296 ****
--- 289,295 ----
{
conn->status = CONNECTION_BAD;
/* errorMessage is already set */
+   sprintf( FLastError, "PQconnectStart-Invalid Connection Info");
return conn;
}

***************
*** 516,523 ****
conn->require_ssl = 0;
#endif

!  if (error)
conn->status = CONNECTION_BAD;
else
{
if (connectDBStart(conn))
--- 515,524 ----
conn->require_ssl = 0;
#endif
!  if (error){
conn->status = CONNECTION_BAD;
+   sprintf( FLastError, "Failed to set DBLogin");
+  }
else
{
if (connectDBStart(conn))
***************
*** 709,717 ****
if   (fcntl(conn->sock, F_SETFL, O_NONBLOCK) < 0)
#endif
{
printfPQExpBuffer(&conn->errorMessage,
!      "connectMakeNonblocking -- fcntl() failed: errno=%d\n%s\n",
!         errno, strerror(errno));
return 0;
}
--- 710,724 ----
if   (fcntl(conn->sock, F_SETFL, O_NONBLOCK) < 0)
#endif
{
+  #ifdef WIN32
+   sprintf( FLastError, "connectMakeNonblocking -- fcntl() failed:
errno=%d\n%s\n",
+   WSAGetLastError());
+  #else
printfPQExpBuffer(&conn->errorMessage,
!      "connectMakeNonblocking -- fcntl() failed: errno=%d\n%s\n",
!      errno, strerror(errno));
!  #endif
!
return 0;
}
***************
*** 788,794 ****
{
int   portno,
family;
-
#ifdef USE_SSL
StartupPacket np;   /* Used to negotiate SSL connection */
char  SSLok;
--- 795,800 ----
***************
*** 932,943 ****
* Thus, we have make arrangements for all eventualities.
* ----------
*/
if (connect(conn->sock, &conn->raddr.sa, conn->raddr_len) < 0)
{
- #ifndef WIN32
if (errno == EINPROGRESS || errno == 0)
#else
!   if (WSAGetLastError() == WSAEINPROGRESS)
#endif
{
--- 938,952 ----
* Thus, we have make arrangements for all eventualities.
* ----------
*/
+
+ #ifndef WIN32
if (connect(conn->sock, &conn->raddr.sa, conn->raddr_len) < 0)
{
if (errno == EINPROGRESS || errno == 0)
#else
!  if (connect(conn->sock, &conn->raddr.sa, conn->raddr_len) != 0)
!  {
!   if (WSAGetLastError() == WSAEINPROGRESS || WSAGetLastError() ==
WSAEWOULDBLOCK)
#endif
{
***************
*** 1056,1061 ****
--- 1065,1071 ----
conn->status = CONNECTION_BAD;

return 0;
+
}

***************
*** 1095,1100 ****
--- 1105,1111 ----
if (pqWait(1, 0, conn))
{
conn->status = CONNECTION_BAD;
+      sprintf(FLastError,conn->errorMessage.data);
return 0;
}
break;
***************
*** 1103,1108 ****
--- 1114,1120 ----
if (pqWait(0, 1, conn))
{
conn->status = CONNECTION_BAD;
+      sprintf(FLastError,conn->errorMessage.data);
return 0;
}
break;
***************
*** 1110,1115 ****
--- 1122,1128 ----
default:
/* Just in case we failed to set it in PQconnectPoll */
conn->status = CONNECTION_BAD;
+     sprintf(FLastError,conn->errorMessage.data);
return 0;
}

***************
*** 1208,1222 ****
{
ACCEPT_TYPE_ARG3 laddrlen;

- #ifndef WIN32
-     int   optval;
-
- #else
-     char  optval;
-
- #endif
-     ACCEPT_TYPE_ARG3 optlen = sizeof(optval);
-
/*
* Write ready, since we've made it here, so the
* connection has been made.
--- 1221,1226 ----
***************
*** 1226,1235 ****
* Now check (using getsockopt) that there is not an error
* state waiting for us on the socket.
*/
if (getsockopt(conn->sock, SOL_SOCKET, SO_ERROR,
!           (char *) &optval, &optlen) == -1)
!     {
printfPQExpBuffer(&conn->errorMessage,
"PQconnectPoll() -- getsockopt() failed: "
"errno=%d\n%s\n",
--- 1230,1241 ----
* Now check (using getsockopt) that there is not an error
* state waiting for us on the socket.
*/
+ #ifndef WIN32
+     int   optval;
+     ACCEPT_TYPE_ARG3 optlen = sizeof(optval);
if (getsockopt(conn->sock, SOL_SOCKET, SO_ERROR,
!           (char *) &optval, &optlen) == -1){
printfPQExpBuffer(&conn->errorMessage,
"PQconnectPoll() -- getsockopt() failed: "
"errno=%d\n%s\n",
***************
*** 1247,1252 ****
--- 1253,1272 ----
connectFailureMessage(conn, "PQconnectPoll()", optval);
goto error_return;
}
+ #else
+     char far  optval[8];
+     ACCEPT_TYPE_ARG3 optlen = sizeof(optval);
+
+     int OptResult=getsockopt(conn->sock, SOL_SOCKET, SO_ERROR,optval,
&optlen);
+     if (OptResult==SOCKET_ERROR){
+      printfPQExpBuffer(&conn->errorMessage,
+           "PQconnectPoll() -- getsockopt() failed: "
+            "errno=%i\n",
+            WSAGetLastError());
+      connectFailureMessage(conn, "PQconnectPoll()", OptResult);
+      goto error_return;
+     }
+ #endif
/* Fill in the client address */
laddrlen = sizeof(conn->laddr);
***************
*** 1929,1934 ****
--- 1949,1955 ----
#endif
if (conn->sock >= 0)
#ifdef WIN32
+   //WSACleanup();
closesocket(conn->sock);
#else
close(conn->sock);
***************
*** 2699,2706 ****
char *
PQerrorMessage(const PGconn *conn)
{
if (!conn)
!   return "PQerrorMessage: conn pointer is NULL\n";
return conn->errorMessage.data;
}
--- 2720,2732 ----
char *
PQerrorMessage(const PGconn *conn)
{
+  //char  ErrBuffer[200];
if (!conn)
!   #ifdef WIN32
!    return FLastError;
!   #else
!    return "PQerrorMessage: conn pointer is NULL\n";
!   #endif

return conn->errorMessage.data;
}

---------------------------(end of broadcast)---------------------------
TIP 3: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to majordomo@postgresql.org so that your
message can get through to the mailing list cleanly

-- 
  Bruce Momjian                        |  http://candle.pha.pa.us
  pgman@candle.pha.pa.us               |  (610) 853-3000
  +  If your life is a hard drive,     |  830 Blythe Avenue
  +  Christ can be your backup.        |  Drexel Hill, Pennsylvania 19026
#4Bruce Momjian
bruce@momjian.us
In reply to: Denis A. Doroshenko (#2)
bugs
Re: WIN32 Non Blocking

Ugh... statically alocated buffer and sprintf()s with data of variable
length; usage of data as format string... hell, i'm happy this is code
for win32, although it scares me greatly. will it go as it is to PGSQL?
:-0

Good points. Right now, because they arrived on the same day, we have
two libpq Win32 patches floating around. Seems the two authors are
going to have to communicate and submit one patch anyway. I am going to
put both patches

http://candle.pha.pa.us/cgi-bin/pgpatches

and maybe someone can merge them and clean them up as needed. Few of us
have Win32 development machines so we need some help.

We know we have Win32 errno problems and I am glad two people have
jumped in to fix them.

-- 
  Bruce Momjian                        |  http://candle.pha.pa.us
  pgman@candle.pha.pa.us               |  (610) 853-3000
  +  If your life is a hard drive,     |  830 Blythe Avenue
  +  Christ can be your backup.        |  Drexel Hill, Pennsylvania 19026
#5Bruce Momjian
bruce@momjian.us
In reply to: Darko Prenosil (#1)
bugs
Re: WIN32 Non Blocking

Your patch has been added to the PostgreSQL unapplied patches list at:

http://candle.pha.pa.us/cgi-bin/pgpatches

This must be merged with the other Win32 libpq patch. Thanks.

Hi ,Bruce !
There is diff for fe-connect.c.
Diff was made with options -cr as You asked.
I must say that this is the first time I ever use diff, so I do not know if
if it is ok.

I did not check if all of non-blocking functions are working,
but I checked PQsetnonblocking,PQisnonblocking,
PQsendQuery, PQgetResult and few others.
I think that

*** ./fe-connect.c Tue Jun 12 20:03:04 2001
--- ./fe-connect1.c Fri Jun 29 05:25:18 2001
***************
*** 189,195 ****
static void defaultNoticeProcessor(void *arg, const char *message);
static int parseServiceInfo(PQconninfoOption *options,
PQExpBuffer errorMessage);
!
/* ----------------
*  Connecting to a Database
--- 189,195 ----
static void defaultNoticeProcessor(void *arg, const char *message);
static int parseServiceInfo(PQconninfoOption *options,
PQExpBuffer errorMessage);
! static char FLastError[200];

/* ----------------
* Connecting to a Database
***************
*** 240,249 ****
PQconnectdb(const char *conninfo)
{
PGconn *conn = PQconnectStart(conninfo);
-
if (conn && conn->status != CONNECTION_BAD)
(void) connectDBComplete(conn);
-
return conn;
}

--- 240,247 ----
***************
*** 291,296 ****
--- 289,295 ----
{
conn->status = CONNECTION_BAD;
/* errorMessage is already set */
+   sprintf( FLastError, "PQconnectStart-Invalid Connection Info");
return conn;
}

***************
*** 516,523 ****
conn->require_ssl = 0;
#endif

!  if (error)
conn->status = CONNECTION_BAD;
else
{
if (connectDBStart(conn))
--- 515,524 ----
conn->require_ssl = 0;
#endif
!  if (error){
conn->status = CONNECTION_BAD;
+   sprintf( FLastError, "Failed to set DBLogin");
+  }
else
{
if (connectDBStart(conn))
***************
*** 709,717 ****
if   (fcntl(conn->sock, F_SETFL, O_NONBLOCK) < 0)
#endif
{
printfPQExpBuffer(&conn->errorMessage,
!      "connectMakeNonblocking -- fcntl() failed: errno=%d\n%s\n",
!         errno, strerror(errno));
return 0;
}
--- 710,724 ----
if   (fcntl(conn->sock, F_SETFL, O_NONBLOCK) < 0)
#endif
{
+  #ifdef WIN32
+   sprintf( FLastError, "connectMakeNonblocking -- fcntl() failed:
errno=%d\n%s\n",
+   WSAGetLastError());
+  #else
printfPQExpBuffer(&conn->errorMessage,
!      "connectMakeNonblocking -- fcntl() failed: errno=%d\n%s\n",
!      errno, strerror(errno));
!  #endif
!
return 0;
}
***************
*** 788,794 ****
{
int   portno,
family;
-
#ifdef USE_SSL
StartupPacket np;   /* Used to negotiate SSL connection */
char  SSLok;
--- 795,800 ----
***************
*** 932,943 ****
* Thus, we have make arrangements for all eventualities.
* ----------
*/
if (connect(conn->sock, &conn->raddr.sa, conn->raddr_len) < 0)
{
- #ifndef WIN32
if (errno == EINPROGRESS || errno == 0)
#else
!   if (WSAGetLastError() == WSAEINPROGRESS)
#endif
{
--- 938,952 ----
* Thus, we have make arrangements for all eventualities.
* ----------
*/
+
+ #ifndef WIN32
if (connect(conn->sock, &conn->raddr.sa, conn->raddr_len) < 0)
{
if (errno == EINPROGRESS || errno == 0)
#else
!  if (connect(conn->sock, &conn->raddr.sa, conn->raddr_len) != 0)
!  {
!   if (WSAGetLastError() == WSAEINPROGRESS || WSAGetLastError() ==
WSAEWOULDBLOCK)
#endif
{
***************
*** 1056,1061 ****
--- 1065,1071 ----
conn->status = CONNECTION_BAD;

return 0;
+
}

***************
*** 1095,1100 ****
--- 1105,1111 ----
if (pqWait(1, 0, conn))
{
conn->status = CONNECTION_BAD;
+      sprintf(FLastError,conn->errorMessage.data);
return 0;
}
break;
***************
*** 1103,1108 ****
--- 1114,1120 ----
if (pqWait(0, 1, conn))
{
conn->status = CONNECTION_BAD;
+      sprintf(FLastError,conn->errorMessage.data);
return 0;
}
break;
***************
*** 1110,1115 ****
--- 1122,1128 ----
default:
/* Just in case we failed to set it in PQconnectPoll */
conn->status = CONNECTION_BAD;
+     sprintf(FLastError,conn->errorMessage.data);
return 0;
}

***************
*** 1208,1222 ****
{
ACCEPT_TYPE_ARG3 laddrlen;

- #ifndef WIN32
-     int   optval;
-
- #else
-     char  optval;
-
- #endif
-     ACCEPT_TYPE_ARG3 optlen = sizeof(optval);
-
/*
* Write ready, since we've made it here, so the
* connection has been made.
--- 1221,1226 ----
***************
*** 1226,1235 ****
* Now check (using getsockopt) that there is not an error
* state waiting for us on the socket.
*/
if (getsockopt(conn->sock, SOL_SOCKET, SO_ERROR,
!           (char *) &optval, &optlen) == -1)
!     {
printfPQExpBuffer(&conn->errorMessage,
"PQconnectPoll() -- getsockopt() failed: "
"errno=%d\n%s\n",
--- 1230,1241 ----
* Now check (using getsockopt) that there is not an error
* state waiting for us on the socket.
*/
+ #ifndef WIN32
+     int   optval;
+     ACCEPT_TYPE_ARG3 optlen = sizeof(optval);
if (getsockopt(conn->sock, SOL_SOCKET, SO_ERROR,
!           (char *) &optval, &optlen) == -1){
printfPQExpBuffer(&conn->errorMessage,
"PQconnectPoll() -- getsockopt() failed: "
"errno=%d\n%s\n",
***************
*** 1247,1252 ****
--- 1253,1272 ----
connectFailureMessage(conn, "PQconnectPoll()", optval);
goto error_return;
}
+ #else
+     char far  optval[8];
+     ACCEPT_TYPE_ARG3 optlen = sizeof(optval);
+
+     int OptResult=getsockopt(conn->sock, SOL_SOCKET, SO_ERROR,optval,
&optlen);
+     if (OptResult==SOCKET_ERROR){
+      printfPQExpBuffer(&conn->errorMessage,
+           "PQconnectPoll() -- getsockopt() failed: "
+            "errno=%i\n",
+            WSAGetLastError());
+      connectFailureMessage(conn, "PQconnectPoll()", OptResult);
+      goto error_return;
+     }
+ #endif
/* Fill in the client address */
laddrlen = sizeof(conn->laddr);
***************
*** 1929,1934 ****
--- 1949,1955 ----
#endif
if (conn->sock >= 0)
#ifdef WIN32
+   //WSACleanup();
closesocket(conn->sock);
#else
close(conn->sock);
***************
*** 2699,2706 ****
char *
PQerrorMessage(const PGconn *conn)
{
if (!conn)
!   return "PQerrorMessage: conn pointer is NULL\n";
return conn->errorMessage.data;
}
--- 2720,2732 ----
char *
PQerrorMessage(const PGconn *conn)
{
+  //char  ErrBuffer[200];
if (!conn)
!   #ifdef WIN32
!    return FLastError;
!   #else
!    return "PQerrorMessage: conn pointer is NULL\n";
!   #endif

return conn->errorMessage.data;
}

---------------------------(end of broadcast)---------------------------
TIP 3: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to majordomo@postgresql.org so that your
message can get through to the mailing list cleanly

-- 
  Bruce Momjian                        |  http://candle.pha.pa.us
  pgman@candle.pha.pa.us               |  (610) 853-3000
  +  If your life is a hard drive,     |  830 Blythe Avenue
  +  Christ can be your backup.        |  Drexel Hill, Pennsylvania 19026
#6Darko Prenosil
darko_prenosil@yahoo.com
In reply to: Bruce Momjian (#5)
bugspatches
Re: WIN32 Non Blocking

I think we are in great shape now. Thanks. The elog() problem was
because they didn't define FRONTEND in the compile.

--
Bruce Momjian                        |  http://candle.pha.pa.us
pgman@candle.pha.pa.us               |  (610) 853-3000
+  If your life is a hard drive,     |  830 Blythe Avenue
+  Christ can be your backup.        |  Drexel Hill, Pennsylvania 19026

I start to dig little bit further and tried to compile WIN32 with MULTIBYTE
support.
There are also a few simple problems.
In src/include/miscadmin.h there is declared external function GetUserName.

Under WIN32 there is already declared that function in winbase.h

Description from MSDN:

BOOL GetUserName(
LPTSTR lpBuffer, // address of name buffer
LPDWORD nSize // address of size of name buffer
);
The GetUserName function retrieves the user name of the current thread. This
is the name of the user currently logged onto the system.

Fortunately Compiler reports error because function arguments are not the
same.
These two functions are not the same at all !!!
I think that this header should not be imported in libpq at all, or should
be
imported only some parts, I'm not for shore yet.
Just to make it work I only disabled GetUserName using WIN32 compiler
constant.
Is there maybe some other compiler constant that means that we are compiling
client library, or should I use FRONTEND compiler constant ?

Compilation after this, and few corrections in win32.h and win32.mak passed
ok,
but now I have another problem. When I tried to test libpq.dll by setting
client encoding, I end up with this error message from server :

"Client Encoding LATIN1 is not supported !"

I think that my server is compiled without MULTIBYTE, because it also
reports error
when I try to CREATE DATABASE WITH ENCODING.
Should I be shamed to confess that I do not know how to re-compile under
Linux ?
So, I first must read the installation manuals or wait for our "Linux-Man"
that returns to work in Monday !

However I'll send you a note as soon as some testing is done !

Darko.Prenosil@finteh.hr

_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com

#7Gerhard Häring
haering_python@gmx.de
In reply to: Darko Prenosil (#6)
patches
Re: [BUGS] WIN32 Non Blocking

Bruce Momjian wrote:

OK, there appears to be heavy demand for this patch so I am applying it
right away. I also made the win32.h change you suggested. This fixes
the _snprintf undefined error reported a few hours ago. Not sure why
the elog() problem is appearing.

I guess you mean why it doesn't succesfully link on win32? The offending
elog call is made in src/backend/lib/dllist.c I have commented the two calls out
and it linked fine on win32. These should probably be replaced by something
else.

Gerhard

--
GMX - Die Kommunikationsplattform im Internet.
http://www.gmx.net

GMX Tipp:

Machen Sie Ihr Hobby zu Geld bei unserem Partner 1&1!
http://profiseller.de/info/index.php3?ac=OM.PS.PS003K00596T0409a

#8Darko Prenosil
darko.prenosil@finteh.hr
In reply to: Darko Prenosil (#6)
bugspatches
Re: [BUGS] WIN32 MULTIBYTE

"Darko Prenosil" <darko_prenosil@yahoo.com> writes:

In src/include/miscadmin.h there is declared external function

GetUserName.

I think that this header should not be imported in libpq at all,

It isn't --- at least I can't see any inclusion path for it in current
sources.

regards, tom lane

Maybe You can not see it in build for Linux (I did not check),
but in WIN32.MAK file there is section
that looks like this:

!IFDEF MULTIBYTE
"$(INTDIR)\common.obj" : ..\..\backend\utils\mb\common.c
$(CPP) @<<
$(CPP_PROJ) /I "." ..\..\backend\utils\mb\common.c
<<

And there are first few lines from common.c :

/*
* This file contains some public functions
* usable for both the backend and the frontend.
* Tatsuo Ishii
* $Id: common.c,v 1.13 2001/04/16 02:42:01 tgl Exp $
*/
#include "postgres.h"

#ifdef WIN32
#include "win32.h"
#else
#include <unistd.h>
#endif

#include "miscadmin.h"
#include "mb/pg_wchar.h"
#include "utils/builtins.h"
...etc...

When I try to compile without correction I mentioned in previous message I
got this error:

..\..\include\miscadmin.h(206) : error C2373: 'GetUserNameA' : redefinition;
different type modifiers !

I'm shore that this header is imported, but I do not know if it can be
skipped in this way:

/*
* This file contains some public functions
* usable for both the backend and the frontend.
* Tatsuo Ishii
* $Id: common.c,v 1.13 2001/04/16 02:42:01 tgl Exp $
*/
#include "postgres.h"

#ifdef WIN32
#include "win32.h"
#else
#include <unistd.h>
#include "miscadmin.h"
#endif

#include "mb/pg_wchar.h"
#include "utils/builtins.h"
...etc...

I supose that this should not impact some other builds?
Is this part of code used by ODBC driver for example, and this change can
corrupt this build ?
I'm quite new in this, so I do not know those answers.

Darko.Prenosil@finteh.hr

#9Bruce Momjian
bruce@momjian.us
In reply to: Darko Prenosil (#8)
patches
Re: [INTERFACES] WIN32 MULTIBYTE

Your patch has been added to the PostgreSQL unapplied patches list at:

http://candle.pha.pa.us/cgi-bin/pgpatches

I will try to apply it within the next 48 hours.

----- Original Message -----
From: "Bruce Momjian" <pgman@candle.pha.pa.us>
To: "Darko Prenosil" <Darko.Prenosil@finteh.hr>
Cc: "pgsql interfaces" <pgsql-interfaces@postgresql.org>
Sent: Thursday, July 26, 2001 11:22 PM
Subject: Re: [INTERFACES] WIN32 MULTIBYTE

Sure, send the patch to the patches list.

I alsi removed definition WIN32_NON_BLOCKING_CONNECTIONS
from fe-connect.c to win32.h.
Ok , here are the changes:

*** win32.mak Mon Jul 30 00:51:28 2001
--- win32.mak.new Mon Jul 30 00:37:40 2001
***************
*** 4,9 ****
--- 4,36 ----
#        and a Win32 dynamic library (non-debug) libpq.dll with import
library libpqdll.lib
+ !MESSAGE Building the Win32 static library...
+ !MESSAGE
+ !IF "$(CFG)" == ""
+ CFG=Release
+ !MESSAGE No configuration specified. Defaulting to Release.
+ !MESSAGE
+ !ELSE
+ !MESSAGE Configuration "$(CFG)"
+ !MESSAGE
+ !ENDIF
+
+ !IF "$(CFG)" != "Release" && "$(CFG)" != "MultibyteRelease"
+ !MESSAGE Invalid configuration "$(CFG)" specified.
+ !MESSAGE You can specify a configuration when running NMAKE
+ !MESSAGE by defining the macro CFG on the command line. For example:
+ !MESSAGE
+ !MESSAGE NMAKE /f win32.mak CFG=[Release | MultibyteRelease ]
+ !MESSAGE
+ !MESSAGE Possible choices for configuration are:
+ !MESSAGE
+ !MESSAGE "Release" (Win32 Release DLL)
+ !MESSAGE "MultibyteRelease" (Win32 Release DLL with Multibyte support)
+ !MESSAGE
+ !ERROR An invalid configuration was specified.
+ !ENDIF
+
+
!IF "$(OS)" == "Windows_NT"
NULL=
!ELSE
***************
*** 15,20 ****
--- 42,51 ----

OUTDIR=.\Release
INTDIR=.\Release
+ !IF "$(CFG)" == "MultibyteRelease"
+ MULTIBYTE=1
+ !ENDIF
+
# Begin Custom Macros
OutDir=.\Release
# End Custom Macros

*** win32.h Mon Jul 30 00:51:28 2001
--- win32.h.new Sun Jul 29 19:43:26 2001
***************
*** 37,39 ****
--- 37,46 ----
#define EWOULDBLOCK WSAEWOULDBLOCK
#define ECONNRESET WSAECONNRESET
#define EINPROGRESS WSAEINPROGRESS
+
+ /*Windows libPq Specific*/
+ #define WIN32_NON_BLOCKING_CONNECTIONS
+ #define FRONTEND
+
+ /*Needed for MULTIBYTE*/
+ #define FUNC_MAX_ARGS  16
*** fe-connect.c Mon Jul 30 00:51:28 2001
--- fe-connect.c.new Fri Jul 27 00:22:39 2001
***************
*** 70,76 ****

#define NOTIFYLIST_INITIAL_SIZE 10
#define NOTIFYLIST_GROWBY 10
- #define WIN32_NON_BLOCKING_CONNECTIONS

/* ----------
* Definition of the conninfo parameters and their fallback resources.
--- 70,75 ----
*** common.c Mon Jul 30 00:51:28 2001
--- common.c.new Mon Jul 30 00:38:02 2001
***************
*** 10,18 ****
#include "win32.h"
#else
#include <unistd.h>
#endif

- #include "miscadmin.h"
#include "mb/pg_wchar.h"
#include "utils/builtins.h"

--- 10,18 ----
#include "win32.h"
#else
#include <unistd.h>
+ #include "miscadmin.h"
#endif

#include "mb/pg_wchar.h"
#include "utils/builtins.h"

*** dllist.c Mon Jul 30 00:51:28 2001
--- dllist.c.new Mon Jul 30 00:38:18 2001
***************
*** 16,27 ****

/* can be used in frontend or backend */
#ifdef FRONTEND
! #include "postgres_fe.h"
! #include <sysexits.h>
! /* No assert checks in frontend ... */
! #define Assert(condition)
#else
! #include "postgres.h"
#endif

#include "lib/dllist.h"
--- 16,29 ----

/* can be used in frontend or backend */
#ifdef FRONTEND
! #include "postgres_fe.h"
! #ifndef WIN32
! #include <sysexits.h>
! #endif
! /* No assert checks in frontend ... */
! #define Assert(condition)
#else
! #include "postgres.h"
#endif

#include "lib/dllist.h"
***************
*** 40,46 ****
--- 42,50 ----
exit(EX_UNAVAILABLE);
}
#else
+   #ifndef WIN32
elog(ERROR, "Memory exhausted in DLNewList");
+   #endif
#endif
l->dll_head = 0;
l->dll_tail = 0;
***************
*** 83,89 ****
--- 87,95 ----
exit(EX_UNAVAILABLE);
}
#else
+   #ifndef WIN32
elog(ERROR, "Memory exhausted in DLNewElem");
+   #endif
#endif
e->dle_next = 0;
e->dle_prev = 0;
-- 
  Bruce Momjian                        |  http://candle.pha.pa.us
  pgman@candle.pha.pa.us               |  (610) 853-3000
  +  If your life is a hard drive,     |  830 Blythe Avenue
  +  Christ can be your backup.        |  Drexel Hill, Pennsylvania 19026
#10Bruce Momjian
bruce@momjian.us
In reply to: Bruce Momjian (#9)
patches
Re: [INTERFACES] WIN32 MULTIBYTE

Tom Lane doesn't want this patch applied. I assume he will give further
guidance. Thanks.

----- Original Message -----
From: "Bruce Momjian" <pgman@candle.pha.pa.us>
To: "Darko Prenosil" <Darko.Prenosil@finteh.hr>
Cc: "pgsql interfaces" <pgsql-interfaces@postgresql.org>
Sent: Thursday, July 26, 2001 11:22 PM
Subject: Re: [INTERFACES] WIN32 MULTIBYTE

Sure, send the patch to the patches list.

I alsi removed definition WIN32_NON_BLOCKING_CONNECTIONS
from fe-connect.c to win32.h.
Ok , here are the changes:

*** win32.mak Mon Jul 30 00:51:28 2001
--- win32.mak.new Mon Jul 30 00:37:40 2001
***************
*** 4,9 ****
--- 4,36 ----
#        and a Win32 dynamic library (non-debug) libpq.dll with import
library libpqdll.lib
+ !MESSAGE Building the Win32 static library...
+ !MESSAGE
+ !IF "$(CFG)" == ""
+ CFG=Release
+ !MESSAGE No configuration specified. Defaulting to Release.
+ !MESSAGE
+ !ELSE
+ !MESSAGE Configuration "$(CFG)"
+ !MESSAGE
+ !ENDIF
+
+ !IF "$(CFG)" != "Release" && "$(CFG)" != "MultibyteRelease"
+ !MESSAGE Invalid configuration "$(CFG)" specified.
+ !MESSAGE You can specify a configuration when running NMAKE
+ !MESSAGE by defining the macro CFG on the command line. For example:
+ !MESSAGE
+ !MESSAGE NMAKE /f win32.mak CFG=[Release | MultibyteRelease ]
+ !MESSAGE
+ !MESSAGE Possible choices for configuration are:
+ !MESSAGE
+ !MESSAGE "Release" (Win32 Release DLL)
+ !MESSAGE "MultibyteRelease" (Win32 Release DLL with Multibyte support)
+ !MESSAGE
+ !ERROR An invalid configuration was specified.
+ !ENDIF
+
+
!IF "$(OS)" == "Windows_NT"
NULL=
!ELSE
***************
*** 15,20 ****
--- 42,51 ----

OUTDIR=.\Release
INTDIR=.\Release
+ !IF "$(CFG)" == "MultibyteRelease"
+ MULTIBYTE=1
+ !ENDIF
+
# Begin Custom Macros
OutDir=.\Release
# End Custom Macros

*** win32.h Mon Jul 30 00:51:28 2001
--- win32.h.new Sun Jul 29 19:43:26 2001
***************
*** 37,39 ****
--- 37,46 ----
#define EWOULDBLOCK WSAEWOULDBLOCK
#define ECONNRESET WSAECONNRESET
#define EINPROGRESS WSAEINPROGRESS
+
+ /*Windows libPq Specific*/
+ #define WIN32_NON_BLOCKING_CONNECTIONS
+ #define FRONTEND
+
+ /*Needed for MULTIBYTE*/
+ #define FUNC_MAX_ARGS  16
*** fe-connect.c Mon Jul 30 00:51:28 2001
--- fe-connect.c.new Fri Jul 27 00:22:39 2001
***************
*** 70,76 ****

#define NOTIFYLIST_INITIAL_SIZE 10
#define NOTIFYLIST_GROWBY 10
- #define WIN32_NON_BLOCKING_CONNECTIONS

/* ----------
* Definition of the conninfo parameters and their fallback resources.
--- 70,75 ----
*** common.c Mon Jul 30 00:51:28 2001
--- common.c.new Mon Jul 30 00:38:02 2001
***************
*** 10,18 ****
#include "win32.h"
#else
#include <unistd.h>
#endif

- #include "miscadmin.h"
#include "mb/pg_wchar.h"
#include "utils/builtins.h"

--- 10,18 ----
#include "win32.h"
#else
#include <unistd.h>
+ #include "miscadmin.h"
#endif

#include "mb/pg_wchar.h"
#include "utils/builtins.h"

*** dllist.c Mon Jul 30 00:51:28 2001
--- dllist.c.new Mon Jul 30 00:38:18 2001
***************
*** 16,27 ****

/* can be used in frontend or backend */
#ifdef FRONTEND
! #include "postgres_fe.h"
! #include <sysexits.h>
! /* No assert checks in frontend ... */
! #define Assert(condition)
#else
! #include "postgres.h"
#endif

#include "lib/dllist.h"
--- 16,29 ----

/* can be used in frontend or backend */
#ifdef FRONTEND
! #include "postgres_fe.h"
! #ifndef WIN32
! #include <sysexits.h>
! #endif
! /* No assert checks in frontend ... */
! #define Assert(condition)
#else
! #include "postgres.h"
#endif

#include "lib/dllist.h"
***************
*** 40,46 ****
--- 42,50 ----
exit(EX_UNAVAILABLE);
}
#else
+   #ifndef WIN32
elog(ERROR, "Memory exhausted in DLNewList");
+   #endif
#endif
l->dll_head = 0;
l->dll_tail = 0;
***************
*** 83,89 ****
--- 87,95 ----
exit(EX_UNAVAILABLE);
}
#else
+   #ifndef WIN32
elog(ERROR, "Memory exhausted in DLNewElem");
+   #endif
#endif
e->dle_next = 0;
e->dle_prev = 0;
-- 
  Bruce Momjian                        |  http://candle.pha.pa.us
  pgman@candle.pha.pa.us               |  (610) 853-3000
  +  If your life is a hard drive,     |  830 Blythe Avenue
  +  Christ can be your backup.        |  Drexel Hill, Pennsylvania 19026
#11Tom Lane
tgl@sss.pgh.pa.us
In reply to: Bruce Momjian (#10)
patches
Re: Re: [INTERFACES] WIN32 MULTIBYTE

Bruce Momjian <pgman@candle.pha.pa.us> writes:

Tom Lane doesn't want this patch applied. I assume he will give further
guidance. Thanks.

The changes to dllist.c are obviously broken; also, the multibyte
linking issue is valid across all platforms and should not be solved by
#ifdef WIN32 kluges. I don't have a problem with the makefile changes,
though.

I alsi removed definition WIN32_NON_BLOCKING_CONNECTIONS
from fe-connect.c to win32.h.

Since this seems to work now, I'm inclined to remove both the symbol and
the #if tests on it, so that we can have some code de-cluttering instead
of increased clutter.

regards, tom lane

#12Tom Lane
tgl@sss.pgh.pa.us
In reply to: Darko Prenosil (#8)
bugspatches
Re: Re: [BUGS] WIN32 MULTIBYTE

"Darko Prenosil" <Darko.Prenosil@finteh.hr> writes:

I think that this header should not be imported in libpq at all,

It isn't --- at least I can't see any inclusion path for it in current
sources.

regards, tom lane

Maybe You can not see it in build for Linux (I did not check),
but in WIN32.MAK file there is section
that looks like this:

!IFDEF MULTIBYTE
"$(INTDIR)\common.obj" : ..\..\backend\utils\mb\common.c
$(CPP) @<<
$(CPP_PROJ) /I "." ..\..\backend\utils\mb\common.c

Hmm. That seems to be rather substantially out of date: in the regular
Unix build, the only file added for MULTIBYTE support is
utils/mb/wchar.c, and it doesn't include any backend-only include files.
We used to import those other backend source files, but that was long
ago.

Please try ripping all the stuff about common.c, conv.c, and big5.c
out of win32.mak, and see if it works then.

regards, tom lane

#13Bruce Momjian
bruce@momjian.us
In reply to: Darko Prenosil (#6)
bugspatches
Re: [BUGS] WIN32 Non Blocking

Do we have a fix for this? It is a WIN32/libpq/multibyte problem.

I think we are in great shape now. Thanks. The elog() problem was
because they didn't define FRONTEND in the compile.

--
Bruce Momjian                        |  http://candle.pha.pa.us
pgman@candle.pha.pa.us               |  (610) 853-3000
+  If your life is a hard drive,     |  830 Blythe Avenue
+  Christ can be your backup.        |  Drexel Hill, Pennsylvania 19026

I start to dig little bit further and tried to compile WIN32 with MULTIBYTE
support.
There are also a few simple problems.
In src/include/miscadmin.h there is declared external function GetUserName.

Under WIN32 there is already declared that function in winbase.h

Description from MSDN:

BOOL GetUserName(
LPTSTR lpBuffer, // address of name buffer
LPDWORD nSize // address of size of name buffer
);
The GetUserName function retrieves the user name of the current thread. This
is the name of the user currently logged onto the system.

Fortunately Compiler reports error because function arguments are not the
same.
These two functions are not the same at all !!!
I think that this header should not be imported in libpq at all, or should
be
imported only some parts, I'm not for shore yet.
Just to make it work I only disabled GetUserName using WIN32 compiler
constant.
Is there maybe some other compiler constant that means that we are compiling
client library, or should I use FRONTEND compiler constant ?

Compilation after this, and few corrections in win32.h and win32.mak passed
ok,
but now I have another problem. When I tried to test libpq.dll by setting
client encoding, I end up with this error message from server :

"Client Encoding LATIN1 is not supported !"

I think that my server is compiled without MULTIBYTE, because it also
reports error
when I try to CREATE DATABASE WITH ENCODING.
Should I be shamed to confess that I do not know how to re-compile under
Linux ?
So, I first must read the installation manuals or wait for our "Linux-Man"
that returns to work in Monday !

However I'll send you a note as soon as some testing is done !

Darko.Prenosil@finteh.hr

_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com

-- 
  Bruce Momjian                        |  http://candle.pha.pa.us
  pgman@candle.pha.pa.us               |  (610) 853-3000
  +  If your life is a hard drive,     |  830 Blythe Avenue
  +  Christ can be your backup.        |  Drexel Hill, Pennsylvania 19026
#14Tom Lane
tgl@sss.pgh.pa.us
In reply to: Bruce Momjian (#13)
bugspatches
Re: Re: [BUGS] WIN32 Non Blocking

Bruce Momjian <pgman@candle.pha.pa.us> writes:

Do we have a fix for this? It is a WIN32/libpq/multibyte problem.

AFAIK it's all fixed (barring new bug reports ;-)). The main problems
were (a) win32.mak hadn't gotten updated when we changed the set of
backend source files that are included into libpq for MULTIBYTE;
(b) win32.mak failed to define FRONTEND, (c) someone had incorrectly
added

#ifndef WIN32
int optval;
#else
char optval;
#endif

upon noting that his Windows compiler griped about

if (getsockopt(conn->sock, SOL_SOCKET, SO_ERROR,
&optval, &optlen) == -1)

instead of realizing that the correct fix is

if (getsockopt(conn->sock, SOL_SOCKET, SO_ERROR,
(char *) &optval, &optlen) == -1)

(a) is new in 7.1 but the other bugs go back at least to 7.0.

regards, tom lane

#15Bruce Momjian
bruce@momjian.us
In reply to: Tom Lane (#14)
bugspatches
Re: Re: [BUGS] WIN32 Non Blocking

Great. Glad to have these Win32 things done.

Bruce Momjian <pgman@candle.pha.pa.us> writes:

Do we have a fix for this? It is a WIN32/libpq/multibyte problem.

AFAIK it's all fixed (barring new bug reports ;-)). The main problems
were (a) win32.mak hadn't gotten updated when we changed the set of
backend source files that are included into libpq for MULTIBYTE;
(b) win32.mak failed to define FRONTEND, (c) someone had incorrectly
added

#ifndef WIN32
int optval;
#else
char optval;
#endif

upon noting that his Windows compiler griped about

if (getsockopt(conn->sock, SOL_SOCKET, SO_ERROR,
&optval, &optlen) == -1)

instead of realizing that the correct fix is

if (getsockopt(conn->sock, SOL_SOCKET, SO_ERROR,
(char *) &optval, &optlen) == -1)

(a) is new in 7.1 but the other bugs go back at least to 7.0.

regards, tom lane

-- 
  Bruce Momjian                        |  http://candle.pha.pa.us
  pgman@candle.pha.pa.us               |  (610) 853-3000
  +  If your life is a hard drive,     |  830 Blythe Avenue
  +  Christ can be your backup.        |  Drexel Hill, Pennsylvania 19026