From bd547139c77f2f3bb581d329e70c2c5cd246a3ab Mon Sep 17 00:00:00 2001 From: Ulrich Drepper Date: Tue, 22 Nov 2005 19:06:27 +0000 Subject: * nscd/connections.c (sendfileall): Define. (handle_request): Use it instead of sendfile call. * nscd/nscd-client.h: Declare sendfileall. * nscd/aicache.c: Use sendfileall instead of sendfile. * nscd/grpcache.c: Likewise. * nscd/hstcache.c: Likewise. * nscd/initgrcache.c: Likewise. * nscd/pwdcache.c: Likewise. --- nscd/aicache.c | 8 +++----- nscd/connections.c | 25 +++++++++++++++++++++++-- nscd/grpcache.c | 8 +++----- nscd/hstcache.c | 8 +++----- nscd/initgrcache.c | 8 +++----- nscd/nscd-client.h | 2 ++ nscd/pwdcache.c | 8 +++----- 7 files changed, 40 insertions(+), 27 deletions(-) (limited to 'nscd') diff --git a/nscd/aicache.c b/nscd/aicache.c index 9b8a4e5..59fa2df 100644 --- a/nscd/aicache.c +++ b/nscd/aicache.c @@ -26,9 +26,6 @@ #include #include #include -#ifdef HAVE_SENDFILE -# include -#endif #include "dbg_log.h" #include "nscd.h" @@ -382,9 +379,10 @@ addhstaiX (struct database_dyn *db, int fd, request_header *req, <= (sizeof (struct database_pers_head) + db->head->module * sizeof (ref_t) + db->head->data_size)); - off_t off = (char *) &dataset->resp - (char *) db->head; ssize_t written; - written = sendfile (fd, db->wr_fd, &off, total); + written = sendfileall (fd, db->wr_fd, + (char *) &dataset->resp + - (char *) db->head, total); # ifndef __ASSUME_SENDFILE if (written == -1 && errno == ENOSYS) goto use_write; diff --git a/nscd/connections.c b/nscd/connections.c index 0a1ca77..a6d2a55 100644 --- a/nscd/connections.c +++ b/nscd/connections.c @@ -204,6 +204,26 @@ writeall (int fd, const void *buf, size_t len) } +#ifdef HAVE_SENDFILE +ssize_t +sendfileall (int tofd, int fromfd, off_t off, size_t len) +{ + ssize_t n = len; + ssize_t ret; + + do + { + ret = TEMP_FAILURE_RETRY (sendfile (tofd, fromfd, &off, n)); + if (ret <= 0) + break; + n -= ret; + } + while (n > 0); + return ret < 0 ? ret : len - n; +} +#endif + + enum usekey { use_not = 0, @@ -957,8 +977,9 @@ cannot handle old request version %d; current version is %d"), <= (sizeof (struct database_pers_head) + db->head->module * sizeof (ref_t) + db->head->data_size)); - off_t off = (char *) cached->data - (char *) db->head; - nwritten = sendfile (fd, db->wr_fd, &off, cached->recsize); + nwritten = sendfileall (fd, db->wr_fd, + (char *) cached->data + - (char *) db->head, cached->recsize); # ifndef __ASSUME_SENDFILE if (nwritten == -1 && errno == ENOSYS) goto use_write; diff --git a/nscd/grpcache.c b/nscd/grpcache.c index fb04315..81c61c7 100644 --- a/nscd/grpcache.c +++ b/nscd/grpcache.c @@ -32,9 +32,6 @@ #include #include #include -#ifdef HAVE_SENDFILE -# include -#endif #include #include @@ -310,8 +307,9 @@ cache_addgr (struct database_dyn *db, int fd, request_header *req, <= (sizeof (struct database_pers_head) + db->head->module * sizeof (ref_t) + db->head->data_size)); - off_t off = (char *) &dataset->resp - (char *) db->head; - written = sendfile (fd, db->wr_fd, &off, total); + written = sendfileall (fd, db->wr_fd, + (char *) &dataset->resp + - (char *) db->head, total); # ifndef __ASSUME_SENDFILE if (written == -1 && errno == ENOSYS) goto use_write; diff --git a/nscd/hstcache.c b/nscd/hstcache.c index 29f14af..22f4d6d 100644 --- a/nscd/hstcache.c +++ b/nscd/hstcache.c @@ -34,9 +34,6 @@ #include #include #include -#ifdef HAVE_SENDFILE -# include -#endif #include #include "nscd.h" @@ -344,8 +341,9 @@ cache_addhst (struct database_dyn *db, int fd, request_header *req, <= (sizeof (struct database_pers_head) + db->head->module * sizeof (ref_t) + db->head->data_size)); - off_t off = (char *) &dataset->resp - (char *) db->head; - written = sendfile (fd, db->wr_fd, &off, total); + written = sendfileall (fd, db->wr_fd, + (char *) &dataset->resp + - (char *) db->head, total); # ifndef __ASSUME_SENDFILE if (written == -1 && errno == ENOSYS) goto use_write; diff --git a/nscd/initgrcache.c b/nscd/initgrcache.c index eb03fc7..23d5d59 100644 --- a/nscd/initgrcache.c +++ b/nscd/initgrcache.c @@ -26,9 +26,6 @@ #include #include #include -#ifdef HAVE_SENDFILE -# include -#endif #include "dbg_log.h" #include "nscd.h" @@ -361,8 +358,9 @@ addinitgroupsX (struct database_dyn *db, int fd, request_header *req, <= (sizeof (struct database_pers_head) + db->head->module * sizeof (ref_t) + db->head->data_size)); - off_t off = (char *) &dataset->resp - (char *) db->head; - written = sendfile (fd, db->wr_fd, &off, total); + written = sendfileall (fd, db->wr_fd, + (char *) &dataset->resp + - (char *) db->head, total); # ifndef __ASSUME_SENDFILE if (written == -1 && errno == ENOSYS) goto use_write; diff --git a/nscd/nscd-client.h b/nscd/nscd-client.h index 1389f2d..98c167e 100644 --- a/nscd/nscd-client.h +++ b/nscd/nscd-client.h @@ -319,5 +319,7 @@ extern ssize_t __readvall (int fd, const struct iovec *iov, int iovcnt) attribute_hidden; extern ssize_t writeall (int fd, const void *buf, size_t len) attribute_hidden; +extern ssize_t sendfileall (int tofd, int fromfd, off_t off, size_t len) + attribute_hidden; #endif /* nscd.h */ diff --git a/nscd/pwdcache.c b/nscd/pwdcache.c index 6f4b032..c3039c8 100644 --- a/nscd/pwdcache.c +++ b/nscd/pwdcache.c @@ -32,9 +32,6 @@ #include #include #include -#ifdef HAVE_SENDFILE -# include -#endif #include #include @@ -305,8 +302,9 @@ cache_addpw (struct database_dyn *db, int fd, request_header *req, <= (sizeof (struct database_pers_head) + db->head->module * sizeof (ref_t) + db->head->data_size)); - off_t off = (char *) &dataset->resp - (char *) db->head; - written = sendfile (fd, db->wr_fd, &off, total); + written = sendfileall (fd, db->wr_fd, + (char *) &dataset->resp + - (char *) db->head, total); # ifndef __ASSUME_SENDFILE if (written == -1 && errno == ENOSYS) goto use_write; -- cgit v1.1