From cfdd330d1c0203d178b9b49932da952a41a0754f Mon Sep 17 00:00:00 2001 From: Ken Raeburn Date: Thu, 15 Jan 2009 19:15:22 +0000 Subject: Fix an additional multiple-write case noted by John, where sendauth calls write_message twice in a row. Add new function krb5int_write_messages, calls krb5_net_writev with multiple messages (currently only two at a time). Use it from krb5_write_message and krb5_sendauth. ticket: 6339 git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@21752 dc483132-0cff-0310-8789-dd5450dbe970 --- src/lib/krb5/os/write_msg.c | 44 +++++++++++++++++++++++++++++++++++--------- 1 file changed, 35 insertions(+), 9 deletions(-) (limited to 'src/lib/krb5/os/write_msg.c') diff --git a/src/lib/krb5/os/write_msg.c b/src/lib/krb5/os/write_msg.c index 86b9275d74..7586c9b869 100644 --- a/src/lib/krb5/os/write_msg.c +++ b/src/lib/krb5/os/write_msg.c @@ -31,18 +31,44 @@ #include #include "os-proto.h" +/* Try to write a series of messages with as few write(v) system calls + as possible, to avoid Nagle/DelayedAck problems. Cheating here a + little -- I know the only cases we have at the moment will send one + or two messages in a call. Sending more will work, but not as + efficiently. */ krb5_error_code -krb5_write_message(krb5_context context, krb5_pointer fdp, krb5_data *outbuf) +krb5int_write_messages(krb5_context context, krb5_pointer fdp, krb5_data *outbuf, int nbufs) { - krb5_int32 len; - int fd = *( (int *) fdp); - sg_buf sg[2]; + int fd = *( (int *) fdp); + + while (nbufs) { + int nbufs1; + sg_buf sg[4]; + krb5_int32 len[2]; - len = htonl(outbuf->length); - SG_SET(&sg[0], &len, 4); - SG_SET(&sg[1], outbuf->data, outbuf->length); - if (krb5int_net_writev(context, fd, sg, 2) < 0) { + if (nbufs > 1) + nbufs1 = 2; + else + nbufs1 = 1; + len[0] = htonl(outbuf[0].length); + SG_SET(&sg[0], &len[0], 4); + SG_SET(&sg[1], outbuf[0].data, outbuf[0].length); + if (nbufs1 == 2) { + len[1] = htonl(outbuf[1].length); + SG_SET(&sg[2], &len[1], 4); + SG_SET(&sg[3], outbuf[1].data, outbuf[1].length); + } + if (krb5int_net_writev(context, fd, sg, nbufs1 * 2) < 0) { return errno; } - return(0); + outbuf += nbufs1; + nbufs -= nbufs1; + } + return(0); +} + +krb5_error_code +krb5_write_message(krb5_context context, krb5_pointer fdp, krb5_data *outbuf) +{ + return krb5int_write_messages(context, fdp, outbuf, 1); } -- cgit