aboutsummaryrefslogtreecommitdiff
path: root/nscd/connections.c
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@redhat.com>1998-07-24 21:32:39 +0000
committerUlrich Drepper <drepper@redhat.com>1998-07-24 21:32:39 +0000
commit264d5b944dca563c8b948392942d1ea33d221723 (patch)
treefdbba5a3dab20a3ada3736e48802867b6a6c6816 /nscd/connections.c
parent6c202c68704b50016c4faba8d6445ab542b5f301 (diff)
downloadglibc-264d5b944dca563c8b948392942d1ea33d221723.tar
glibc-264d5b944dca563c8b948392942d1ea33d221723.tar.gz
glibc-264d5b944dca563c8b948392942d1ea33d221723.tar.bz2
glibc-264d5b944dca563c8b948392942d1ea33d221723.zip
Update.
1998-07-24 21:29 Ulrich Drepper <drepper@cygnus.com> * nscd/connections.c (pw_send_answer): Make one single writev call. (gr_send_answer): Do the work in two writev calls. This change changes the protocol. * nscd/nscd_getgr_r.c (__nscd_getgr_r): Adjust for protocol change. We now can do the job using two readv calls.
Diffstat (limited to 'nscd/connections.c')
-rw-r--r--nscd/connections.c146
1 files changed, 78 insertions, 68 deletions
diff --git a/nscd/connections.c b/nscd/connections.c
index 7fdafe16b2..e11132c514 100644
--- a/nscd/connections.c
+++ b/nscd/connections.c
@@ -157,7 +157,7 @@ handle_new_request (int **connp, request_header **reqp, char **key)
read_polls[i].fd = -1;
}
}
-
+
if (found == 0)
{
dbg_log (_("No sockets with data found !"));
@@ -320,7 +320,10 @@ init_sockets (void)
void
pw_send_answer (int conn, struct passwd *pwd)
{
+ struct iovec vec[6];
pw_response_header resp;
+ size_t total_len;
+ int nblocks;
resp.version = NSCD_VERSION;
if (pwd != NULL)
@@ -352,40 +355,42 @@ pw_send_answer (int conn, struct passwd *pwd)
return;
}
- /* Send response header. */
- if (write (sock[conn], &resp, sizeof (pw_response_header)) !=
- sizeof (pw_response_header))
- {
- dbg_log (_("write incomplete on send response: %s"), strerror (errno));
- return;
- }
+ /* Add response header. */
+ vec[0].iov_base = &resp;
+ vec[0].iov_len = sizeof (pw_response_header);
+ total_len = sizeof (pw_response_header);
+ nblocks = 1;
if (resp.found)
{
- struct iovec vec[5];
-
- /* Send pw_name. */
- vec[0].iov_base = pwd->pw_name;
- vec[0].iov_len = resp.pw_name_len;
- /* Send pw_passwd. */
- vec[1].iov_base = pwd->pw_passwd;
- vec[1].iov_len = resp.pw_passwd_len;
- /* Send pw_gecos. */
- vec[2].iov_base = pwd->pw_gecos;
- vec[2].iov_len = resp.pw_gecos_len;
- /* Send pw_dir. */
- vec[3].iov_base = pwd->pw_dir;
- vec[3].iov_len = resp.pw_dir_len;
- /* Send pw_shell. */
- vec[4].iov_base = pwd->pw_shell;
- vec[4].iov_len = resp.pw_shell_len;
-
- if (writev (sock[conn], vec, 5) != (resp.pw_name_len + resp.pw_passwd_len
- + resp.pw_gecos_len + resp.pw_dir_len
- + resp.pw_shell_len))
- dbg_log (_("write incomplete on send passwd answer: %s"),
- strerror (errno));
+ /* Add pw_name. */
+ vec[1].iov_base = pwd->pw_name;
+ vec[1].iov_len = resp.pw_name_len;
+ total_len += resp.pw_name_len;
+ /* Add pw_passwd. */
+ vec[2].iov_base = pwd->pw_passwd;
+ vec[2].iov_len = resp.pw_passwd_len;
+ total_len += resp.pw_passwd_len;
+ /* Add pw_gecos. */
+ vec[3].iov_base = pwd->pw_gecos;
+ vec[3].iov_len = resp.pw_gecos_len;
+ total_len += resp.pw_gecos_len;
+ /* Add pw_dir. */
+ vec[4].iov_base = pwd->pw_dir;
+ vec[4].iov_len = resp.pw_dir_len;
+ total_len += resp.pw_dir_len;
+ /* Add pw_shell. */
+ vec[5].iov_base = pwd->pw_shell;
+ vec[5].iov_len = resp.pw_shell_len;
+ total_len += resp.pw_shell_len;
+
+ nblocks = 6;
}
+
+ /* Send all the data. */
+ if (writev (sock[conn], vec, nblocks) != total_len)
+ dbg_log (_("write incomplete on send passwd answer: %s"),
+ strerror (errno));
}
void
@@ -419,7 +424,11 @@ pw_send_disabled (int conn)
void
gr_send_answer (int conn, struct group *grp)
{
+ struct iovec *vec;
+ size_t *len;
gr_response_header resp;
+ size_t total_len;
+ int nblocks;
resp.version = NSCD_VERSION;
if (grp != NULL)
@@ -447,54 +456,55 @@ gr_send_answer (int conn, struct group *grp)
return;
}
- /* Send response header. */
- if (write (sock[conn], &resp, sizeof (gr_response_header))
- != sizeof (gr_response_header))
- {
- dbg_log (_("write incomplete on send response: %s"), strerror (errno));
- return;
- }
+ /* We have no fixed number of records so allocate the IOV here. */
+ vec = alloca ((3 + 1 + resp.gr_mem_len) * sizeof (struct iovec));
+ len = alloca (resp.gr_mem_len * sizeof (size_t));
+
+ /* Add response header. */
+ vec[0].iov_base = &resp;
+ vec[0].iov_len = sizeof (gr_response_header);
+ total_len = sizeof (gr_response_header);
+ nblocks = 1;
if (resp.found)
{
unsigned int l = 0;
- /* Send gr_name. */
- if (write (sock[conn], grp->gr_name, resp.gr_name_len)
- != resp.gr_name_len)
- {
- dbg_log (_("write incomplete on send response: %s"),
- strerror (errno));
- return;
- }
- /* Send gr_passwd. */
- if (write (sock[conn], grp->gr_passwd, resp.gr_passwd_len)
- != resp.gr_passwd_len)
- {
- dbg_log (_("write incomplete on send response: %s"),
- strerror (errno));
- return;
- }
-
- while (grp->gr_mem[l])
+ /* Add gr_name. */
+ vec[1].iov_base = grp->gr_name;
+ vec[1].iov_len = resp.gr_name_len;
+ total_len += resp.gr_name_len;
+ /* Add gr_passwd. */
+ vec[2].iov_base = grp->gr_passwd;
+ vec[2].iov_len = resp.gr_passwd_len;
+ total_len += resp.gr_passwd_len;
+ nblocks = 3;
+
+ if (grp->gr_mem[l])
{
- size_t len = strlen (grp->gr_mem[l]);
+ vec[3].iov_base = len;
+ vec[3].iov_len = resp.gr_mem_len * sizeof (size_t);
+ total_len += resp.gr_mem_len * sizeof (size_t);
+ nblocks = 4;
- if (write (sock[conn], &len, sizeof (len)) != sizeof (len))
+ do
{
- dbg_log (_("write incomplete on send response: %s"),
- strerror (errno));
- return;
- }
- if (write (sock[conn], grp->gr_mem[l], len) != len)
- {
- dbg_log (_("write incomplete on send response: %s"),
- strerror (errno));
- return;
+ len[l] = strlen (grp->gr_mem[l]);
+
+ vec[nblocks].iov_base = grp->gr_mem[l];
+ vec[nblocks].iov_len = len[l];
+ total_len += len[l];
+
+ ++nblocks;
}
- ++l;
+ while (grp->gr_mem[++l]);
}
}
+
+ /* Send all the data. */
+ if (writev (sock[conn], vec, nblocks) != total_len)
+ dbg_log (_("write incomplete on send group answer: %s"),
+ strerror (errno));
}
void