Skip to content

Commit

Permalink
Added dbx_sleep function
Browse files Browse the repository at this point in the history
  • Loading branch information
Lowentwickler committed Feb 1, 2019
1 parent dd82046 commit a423fa7
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 2 deletions.
36 changes: 34 additions & 2 deletions dbx.c
Expand Up @@ -36,10 +36,10 @@ static char * dbxUri;
/* -------------------------------------------------------------------------- */

/* connections pointers */
PGconn ** dbxConnPool;
PGconn ** dbxConnPool = NULL;

/* connections number */
static int dbxConnSize;
static int dbxConnSize = 0;

/* connections number */
static int dbxConnIter;
Expand Down Expand Up @@ -844,3 +844,35 @@ dbx_as_timestamp( PGresult * data, int row_num, int col_num, time_t * p_ts )

return result;
}


int
dbx_sleep(int usec)
{
fd_set fs;

struct timeval tv;

tv.tv_sec = 0;
tv.tv_usec = usec;


if (dbxConnPool)
{
FD_ZERO (&fs);

int maxsd = 0;

for (int i=0; i< dbxConnSize; i++)
{
int sd = PQsocket(dbxConnPool[i]);
FD_SET(sd, &fs);
if (sd > maxsd)
maxsd = sd;
}

return select(maxsd+1, &fs, NULL, NULL, &tv);
}

return 0;
}
5 changes: 5 additions & 0 deletions dbx.h
Expand Up @@ -165,4 +165,9 @@ dbx_as_timestamp( PGresult * result, int row_num, int col_num, time_t * p_ts );

/* -------------------------------------------------------------------------- */

int
dbx_sleep(int usec);

/* -------------------------------------------------------------------------- */

#endif

0 comments on commit a423fa7

Please sign in to comment.