From owner-freebsd-stable Thu Mar 29 12:14:44 2001 Delivered-To: freebsd-stable@freebsd.org Received: from corrupt.network-alchemy.com (Corrupt.Network-Alchemy.COM [199.46.16.36]) by hub.freebsd.org (Postfix) with ESMTP id A4E6137B71D for ; Thu, 29 Mar 2001 12:14:38 -0800 (PST) (envelope-from mruhl@network-alchemy.com) Received: from network-alchemy.com (localhost [127.0.0.1]) by corrupt.network-alchemy.com (8.11.2/8.11.2) with ESMTP id f2TKDGg81149; Thu, 29 Mar 2001 12:13:16 -0800 (PST) (envelope-from mruhl@network-alchemy.com) Message-ID: <3AC3975B.C2F624AF@network-alchemy.com> Date: Thu, 29 Mar 2001 12:13:15 -0800 From: Mike Ruhl X-Mailer: Mozilla 4.76 [en] (X11; U; FreeBSD 4.2-STABLE i386) X-Accept-Language: en MIME-Version: 1.0 To: Jim King Cc: Nate Williams , Paul Marquis , Brian Matthews , Allen Landsidel , freebsd-stable@FreeBSD.ORG Subject: Re: Threads vs. blocking sockets References: <15043.35980.669828.971544@nomad.yogotech.com> <00dd01c0b886$d8510250$524c8486@jking> <3AC390FD.6C03BF8F@pobox.com> <00f201c0b889$c4ff4d30$524c8486@jking> <15043.37950.941991.251263@nomad.yogotech.com> Content-Type: multipart/mixed; boundary="------------9F0D9F61BA9412F5C0A087B4" Sender: owner-freebsd-stable@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG This is a multi-part message in MIME format. --------------9F0D9F61BA9412F5C0A087B4 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Just two other comments on this topic... Note: a send of 0 (zero) bytes is just as valid as a send of > 0 bytes. Also, depending on how the socket was created, send(2) will behave differently. s = socket(domain, SOCK_STREAM, 0); Does completly different things than: s = socket(domain, SOCK_DGRAM, 0); When doing send()s on sockets, make sure you understand the underlying protocol before you decide that something works or does not work. Mike Nate Williams wrote: > > > None of the documented values for errno as set by send(2) indicate "only > > part of the data was sent", at least by my reading. > > That's because it's not an error to send part of the data. > > > How do I tell how many bytes were sent? > > The call returns the number of characters (bytes) sent. You do know how > much data you were sending, don't you? > > Here's a clue for you, since you apparently aren't getting one > otherwise. This code probably won't even compile due to const > poisoning, but hopefully you'll get the idea. > > boolean > mySocketSend(int s, const void *msg, size_t len, int flags) > { > size_t totalSent; > void *data; > > totalSent = 0; > data = msg; > do > { > size_t sent; > sent = send(s, data, len - sentBytes, flags); > if (sent < 0) > { > /* XXX - Handle the error here */ > return false; > } > else if (sent > 0) > { > totalSent += sent; > data += sent; > } > } while (totalSent < len); > > /* Success, sent all the bytes */ > return true; > } > > > > > Still sounds broken to me. > > > > Jim > > > > "Paul Marquis" wrote: > > > > > Under the manual entry for send(2), the RETURN VALUES section states: > > > > > > The call returns the number of characters sent, or -1 if an > > > error occured. > > > > > > So if you request to send 100 bytes, the OS may only be able to sent > > > half those and you need to check how many you sent an resend the part > > > that wasn't sent. > > > > > > Nate is right. > > > > > > Jim King wrote: > > > > Nate Williams wrote: > > > > > Again, all threading libraries I've used (not just on FreeBSD) > > *require* > > > > > the user to check that when sending/receiving data, the caller must > > make > > > > > sure that all the expected data has been sent/received. > > > > > > > > The man page for send(2) doesn't mention this. It sounds broken to me. > > > > > > To Unsubscribe: send mail to majordomo@FreeBSD.org > with "unsubscribe freebsd-stable" in the body of the message --------------9F0D9F61BA9412F5C0A087B4 Content-Type: text/x-vcard; charset=us-ascii; name="mruhl.vcf" Content-Transfer-Encoding: 7bit Content-Description: Card for Mike Ruhl Content-Disposition: attachment; filename="mruhl.vcf" begin:vcard n:Ruhl;Michael J tel;work:(831) 440-6472 x-mozilla-html:FALSE org:Nokia adr:;;1538 Pacific Avenue;Santa Cruz;CA.;95060;U.S.A. version:2.1 email;internet:mruhl@cips.nokia.com title:Tall Blond Guy x-mozilla-cpt:;0 fn:Michael J Ruhl end:vcard --------------9F0D9F61BA9412F5C0A087B4-- To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-stable" in the body of the message