Arthur de Jong

Open Source / Free Software developer

summaryrefslogtreecommitdiffstats
path: root/nss/common.c
diff options
context:
space:
mode:
authorArthur de Jong <arthur@arthurdejong.org>2007-06-09 00:57:27 +0200
committerArthur de Jong <arthur@arthurdejong.org>2007-06-09 00:57:27 +0200
commit51f3f0903b3f32231f7e8780a5d7c4f9ae1f9203 (patch)
tree547d454f6a94f6344033b51a8c4e5411515ec1d6 /nss/common.c
parent6dc21ddc6876690943c093adc7289a922212fe87 (diff)
implement our own stdio-like library that handles IO with a simple configurable timeout mechanism with buffering
git-svn-id: http://arthurdejong.org/svn/nss-pam-ldapd/nss-ldapd@272 ef36b2f9-881f-0410-afb5-c4e39611909c
Diffstat (limited to 'nss/common.c')
-rw-r--r--nss/common.c15
1 files changed, 11 insertions, 4 deletions
diff --git a/nss/common.c b/nss/common.c
index 29e06f2..2735a07 100644
--- a/nss/common.c
+++ b/nss/common.c
@@ -2,7 +2,7 @@
common.c - common functions for NSS lookups
Copyright (C) 2006 West Consulting
- Copyright (C) 2006 Arthur de Jong
+ Copyright (C) 2006, 2007 Arthur de Jong
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
@@ -34,6 +34,7 @@
#include "nslcd.h"
#include "common.h"
+#include "common/tio.h"
/* translates a nsklcd return code (as defined in nslcd.h) to
a nss code (as defined in nss.h) */
@@ -50,11 +51,12 @@ enum nss_status nslcd2nss(int32_t code)
/* returns a socket to the server or NULL on error (see errno),
socket should be closed with fclose() */
-FILE *nslcd_client_open()
+TFILE *nslcd_client_open()
{
int sock;
struct sockaddr_un addr;
- FILE *fp;
+ struct timeval readtimeout,writetimeout;
+ TFILE *fp;
/* create a socket */
if ( (sock=socket(PF_UNIX,SOCK_STREAM,0))<0 )
return NULL;
@@ -67,8 +69,13 @@ FILE *nslcd_client_open()
(void)close(sock);
return NULL;
}
+ /* set the timeouts */
+ readtimeout.tv_sec=2; /* looking up stuff may take some time */
+ readtimeout.tv_usec=0;
+ writetimeout.tv_sec=1; /* nslcd could be loaded with requests */
+ writetimeout.tv_usec=500000;
/* create a stream object */
- if ((fp=fdopen(sock,"w+"))==NULL)
+ if ((fp=tio_fdopen(sock,&readtimeout,&writetimeout))==NULL)
{
(void)close(sock);
return NULL;