~ubuntu-branches/ubuntu/oneiric/pgpool2/oneiric

« back to all changes in this revision

Viewing changes to pool_stream.c

  • Committer: Bazaar Package Importer
  • Author(s): Christoph Berg
  • Date: 2011-06-10 10:18:29 UTC
  • mfrom: (1.1.6 upstream) (4.2.2 sid)
  • Revision ID: james.westby@ubuntu.com-20110610101829-m1aig6u0p74qpif3
Tags: 3.0.4-1
* New upstream release
* Use format 3.0 (quilt).

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* -*-pgsql-c-*- */
2
2
/*
3
 
* $Header: /cvsroot/pgpool/pgpool-II/pool_stream.c,v 1.19 2010/01/26 14:49:58 t-ishii Exp $
 
3
* $Header: /cvsroot/pgpool/pgpool-II/pool_stream.c,v 1.21 2010/06/01 09:03:00 t-ishii Exp $
4
4
*
5
5
* pgpool: a language independent connection pool server for PostgreSQL
6
6
* written by Tatsuo Ishii
34
34
#include <errno.h>
35
35
#include <unistd.h>
36
36
 
 
37
#ifdef HAVE_FCNTL_H
 
38
#include <fcntl.h>
 
39
#endif
 
40
 
37
41
#include "pool.h"
38
 
 
39
 
#define READBUFSZ 1024
40
 
#define WRITEBUFSZ 8192
 
42
#include "pool_stream.h"
 
43
#include "pool_config.h"
41
44
 
42
45
static int mystrlen(char *str, int upper, int *flag);
43
46
static int mystrlinelen(char *str, int upper, int *flag);
824
827
        cp->po = 0;
825
828
        return 0;
826
829
}
 
830
 
 
831
/*
 
832
 * set non-block flag
 
833
 */
 
834
void pool_set_nonblock(int fd)
 
835
{
 
836
        int var;
 
837
 
 
838
        /* set fd to none blocking */
 
839
        var = fcntl(fd, F_GETFL, 0);
 
840
        if (var == -1)
 
841
        {
 
842
                pool_error("fcntl failed. %s", strerror(errno));
 
843
                child_exit(1);
 
844
        }
 
845
        if (fcntl(fd, F_SETFL, var | O_NONBLOCK) == -1)
 
846
        {
 
847
                pool_error("fcntl failed. %s", strerror(errno));
 
848
                child_exit(1);
 
849
        }
 
850
}
 
851
 
 
852
/*
 
853
 * unset non-block flag
 
854
 */
 
855
void pool_unset_nonblock(int fd)
 
856
{
 
857
        int var;
 
858
 
 
859
        /* set fd to none blocking */
 
860
        var = fcntl(fd, F_GETFL, 0);
 
861
        if (var == -1)
 
862
        {
 
863
                pool_error("fcntl failed. %s", strerror(errno));
 
864
                child_exit(1);
 
865
        }
 
866
        if (fcntl(fd, F_SETFL, var & ~O_NONBLOCK) == -1)
 
867
        {
 
868
                pool_error("fcntl failed. %s", strerror(errno));
 
869
                child_exit(1);
 
870
        }
 
871
}