📄 lame-list.html
字号:
Reason: <code>WEP()</code> is lame, ergo depending on it islame. Seriously, 16-bit Windows did not guarantee that <code>WEP()</code>would always be called, and the Windows subsystem was often insuch a hairy state that doing <i>anything</i> in <code>WEP()</code> wasdangerous.<img src="../bitmaps/dot-clear.gif" alt="" width=1 height=30 align=top> <br clear=all>Alternative: Stay away from <code>WEP()</code>.<img src="../bitmaps/dot-clear.gif" alt="" width=1 height=30 align=top> <br clear=all><li>Single byte <code>send()</code>s and <code>recv()</code>s. <i>Festeringin a pool of lameness.</i><img src="../bitmaps/dot-clear.gif" alt="" width=1 height=30 align=top> <br clear=all>Reason: Couple one-byte sends with Nagle disabled, and you have atbest a 40:1 overhead-to-data ratio. Can you say wasted bandwidth? Ithought you could.<img src="../bitmaps/dot-clear.gif" alt="" width=1 height=30 align=top> <br clear=all>As for one-byte receives, think of the effort and inefficiencyinvolved with trying to drink a Guinness Stout through a hypodermicneedle. That's about how your application would feel "drinking" dataone-byte at a time.<img src="../bitmaps/dot-clear.gif" alt="" width=1 height=30 align=top> <br clear=all>Alternative: Consider Postel's <ahref="../../rfcs/official.html#rfc793">RFC 793</a> words to live by:"Be conservative in what you do, be liberal in what you accept fromothers." In other words, send modest amounts, and receive as much aspossible.<img src="../bitmaps/dot-clear.gif" alt="" width=1 height=30 align=top> <br clear=all><a name=item23> <li><code>select()</code>. <i>Self abusively lame.</i><img src="../bitmaps/dot-clear.gif" alt="" width=1 height=30 align=top> <br clear=all>Reason: Consider the steps involved in using <code>select()</code>. Youneed to use the macros to clear the 3 <code>fd_set</code>s, then set theappropriate <code>fd_set</code>s for each socket, then set the timer, thencall <code>select()</code>.<img src="../bitmaps/dot-clear.gif" alt="" width=1 height=30 align=top> <br clear=all>Then after <code>select()</code> returns with the number of sockets thathave done something, you need to go through all the <code>fd_set</code>sand all the sockets using the macros to find the event that occurred,and even then the (lack of) resolution is such you need to infer theevent from the current socket state.<img src="../bitmaps/dot-clear.gif" alt="" width=1 height=30 align=top> <br clear=all>Alternative: Use asynchronous operation mode(e.g. <code>WSAAsyncSelect()</code> or <code>WSAEventSelect()</code>).<img src="../bitmaps/dot-clear.gif" alt="" width=1 height=30 align=top> <br clear=all><li>Applications that call <code>gethostbyname()</code> before calling<code>inet_addr()</code>. <i>Words fail to express such all-consuminglameness.</i><img src="../bitmaps/dot-clear.gif" alt="" width=1 height=30 align=top> <br clear=all>Reason: Some users prefer to use network addresses rather thanhostnames at times. The Winsock 1.1 specification does not say what<code>gethostbyname()</code> should do with an IP address in standard ASCIIdotted IP notation. As a result, it may succeed and do an (unnecessary)reverse-lookup, or it may fail.<img src="../bitmaps/dot-clear.gif" alt="" width=1 height=30 align=top> <br clear=all>Alternative: With any destination input by a user<img src="../bitmaps/waist-dot.gif" alt="--" width=14 height=6 hspace=2>which maybe a hostname <i>or</i> dotted IP address<img src="../bitmaps/waist-dot.gif" alt="--" width=14 height=6 hspace=2>you should call<code>inet_addr()</code> <i>first</i> to check for an IP address, and ifthat fails call <code>gethostbyname()</code> to try to resolve it.<img src="../bitmaps/dot-clear.gif" alt="" width=1 height=30 align=top> <br clear=all>Furthermore, in some applications, you may want to explicitly checkthe input string for the broadcast address "255.255.255.255," since thereturn value from <code>inet_addr()</code> for this address is the same as<code>SOCKET_ERROR</code>.<img src="../bitmaps/dot-clear.gif" alt="" width=1 height=30 align=top> <br clear=all><li>Win32 applications that install blocking hooks. <i>Grosslylame.</i><img src="../bitmaps/dot-clear.gif" alt="" width=1 height=30 align=top> <br clear=all>Reason: Besides yielding to other applications (<a href="#item17">seeitem 17</a>), blocking hook functions were originally designed to allowconcurrent processing within a task while there was a blocking operationpending. In Win32, there's threading.<img src="../bitmaps/dot-clear.gif" alt="" width=1 height=30 align=top> <br clear=all>Alternative: Use threads.<img src="../bitmaps/dot-clear.gif" alt="" width=1 height=30 align=top> <br clear=all><li>Polling with <code>ioctlsocket(FIONREAD)</code> on a stream socketuntil a complete "message" arrives. <i>Exceeds the bounds of earthlylameness.</i><img src="../bitmaps/dot-clear.gif" alt="" width=1 height=30 align=top> <br clear=all>Reason and Alternative: <a href="#item12">See item 12</a>.<img src="../bitmaps/dot-clear.gif" alt="" width=1 height=30 align=top> <br clear=all><li>Assuming that a UDP datagram of any length may besent. <i>Criminally lame.</i><img src="../bitmaps/dot-clear.gif" alt="" width=1 height=30 align=top> <br clear=all>Reason: Various networks all have their limitations on maximumtransmission unit (MTU). As a result, fragmentation will occur, andthis increases the likelihood of a corrupted datagram (more pieces tolose or corrupt). Also, the TCP/IP service providers at the receivingend may not be capable of re-assembling a large, fragmented datagram.<img src="../bitmaps/dot-clear.gif" alt="" width=1 height=30 align=top> <br clear=all>Alternative: check for the maximum datagram size with the<code>SO_MAX_MSG_SIZE</code> socket option, and don't send anythinglarger. Better yet, be even more conservative. A max of 8K is a goodrule-of-thumb.<img src="../bitmaps/dot-clear.gif" alt="" width=1 height=30 align=top> <br clear=all><li>Assuming the UDP transmissions (especially multicast transmissions)are reliable. <i>Sinking in a morass of lameness.</i><img src="../bitmaps/dot-clear.gif" alt="" width=1 height=30 align=top> <br clear=all>Reason: UDP has no reliability mechanisms (that's why we have TCP).<img src="../bitmaps/dot-clear.gif" alt="" width=1 height=30 align=top> <br clear=all>Alternative: Use TCP and keep track of your own message boundaries.<img src="../bitmaps/dot-clear.gif" alt="" width=1 height=30 align=top> <br clear=all><li>Applications that require vendor-specific extensions, and cannotrun (or wore yet, load) without them. <i>Stooping to unspeakable depthsof lameness.</i><img src="../bitmaps/dot-clear.gif" alt="" width=1 height=30 align=top> <br clear=all>Reason: If you can't figure out the reason, it's time to hang upyour keyboard.<img src="../bitmaps/dot-clear.gif" alt="" width=1 height=30 align=top> <br clear=all>Alternative: Have a fallback position that uses only base capabilitiesfor when the extension functions are not present.<img src="../bitmaps/dot-clear.gif" alt="" width=1 height=30 align=top> <br clear=all><li>Expecting errors when UDP datagrams are dropped by the sender,receiver, or any router along the way. <i>Seeping lameness from everycrack and crevice.</i><img src="../bitmaps/dot-clear.gif" alt="" width=1 height=30 align=top> <br clear=all>Reason: UDP is unreliable. TCP/IP stacks don't have to tell you whenthey throw your datagrams away (a sender or receiver may do this whenthey don't have buffer space available, and a receiver will do it ifthey cannot reassemble a large fragmented datagram.<img src="../bitmaps/dot-clear.gif" alt="" width=1 height=30 align=top> <br clear=all>Alternative: Expect to lose datagrams, and deal. Implement reliabilityin your application protocol, if you need it (or use TCP, if yourapplication allows it).<img src="../bitmaps/dot-clear.gif" alt="" width=1 height=30 align=top> <br clear=all> </ol><p><font size=-1>Copyright owned by the authors of the Lame List items,including, but not necessarily limited to, the people mentioned in theintroductory matter at the beginning of this article.</font></p> </td> </tr></table><!-- ---- Document Footer ---- --><hr noshade size=1 color=#404040><table cellpadding=5 cellspacing=0 border=0 width=95% align=center> <tr> <td align=left> <a href="../articles/effective-tcp.html"><< Effective TCP/IP</a> </td> <td align=right> <a href="../articles/debugging-tcp.html">Debugging TCP >></a> </td> </tr> <tr> <td align=left> <i>Last modified on 29 April 2000 at 15:52 UTC-7</i> </td> <td align=right> <font size=-1>Please send corrections to <a href="mailto:tangent@cyberport.com">tangent@cyberport.com</a>.</font> </td> </tr> </table> <table cellpadding=5 cellspacing=0 border=0 width=95% align=center> <tr> <td align=left width=33%> <font size=-1> <a href="../index.html"><b><</b> Go to the main FAQ page</a> </font> </td> <td width=33%> <font size=-1> <center> <a href="http://www.cyberport.com/~tangent/programming"><b><<</b> Go to my Programming pages</a> </center> </font> </td> <td align=right width=33%> <font size=-1> <a href="http://www.cyberport.com/~tangent/"><b><<<</b> Go to my Home Page</a> </font> </td> </tr> </table> </body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -