The following bug has been logged online:

Bug reference:      4060
Logged by:          Bruce Nairn
Email address:      [EMAIL PROTECTED]
PostgreSQL version: 8.3.1
Operating system:   Windows XP Pro
Description:        libpq - large stack causes TCP/IP error
Details: 

I'm using the libpq interface on Win XP (x86) to connect to a postgreSQL
database.  Compiling with microsoft Visual Studio 2005 (express edition). 
When the program stack size increases past a certain size, PQsetdbLogin
returns a TCP/IP buffer error: could not connect to server: No buffer space
available (0x00002747/10055).

A sample code that reproduces the error is attached below.

Any suggestions or fixes would be appreciated.
Thanks,
Bruce

------------------------
#include <cstdio>
#include <string>
#include <iostream>

#include "libpq-fe.h"

/*  ---------------------
*    This is a test program to demonstrate problem connecting to a
PostgreSQL
*    database when the stack is set to exceed approx 0x32cd0000
*    (decimal: 852295680)  seems to depend slightly on shell environment
*
*    Compile on Windows XP with MS Visual Studio 2005:
*   > cl /EHsc /MD /F0x33000000 testconn4.cpp
/Ic:\postgresql\postgresql-8.3.1\src\interfaces\libpq
*    /Ic:\postgresql\postgresql-8.3.1\src\include
/Ic:\postgresql\postgresql-8.3.1\src
*    /link
c:\postgresql\postgresql-8.3.1\src\interfaces\libpq\release\libpqdll.lib
*
*    gives:
*
*       >testconn4 guest 103
*       start
*       inputs first
*       PQsetdbLogin
*       Connection to database failed Error returned: could not connect to 
server:
No buffer space available (0x00002747/10055)
*        Is the server running on host "store.cincomsmalltalk.com" and
accepting
*        TCP/IP connections on port 5432?
*
*     compile with /F0x32000000 (or smaller, or omit), gives expected
output:
*
*       >testconn4 guest 103
*       start
*       inputs first
*       PQsetdbLogin
*       success!
*
*    Is there a solution to allow this to work with a program that requires
*    a stack this large?
*/

using namespace std;
extern "C" void LoadWaterBody(const char* user, const char* setnum){

        std::string newuser = user;
        std::string newsetnum = setnum;

        PGconn* conn;
        PGresult* pgrs;
        char* pghost;
        char* pgport;
        char* pgoptions;
        char* pgtty;
        char* dbName;
        char* login;
        char* pwd;
        
/*  ----------------
*       Google found this database available for public connection, so I use it
for
*       demonstration purposes...  Thanks!
*       
http://www.cincomsmalltalk.com/CincomSmalltalkWiki/PostgreSQL+Access+Page#
guestAccess
*/
        
        pghost="store.cincomsmalltalk.com";
        pgport="5432";

        pgoptions=NULL;
        pgtty=NULL;

        dbName="store_public";
        login="guest";
        pwd="guest";


        cout << "inputs first\n";
        conn = PQsetdbLogin(pghost, pgport, pgoptions, pgtty, dbName, login,
pwd);
        cout << "PQsetdbLogin\n";
        
        if (PQstatus(conn) == CONNECTION_BAD) { // did the database
connection fail?
            cerr << "Connection to database failed " 
                 << "Error returned: " << PQerrorMessage(conn) << endl;
            exit(1);
        }

        // normally db query would go here...
        
        cout << "success!";
}

int main(int argc, const char* argv[] ) {
        cout << "start\n";
        LoadWaterBody (argv[1], argv[2]);
}

-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs

Reply via email to